如何在 react-native android 中 findViewById() [英] How can I findViewById() in react-native android
本文介绍了如何在 react-native android 中 findViewById()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在 index.android.js 文件中提到了这个..
I'm referring to this in my index.android.js file..
<View>
<CustomView>
...
</CustomView>
</View>
推荐答案
这可以通过 React.findNodeHandle
来完成.
This can be done by React.findNodeHandle
.
就你而言,
...
var { findNodeHandle } = React;
...
render: function() {
return (
<View>
<CustomView ref="customView">
...
</CustomView>
</View>
);
},
somethingLikeComponentDidMount: function() {
var customViewNativeID = findNodeHandle(this.refs.customView);
// Something else...
}
...
可能会做这项工作.
有关工作示例(本机绑定两个组件),请查看 此处 作为 JS 部分和 这里 作为原生 Java 部分.
For a working example (natively binding two components), check out here as the JS part and here as the native Java part.
这篇关于如何在 react-native android 中 findViewById()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文