diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/ReactRootView.java b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/ReactRootView.java index a42933c8a5afd1..e8b02a2c649be8 100644 --- a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/ReactRootView.java +++ b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/ReactRootView.java @@ -898,36 +898,27 @@ private void checkForKeyboardEvents() { if (keyboardIsVisible != mKeyboardIsVisible) { mKeyboardIsVisible = keyboardIsVisible; - if (keyboardIsVisible) { - Insets imeInsets = rootInsets.getInsets(WindowInsets.Type.ime()); - Insets barInsets = rootInsets.getInsets(WindowInsets.Type.systemBars()); - int height = imeInsets.bottom - barInsets.bottom; - - ViewGroup.LayoutParams rootLayoutParams = getRootView().getLayoutParams(); - Assertions.assertCondition(rootLayoutParams instanceof WindowManager.LayoutParams); - - int softInputMode = ((WindowManager.LayoutParams) rootLayoutParams).softInputMode; - int screenY = - softInputMode == WindowManager.LayoutParams.SOFT_INPUT_ADJUST_NOTHING - ? mVisibleViewArea.bottom - height - : mVisibleViewArea.bottom; - - sendEvent( - "keyboardDidShow", - createKeyboardEventPayload( - PixelUtil.toDIPFromPixel(screenY), - PixelUtil.toDIPFromPixel(mVisibleViewArea.left), - PixelUtil.toDIPFromPixel(mVisibleViewArea.width()), - PixelUtil.toDIPFromPixel(height))); - } else { - sendEvent( - "keyboardDidHide", - createKeyboardEventPayload( - PixelUtil.toDIPFromPixel(mVisibleViewArea.height()), - 0, - PixelUtil.toDIPFromPixel(mVisibleViewArea.width()), - 0)); - } + Insets imeInsets = rootInsets.getInsets(WindowInsets.Type.ime()); + Insets barInsets = rootInsets.getInsets(WindowInsets.Type.systemBars()); + int height = imeInsets.bottom - barInsets.bottom; + + ViewGroup.LayoutParams rootLayoutParams = getRootView().getLayoutParams(); + Assertions.assertCondition(rootLayoutParams instanceof WindowManager.LayoutParams); + + int softInputMode = ((WindowManager.LayoutParams) rootLayoutParams).softInputMode; + int screenY = + softInputMode == WindowManager.LayoutParams.SOFT_INPUT_ADJUST_NOTHING + ? mVisibleViewArea.bottom - height + : mVisibleViewArea.bottom; + + String eventName = keyboardIsVisible ? "keyboardDidShow" : "keyboardDidHide"; + sendEvent( + eventName, + createKeyboardEventPayload( + PixelUtil.toDIPFromPixel(screenY), + PixelUtil.toDIPFromPixel(mVisibleViewArea.left), + PixelUtil.toDIPFromPixel(mVisibleViewArea.width()), + PixelUtil.toDIPFromPixel(Math.max(height, 0)))); } } @@ -972,8 +963,8 @@ private void checkForKeyboardEventsLegacy() { sendEvent( "keyboardDidHide", createKeyboardEventPayload( - PixelUtil.toDIPFromPixel(mVisibleViewArea.height()), - 0, + PixelUtil.toDIPFromPixel(mVisibleViewArea.bottom), + PixelUtil.toDIPFromPixel(mVisibleViewArea.left), PixelUtil.toDIPFromPixel(mVisibleViewArea.width()), 0)); }