react-native: keyboardWillShow not triggered in Android

I am registering for keyboardWillShow like this:

this.addListenerOn(RCTDeviceEventEmitter, 'keyboardWillShow', this.updateKeyboardSpace);

This works fine in iOS, but in Android it does not trigger the event as expected. keyboardDidShow does work in Android.

About this issue

  • Original URL
  • State: closed
  • Created 9 years ago
  • Reactions: 10
  • Comments: 45 (11 by maintainers)

Commits related to this issue

Most upvoted comments

ok, i somehow missed this, so… for anybody who was confused (like me 😃) i can confirm that keyboardWillShow + keyboardWillHide don’t work on android but keyboardDidShow and keyboardDidHide do work on android.

thanks @skv-headless

Still not working for keyboardWillShow and keyboardWillHide

It’s works both iOS and Android.

state = {
 btnLocation: 0
}
  componentWillMount() {
    this.keyboardDidShowListener = Keyboard.addListener('keyboardDidShow', this._keyboardWillShow.bind(this));
    this.keyboardDidHideListener = Keyboard.addListener('keyboardDidHide', this._keyboardWillHide.bind(this));
  }
  componentWillUnmount () {
    this.keyboardDidShowListener.remove();
    this.keyboardDidHideListener.remove();
  }

  _keyboardWillShow(e) {
    this.setState({btnLocation: e.endCoordinates.height});
  }
  _keyboardWillHide(e) {
    this.setState({btnLocation: 0})
  }

@christopherdro why was this closed? In the docs it says that all event should fire for both iOS and Android: https://facebook.github.io/react-native/docs/keyboard.html

If some events have not been implemented yet, then the docs should be updated to reflect that some events are iOS only.

On Android it sort of works in React 0.41.2 (except for keyboardWillShow/keyboardWillHide)

I have noticed, that if I have set android:windowSoftInputMode to ‘adjustNothing’, these events are not fired.

Why? For me, the default behavior for android:windowSoftInputMode produces layout issues, so i’d like these events to still fire even if I’ve set android:windowSoftInputMode to ‘adjustNothing’

@christopherdro I see this was closed, but I don’t see why. Is there a PR that fixes this? I’d like to follow whatever version it will be released with, if so.

NOTE I don’t think keyboardDidShow is a sufficient replacement for keyboardWillShow

Note that if you set android:windowSoftInputMode to adjustResize or adjustNothing, only keyboardDidShow and keyboardDidHide events will be available on Android. keyboardWillShow as well as keyboardWillHide are generally not available on Android since there is no native corresponding event.

I can confirm that if you set android:windowSoftInputMode to adjustNothing none of events are available for Android.

keyboardWillShow/keyboardWillHide still not working for me on Android and RN 0.47.0

@christopherdro @shergin Can someone explain why this was closed please?

Still the same on Android.

re-open mkayyy

I’m running into the same problem in that the keyboardDidShow and keyboardDidHide are only fired on Android when the android:windowSoftInputMode is set to adjustResize.

However, when the android:windowSoftInputMode is set to adjustResize then when you’re using a TabNavigator from the React Navigation package, when the keyboard on Android shows, it pushes the tabbar (if it’s aligned at the bottom) up with the keyboard. To work around this pushing up you can set android:windowSoftInputMode is set to adjustNothing but doing this means that your content (text fields etc.) are behind your keyboard.

On iOS I’ve been working around this problem by adding a spacer View with a height of the keyboard at the end of my view when the keyboard opens, but since the event doesn’t fire, this work around doesn’t work for Android.

So, at the moment, on Android you can either have keyboard events (with adjustResize) but you will have a pushed up TabNavigator or you can have a hidden TabNavigator and no keyboard events.

It’s a bit of a pickle…

+1 confirmed no event when android:windowSoftInputMode is adjustNothing

I also need the event when android:windowSoftInputMode is adjustNothing 😢

same issue , react native version is 0.44.0