React' findNodeHandle 方法停止工作

React' findNodeHandle method stopped working

升级到0.26.0-rc版本后,这一行:

React.findNodeHandle(this.refs.myRef)

抛出此错误消息:

Unhandled JS Exception: _react2.default.findNodeHandle is not a function.

我正在导入 React:

import React from 'react';

文档still say"As always, to obtain a native node handle for a component, you can use React.findNodeHandle(component)."

您还必须导入 ReactNative。

import ReactNative from 'react-native';
...
ReactNative.findNodeHandle(...)

现在函数可以在没有对象的情况下使用:

import {
  ...
  findNodeHandle,
  ...
} from 'react-native';

并直接调用:

findNodeHandle(this.refs[refName])
import {
  ...
  findNodeHandle,
} from 'react-native';

var RCTUIManager = require('NativeModules').UIManager;

var view = this.refs['yourRef']; // Where view is a ref obtained through <View ref='ref'/>
RCTUIManager.measure(findNodeHandle(view), (fx, fy, width, height, px, py) => {
  console.log('Component width is: ' + width)
  console.log('Component height is: ' + height)
  console.log('X offset to frame: ' + fx)
  console.log('Y offset to frame: ' + fy)
  console.log('X offset to page: ' + px)
  console.log('Y offset to page: ' + py)
})