我是 native react 的新手。我有一个textfield(Input)。我希望在用户单击除输入字段以外的其他位置时关闭键盘。
我尝试了此处建议的几种解决方案,例如TouchableWithoudFeedback,但是它们没有用。
另外,我不清楚这一点,我可以使用onFocus内部的任何函数,另一方面,在onBlur或onEndEditing中没有任何作用
这是我的输入组件代码。
<InputGroup borderType='rounded' style={styles.inputGrp}>
<Input placeholder={'Password'} secureTextEntry={true} style={styles.input}
onChangeText={(pin1) => this.setState({pin1: pin1})}
value={this.state.pin1}
maxLength={8}
/>
最佳答案
这是上述问题的解决方案:在响应 native 中隐藏键盘
import {Keyboard, TouchableWithoutFeedback} from 'react-native'
使用TouchableWithoutFeedback包装您的根组件,并在onPress触发Keyboard.dismiss,如下所示<TouchableWithoutFeedback onPress={Keyboard.dismiss}>
<View style={{flex: 1}}>
........
//rest of the component
........
</View>
</TouchableWithoutFeedback>
关于input - 当焦点移出/单击文本字段外的其他位置时,React-native关闭键盘,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41380651/