I am trying to create a KeyboardAvoidingView
area for a signup form. I have gotten the component to a place where the actual keyboard adjustment is decent on iOS and Android.
However, instead of adding more height to the bottom of the view and scrolling up, the KeyboardAvoidingView
seems to be simply compressing the height.
Here is the resulting effect on Android:
Before keyboard adjustment:
After keyboard adjustment:
Here's the code for the component:
<KeyboardAvoidingView keyboardVerticalOffset={20} behavior={Platform.OS === 'ios' ? 'padding' : null} style={mainWithFooter.container}>
<View style={mainWithFooter.main}>
<Text style={material.display1}>Create Your Account</Text>
</View>
<View style={mainWithFooter.footer}>
<Input
placeholder='First name'
onChangeText={t => updateSignupForm('firstName', t)}
/>
<Input
placeholder='Last name'
onChangeText={t => updateSignupForm('lastName', t)}
/>
<Input
placeholder='Email'
keyboardType='email-address'
autoCapitalize='none'
onChangeText={t => updateSignupForm('email', t)}
/>
<Input
placeholder='Password'
secureTextEntry
onChangeText={t => updateSignupForm('password', t)}
/>
<Button
text='Create Account'
onPress={signup}
primary
disabled={!signupFormIsValid}
block
/>
</View>
</KeyboardAvoidingView>
And the styles:
export default StyleSheet.create({
container: {
display: 'flex',
flex: 1,
backgroundColor: '#fff',
alignItems: 'center',
justifyContent: 'center',
padding: 30,
minHeight: '100%',
},
main: {
flex: 1,
display: 'flex',
alignItems: 'center',
justifyContent: 'center',
marginBottom: 20,
},
footer: {
width: '100%',
flex: 0,
},
})
How can I fix this, so that the content does not overlap?
I ran into the same issue. I wrapped the children of KeyboardAvoidingView
in a View
component and then set the minHeight
of that component using Dimennsions.get('window').height
. See your example below:
<KeyboardAvoidingView keyboardVerticalOffset={20} behavior={Platform.OS === 'ios' ? 'padding' : null} style={mainWithFooter.container}>
<View style={mainWithFooter.wrapper}> ** <-- wrapper here. **
<View style={mainWithFooter.main}>
<Text style={material.display1}>Create Your Account</Text>
</View>
<View style={mainWithFooter.footer}>
<Input
placeholder='First name'
onChangeText={t => updateSignupForm('firstName', t)}
/>
...
</View>
</View>
</KeyboardAvoidingView>
Then the style:
const windowHeight: Dimensions.get('window').height;
export default StyleSheet.create({
wrapper: {
minHeight: windowHeight,
},
...
});
You may need to add additional necessary styles such as flex
etc. to the wrapper.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With