I'am working right now on the common problem that the keyboard is pushing the app outside the view.
The android:windowSoftInputMode="adjustResize" setting does not work.
Right now i resize the view according to the keyboard by hand like this:
keyboardWillShow(e) {
setTimeout(()=> {
this.keyboardOffset = e.endCoordinates.height;
}, 500)
}
keyboardWillHide(e) {
this.keyboardOffset = 0;
}
///...
const resultingHeight = windowHeight - this.keyboardOffset - Navigator.NavigationBar.Styles.General.TotalNavHeight;
viewStyle = {
height: resultingHeight
};
This almost works. But my problem is that the app is getting pushed outside the view, then the keyboardWillShow is getting fired and resizes the view correct and then nothing happens. Android does not update the layout after the keyboard is shown.
EDIT: The other posts on SO didn't help because the adjustResize setting does not work and i use react-native and not native android.
How do you control what keyboard pushes up React Native? 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.
The most simple solution, and the easiest to install, is KeyboardAvoidingView. It's a core component but it's also pretty simple in what it does. You can take the base code, which has the keyboard covering the inputs, and update that so that the inputs are no longer covered.
If I recall, keyboardwillShow
and keyboardWillHide
are not fired on Android.
This behavior should be native to Android, have you tried setting the windowSoftInputMode as follows and not listening for the events?
android:windowSoftInputMode="adjustPan"
If that's not working for you, you could take a look into KeyboardAvoidingView
, new with 0.34
. it seems to be solving what you are attempting to accomplish.
It is a component to solve the common problem of views that need to move out of the way of the virtual keyboard. It can automatically adjust either its position or bottom padding based on the position of the keyboard.
KeyboardAvoidingView Docs
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