I just followed the answer from the link react-native: hide keyboard
But the keyboard is coming as flash for fraction of seconds then it is dismissing. Is there is a way to avoid keyboard totally.
asked Mar 8, 2017 at 13:12
Venuu Munnuruu
3251 gold badge7 silver badges18 bronze badges
-
did you try stackoverflow.com/questions/29685421/react-native-hide-keyboard/… ?vinayr– vinayr2017年03月08日 13:57:36 +00:00Commented Mar 8, 2017 at 13:57
-
Does this answer your question? Hide keyboard in react-nativeBhavin Parghi– Bhavin Parghi2023年05月11日 13:47:16 +00:00Commented May 11, 2023 at 13:47
3 Answers 3
Correct way is to dismiss View with TouchableWithoutFeedback and calling Keyboard.dismiss()
import {Keyboard} from 'react-native'
<TouchableWithoutFeedback onPress={Keyboard.dismiss}>
<View style={styles.container}>
<TextInput keyboardType='numeric'/>
</View>
</TouchableWithoutFeedback>
answered Jul 21, 2017 at 6:11
HpDev
2,9471 gold badge18 silver badges20 bronze badges
Comments
You can use Keyboard.dismiss() for keyboard hide.
import React from "react";
import {
Keyboard,
StyleSheet,
View,
TextInput,
TouchableOpacity
} from "react-native";
export default function App() {
return (
<TouchableOpacity onPress={() => Keyboard.dismiss()}>
<View style={styles.MainContainer}>
<TextInput
style={styles.textinput}
placeholder="Enter Your Name"
/>
</View>
</TouchableOpacity>
);
}
const styles = StyleSheet.create({
MainContainer: {
flex: 1,
justifyContent: "center",
alignItems: "center"
},
text: {
fontSize: 28,
textAlign: "center"
},
textinput: {
paddingVertical: 12,
margin: 8,
borderRadius: 7,
backgroundColor: "#F9FBE7",
borderWidth: 2,
borderColor: "#000000",
textAlign: "center"
}
});
Comments
Explore related questions
See similar questions with these tags.
lang-js