【发布时间】:2016-08-18 21:52:29
【问题描述】:
如果只有 ref,如何测量 react-native 元素的高度?
我看到NativeMethodsMixin,但不清楚如何实现。
我尝试将其包含为:
import { NativeMethodsMixin } from 'react-native';
class Foo extends Component {
mixins: [NativeMethodsMixin]
measure(ref) {
console.log(NativeMethodsMixin.measure(ref));
}
...
}
但应用程序抱怨 NativeMethodsMixin 未定义。
如果我走RCTUIManager 路线:
import { NativeModules } from 'react-native';
const RCTUIManager = NativeModules.UIManager;
class Foo extends Component {
measure(ref) {
const height = RCTUIManager.measure(ref, (x, y, width, height, pageX, pageY) => height));
console.log(height);
}
...
}
然后我得到一个错误:Uncaught TypeError: Converting circular structure to JSON
我只想知道ref 的高度。我错过了什么?
【问题讨论】:
-
对于任何发现这个的人——你必须使用
ref,而不是实际的 React 支持类实例。 facebook.github.io/react/docs/more-about-refs.html
标签: react-native react-native-listview react-native-scrollview nativemethodsmixin