Skip to content

Commit

Permalink
fix KeyboardAvoidingView infinite jump on android
Browse files Browse the repository at this point in the history
  • Loading branch information
Kudo committed Dec 7, 2024
1 parent e9f92fa commit 59ab63c
Showing 1 changed file with 23 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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))));
}
}

Expand Down Expand Up @@ -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));
}
Expand Down

0 comments on commit 59ab63c

Please sign in to comment.