如何在ComponentDidMount上关注TextInput?

时间:2018-03-20 22:10:09

标签: react-native

我用:

ComponentDidMount(){
  this.foca()
}

foca = () => {
  this.refs.edit.focus()
}

<TextInput
  ref='edit'
  style={{height:60, borderColor:'gray', borderWidth:1, backgroundColor:'white', borderRadius:10}}
  onChangeText={(text) => this.setState({busca: text})}
  onSubmitEditing={(event) => this.props.navigation.navigate('Resultado', {busca: this.state.busca})}
/>

但它不起作用......

我喜欢在显示屏幕时将焦点设置在我的TextInput上

1 个答案:

答案 0 :(得分:6)

只需将此属性添加到TextInput组件即可 autofocus

<TextInput  autoFocus={true} />