From 15181e2439c7210e8ed7a8a526bd4a5968b6151d Mon Sep 17 00:00:00 2001 From: David Pett Date: Tue, 9 Oct 2018 07:09:10 -0500 Subject: [PATCH] Use correct keyboard events on android `keyboardWillShow/Hide` don't always emit on android, but `keyboardDidShow/Hide` do --- src/KeyboardAwareBase.js | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/src/KeyboardAwareBase.js b/src/KeyboardAwareBase.js index abc665f6..9ddc17b6 100644 --- a/src/KeyboardAwareBase.js +++ b/src/KeyboardAwareBase.js @@ -7,7 +7,8 @@ import ReactNative, { DeviceEventEmitter, Keyboard, NativeModules, - InteractionManager + InteractionManager, + Platform } from 'react-native'; const ScrollViewManager = NativeModules.ScrollViewManager; @@ -27,10 +28,16 @@ export default class KeyboardAwareBase extends Component { _addKeyboardEventListeners() { const KeyboardEventsObj = Keyboard || DeviceEventEmitter; - this.keyboardEventListeners = [ - KeyboardEventsObj.addListener('keyboardWillShow', this._onKeyboardWillShow), - KeyboardEventsObj.addListener('keyboardWillHide', this._onKeyboardWillHide) - ]; + this.keyboardEventListeners = + Platform.OS === 'ios' + ? [ + KeyboardEventsObj.addListener('keyboardWillShow', this._onKeyboardWillShow), + KeyboardEventsObj.addListener('keyboardWillHide', this._onKeyboardWillHide), + ] + : [ + KeyboardEventsObj.addListener('keyboardDidShow', this._onKeyboardWillShow), + KeyboardEventsObj.addListener('keyboardDidHide', this._onKeyboardWillHide), + ]; } _removeKeyboardListeners() {