3
我指的是这在我index.android.js文件..我怎样才能findViewById()的反应,原生的Android
<View>
<CustomView>
...
</CustomView>
</View>
我指的是这在我index.android.js文件..我怎样才能findViewById()的反应,原生的Android
<View>
<CustomView>
...
</CustomView>
</View>
做裁判使用的,可以作为参考作用的成分组件
例如:
<View>
<TextInput style={styles.textInput}
ref={'usrname'}
placeholder={'Username'}
placeholderTextColor={'red'}
onChangeText={(userName) => this.setState({userName})}
value={this.state.userName} />
<TouchableOpacity onPress={this._onPressButton}>
<View style={styles.buttonContainer}>
<Text> Submit </Text>
</View>
</TouchableOpacity>
</View>
和onPress:
_onPressButton: function(e){
var x = this.state.userName;
alert(x); //we can also use alert(this.state.userName)
},
这可以通过React.findNodeHandle
完成。
在你的情况,
...
var { findNodeHandle } = React;
...
render: function() {
return (
<View>
<CustomView ref="customView">
...
</CustomView>
</View>
);
},
somethingLikeComponentDidMount: function() {
var customViewNativeID = findNodeHandle(this.refs.customView);
// Something else...
}
...
可能做的工作。
谢谢... @Pramod Mg但我怎么能在我的java代码中使用它?我可以将它传递给我的模块吗?像Mymodule._module.func(x); – JA21
y到javacode>? –
原因我想在我的java中使用我的CustomView .. 查看canvasView = findViewById(R.id.CustomView); 洙,我可以捕捉到我的CustomView里面的东西,问题是react-native没有xml,我知道它非常容易,如果它有一个xml文件,我可以说.. findViewById()... – JA21