我正在使用TextInput
反应原生组件。我想在onPress功能中设置它的焦点。如何在TextInput上设置焦点或光标原生反应
<TextInput
ref="messageTextInput"
style={{
height: 40,
width: "100%",
borderColor: "gray",
borderWidth: 1,
marginTop: 8
}}
underlineColorAndroid="transparent"
placeholder={strings.enter_your_message}
onChangeText={text => this.setState({ text })}
/>
_onPress(navigate) {
try {
if (!this.state.text.trim()) {
Alert.alert(strings.app_name, strings.validate_text);
this.messageTextInput.focus();
}
} catch (error) {
console.log(error);
}
}
它没有在messageTextInput上设置焦点或光标。有没有人知道如何做到这一点在原生态?
的onfocus ?:回调函数被调用时,文本输入焦点。,您可以在[Focus]上搜索[documentation](http://facebook.github.io/react-native/docs/textinput.html#selection) – chirag90