【发布时间】:2018-08-24 02:41:23
【问题描述】:
我有一个 Textinput,我想在光标未填充时设置它。
class SignupScreen extends Component {
constructor(props) {
super(props);
this.fieldOne = React.createRef();
this.state = {
name: '',
}
}
validate() {
if(_.size(this.state.name) < 3) {
...
this.fieldOne.current.focus() // this is not working
}
}
render() {
return(
....
<TextInput
placeholder={'Name'}
autoCapitalize='words'
autoCorrect={false}
autoFocus={false}
keyboardType='default'
value={this.state.name}
ref={this.fieldOne}
selectionColor={colors.PRIMARY_LIGHT}
placeholderTextColor={colors.PRIMARY_LIGHT}
underlineColorAndroid={colors.NO_COLOR}
onChangeText={(text) => this.setState({ name: text })}
/>
...
}
在验证方法中,当光标不正确时,我想将光标聚焦在字段中。我在互联网上查看过,我也将这个问题作为问题发布在https://github.com/facebook/react-native/issues/20817。虽然,我还没有找到真正的解决方案。
谢谢你!
【问题讨论】:
标签: javascript react-native expo