I am having trouble getting the KeyboardAvoidingView to work properly. For a similar screen it is working smoothly, however, for another it is pushing up content way too far up on the screen, adding excessive amounts of space in between. Any fix?
code:
<KeyboardAvoidingView behavior="padding" style={styles.container}>
{this.props.signNameErr &&
(<Text style={{color: 'red'}}>{this.props.errMessage}</Text>)
}
<View style={styles.formContainer}>
<TextInput
style={styles.formInput}
placeholderTextColor="rgba(255,255,255,0.7)"
underlineColorAndroid='rgba(0,0,0,0)'
returnKeyType="next"
autoCorrect={false}
onChangeText={(full_name)=> this.setState({full_name})}
value={this.state.fullname}
placeholder="Enter Full Name"
/>
{this.props.signEmailErr &&
(<Text style={{color: 'red'}}>{this.props.errMessage}</Text>)
}
<TextInput
style={styles.formInput}
placeholderTextColor="rgba(255,255,255,0.7)"
underlineColorAndroid='rgba(0,0,0,0)'
returnKeyType="next"
keyboardType="email-address"
autoCapitalize="none"
autoCorrect={false}
onChangeText={(email)=> this.setState({email})}
value={this.state.email}
placeholder="Enter Email"
keyboardType="email-address"
/>
{this.props.signPwErr &&
(<Text style={{color: 'red'}}>{this.props.errMessage}</Text>)
}
<TextInput
style={styles.formInput}
placeholderTextColor="rgba(255,255,255,0.7)"
underlineColorAndroid='rgba(0,0,0,0)'
returnKeyType="next"
autoCorrect={false}
onChangeText={(password)=> this.setState({password})}
secureTextEntry={this.state.togglePW}
value={this.state.password}
placeholder="Create Password (Min. 6 Char)"
/>
<TouchableOpacity style={styles.buttonContainer} onPress={this.handleSignup}>
<Text style={styles.buttonText}>SIGN UP</Text>
</TouchableOpacity>
</View >
</KeyboardAvoidingView>
Use android:windowSoftInputMode="adjustResize". KeyboardAvoidingView and other keyboard-related components don't work quite well if you have "adjustPan" set for your android:windowSoftInputMode in AndroidManifest. xml . Instead, you should use "adjustResize" and have a wonderful life.
KeyboardAvoidingView is a React Native built-in component with full JS implementation. It relies on RN's keyboard events ( keyboardWillChangeFrame on iOS & keyboardDidHide/Show on Android) and, based on provided behavior prop, applies additional padding, translation, or changes container's height.
The first thing you have to do is replace the container View with the KeyboardAvoidingView and then add a behavior prop to it. If you look at the documentation you'll see that it accepts 3 different values — height, padding, position. I've found that padding works in the most predictable manner.
keyboardVerticalOffset This is the distance between the top of the user screen and the react native view, may be non-zero in some use cases.
Post a comment KeyboardAvoidingView is a core component in React Native. This component makes sure the virtual keyboard will never cover the TextInput component so that your user can type without annoyance. Without KeyboardAvodingView, a TextInput might be overlapped by the soft keyboard if it stays near the bottom of the screen:
There are different ways to solve it. One of the easiest ways is to use KeyboardAvoidingView that you will get with the react-native package. It automatically adjusts the bottom padding of the view based on the keyboard position. In this post, I will show you how to use KeyboardAvoidingView with a simple example.
KeyboardAvoidingView component is used to avoid keyboard overlapping on TextInput widget in react native. By default if we do not use KeyboardAvoidingView then Keypad will show above TextInput widget on focus.
KeyboardAvoidingView comes with the react-native package. If we wrap all other components inside it, it will move the components once the keyboard appears. For the above example, after adding KeyboardAvoidingView, it will give the following result : Following are the props it accepts :
You can set the padding, you can even set for android and ios
import {KeyboardAvoidingView,Platform,} from 'react-native';
<KeyboardAvoidingView
behavior='padding'
keyboardVerticalOffset={
Platform.select({
ios: () => 0,
android: () => 200
})()
}>
...content...
</KeyboardAvoidingView>
Just an example, try it out and set how you like. The padding can also be a negative value like -300.
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