'React Native: Dismiss the keyboard and remain the focus in the TextInput
I have tried all the methods, but when i dismiss the keyboard the focus also blur. But when I wanna user to paste the information to the TextInput i am not willing to show the soft keyboard.
<TextInput
ref='barcodeInput'
style={{height: 60,borderColor: '#000000', borderWidth: 1, width:300, fontSize:30}}
underlineColorAndroid="transparent"
onChangeText={(text) => this.setState({inputBarcode:text})}
onSubmitEditing={this.handleSubmitEditing.bind(this)}
keyboardType = {'numeric'}
/>
Solution 1:[1]
You can use the showSoftInputOnFocus prop on TextInput to control the behavior.
When
false, it will prevent the soft keyboard from showing when the field is focused. The default value istrue.
Docs: https://reactnative.dev/docs/textinput#showsoftinputonfocus
When this prop is false, the keyboard will not open, but the input will remain focused.
Solution 2:[2]
You should be able to use the Keyboard component from react-native. Eg:
import { Keyboard } from 'react-native'
Keyboard.dismiss()
The focus should still be kept on your input, but the soft keyboard will disappear.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | |
| Solution 2 | user2672053 |
