I'm trying to make a sticky footer with the KeyboardAvoidingView
component in React Native. I'm very close to accomplishing this task, however, when they keyboard comes up, the footer is moving up but shrinking in height at the same time.
Here's what it looks like before the keyboard comes up:
And here's what it looks like after the keyboard comes up:
As you can see, the submit container is smaller than it is before there is a keyboard.
Here's my current code:
render() {
return (
<KeyboardAvoidingView style={{ flex: 1 }} behavior="padding">
<View style={{ flex: 1, }}>
<TextInput
placeholder="Username"
value={this.state.username}
style={Styles.textInput}
onChangeText={(username) => this.setState({ username })}
autoCorrect={false}
/>
<TextInput
style={Styles.textInput}
placeholder="Email"
value={this.state.email}
onChangeText={(email) => this.setState({ email })}
autoCorrect={false}
/>
</View>
<View style={{ height: 100, backgroundColor: 'blue' }}>
<Text>Submit</Text>
</View>
</KeyboardAvoidingView>
);
What am I doing wrong?
Are you using react-navigation? This might be affected by the header of the react-navigation. The height of the header is vary on different mobile screen size. You need to get the get the height of the header and pass into the keyboardVerticalOffset props.
import { Header } from 'react-navigation';
<KeyboardAvoidingView
keyboardVerticalOffset = {Header.HEIGHT + 20}
style = {{ flex: 1 }}
behavior = "padding" >
<ScrollView>
<TextInput/>
<TextInput/>
<TextInput/>
<TextInput/>
<TextInput/>
<TextInput/>
</ScrollView>
</KeyboardAvoidingView>
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