升级到 0.26.0-rc 版本后,此行:
React.findNodeHandle(this.refs.myRef)
引发此错误消息:
未处理的JS异常:_react2.default.findNodeHandle不是 功能
我用这个导入React:
import React from 'react';
文档still say: “与往常一样,要获取组件的本机节点句柄,可以使用React.findNodeHandle(组件)。”
答案 0 :(得分:44)
现在可以在没有对象的情况下使用该函数:
import {
...
findNodeHandle,
...
} from 'react-native';
直接打电话:
findNodeHandle(this.refs[refName])
答案 1 :(得分:32)
您还必须导入ReactNative。
import ReactNative from 'react-native';
...
ReactNative.findNodeHandle(...)
答案 2 :(得分:0)
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)
})