我试图让一个组件的位置反应原生.
说我有一个观点:
<ScrollView>
lots of items...
lots of items...
lots of items...
<View></View>
</ScrollView>
Run Code Online (Sandbox Code Playgroud)
最后,我希望能够最终滚动到View所在的位置.
此链接显示如何使用本机ui管理器获取位置,但是在运行时它返回:
"尝试测量布局,但偏移或尺寸为NaN"
我试过了
this.refs.VIEW.measure((ox, oy, width, height, px, py) => {
//ox ... py all = 0
});
Run Code Online (Sandbox Code Playgroud)
zer*_*ero 11
您可能希望在View组件上使用onLayout回调.setTimeout可能无法100%的工作时间.
<View onLayout={this.measureMyComponent} />
Run Code Online (Sandbox Code Playgroud)
Col*_*say 10
有时如果你在componentDidMount中使用measure,你必须将它包装在setTimeout中:
setTimeout(() => {
this.refs.VIEW.measure((ox, oy, width, height, px, py) => {
});
}, 0);
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
10391 次 |
| 最近记录: |