关闭键盘后,React Native TextInput 仍然具有焦点(TextInput 中的光标)

use*_*934 3 android react-native

关闭键盘或按其他地方后,如何摆脱文本输入中的光标?

这就是我对 TextInput 的全部内容:

<TextInput
  style={styles.searchBar}
  onChangeText={null}
  placeholder={'What are you searching for?'}
  underlineColorAndroid="transparent"
/>
Run Code Online (Sandbox Code Playgroud)

小智 5

我知道这个问题有点老了,但只是改进马丁的答案,你可以这样做:

componentDidMount(){
  Keyboard.addListener('keyboardDidHide', this._forceLoseFocus);
}

<TextInput ref={(component) => this._textInput = component}/>

_forceLoseFocus = () => {
  this._textInput.blur();
}
Run Code Online (Sandbox Code Playgroud)

经过测试并使用 React Native 0.55.4