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