1
如果只有ref
,您如何測量react-native元素的高度?Reaction-native ref的測量高度(ListView)
我看到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',而不是實際的反應支持類實例。 https://facebook.github.io/react/docs/more-about-refs.html – chandlervdw