I was trying to remove a view from the screen when the keyboard appears so everything can fit on the screen.
After the keyboard is initially dismissed the first time - with the keyboardDidHide code commented out - it will not automatically dismiss it again.
Here is the code part of the code. I am using Formik for the form.
What am I doing wrong?
const [keyboardUp, setKeyboardUp] = React.useState(false);
Keyboard.addListener("keyboardDidShow", _keyboardDidShow);
Keyboard.addListener("keyboardDidHide", _keyboardDidHide);
React.useEffect(() => {
Keyboard.addListener("keyboardDidShow", _keyboardDidShow);
Keyboard.addListener("keyboardDidHide", _keyboardDidHide);
// cleanup function
return () => {
Keyboard.removeListener("keyboardDidShow", _keyboardDidShow);
Keyboard.removeListener("keyboardDidHide", _keyboardDidHide);
};
}, []);
const _keyboardDidShow = () => {
setKeyboardUp(true);
};
const _keyboardDidHide = () => {
setKeyboardUp(false);
};
const LoginForm=()=>{
let input_height=40;
return (
<Formik
style={{ backgroundColor:"blue" }}
initialValues={{email:'',password:''}}
onSubmit={(values)=> {
let username = values.email;
let p = values.password;
signIn({ username,p })
}}
>
{(props)=>(
<View style={{width:"100%", height:"45%", justifyContent:"center",alignItems:"center"}}>
<TextInput style={{width:"75%", borderColor: "#1d3557", borderWidth:1, height:input_height, margin:"2%", paddingLeft:"3%", backgroundColor:"white", borderColor:"grey", borderRadius:8}}
placeholder='email' onChangeText={props.handleChange('email')} value={props.values.title} />
<TextInput style={{width:"75%", height:input_height, borderColor: "#1d3557", borderWidth:1, margin:"2%", paddingLeft:"3%", backgroundColor:"white", borderColor:"grey", borderRadius:8}}
placeholder='password' onChangeText={props.handleChange('password')} value={props.values.password} />
<TouchableOpacity style={{backgroundColor:"#008b9a", justifyContent:"center", marginTop:"8%", alignItems:"center", width:"75%", height:40, borderRadius:16}}
onPress={props.handleSubmit}>
<Text style={{fontSize:16, fontWeight:"bold"}}>LOGIN</Text>
</TouchableOpacity>
</View>
)}
</Formik>
);
}