阵营” findNodeHandle方法停止工作
问题描述:
升级后0.26.0-RC版本,该行:阵营” findNodeHandle方法停止工作
React.findNodeHandle(this.refs.myRef)
抛出此错误消息:
未处理的JS例外:_react2.default。 findNodeHandle不是 函数。
我进口这个阵营:
import React from 'react';
文档still say: “一如既往,以获得一个组件的本地节点手柄,你可以使用React.findNodeHandle(组件)。 “
答
你必须导入ReactNative为好。
import ReactNative from 'react-native';
...
ReactNative.findNodeHandle(...)
答
现在可以在没有对象可以使用的功能:
import {
...
findNodeHandle,
...
} from 'react-native';
,并直接把它叫做:
findNodeHandle(this.refs[refName])
+0
酷,好主意! – Cherniv
答
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)
})
版'什么0.26 rc'?哪些文档说的? – loganfsmyth
React Native,https://github.com/facebook/react-native – Cherniv
任何方式,你可以显示更多的代码? –