I'm new to react-native. I have a textfield(Input). I want to the Keyboard to be dismissed when user clicks somewhere else except input field. I tried several solutions suggested here like TouchableWithoudFeedback, but they did not work. Also, the point which is not clear to me, I can use any function inside onFocus, on the other hand, nothing worked in onBlur or onEndEditing Here is my code of Input component.
<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}
/>
You can use keyboard's done button to dismiss the keyboard when the user is done entering text.
Define this method somewhere.
Don't forget to import
Also, there are several workarounds possible if you want to dismiss keyboard when the user taps anywhere else other than keyboard whenever the keyboard is visible. Use keyboardWillShow and keyboardWillHide methods to set and unset a state variable something like isKeyboardVisible = true. Also, based on this state variable, if true, render an overlay over your entire screen (transparent TouchableHighlight or TouchableWithoutFeedback) with absolute coordinates (from height 0 to screen height - keyboardheight) and call the same dismisskeyboard() method on tap.
Something like
You can get screen height like this
From here, you can render a transparent touchable component over your UI only when the keyboard is visible and dismiss keyboard in the onPress method.