Skip to content

Commit

Permalink
[useAnimatedKeyboard][Android] Fix navigation bar with auto hide (#5742)
Browse files Browse the repository at this point in the history
## Summary

Split of
#5666

It ensures proper respect for auto-hiding navigation bars on Android
devices.
  • Loading branch information
piaskowyk authored Mar 1, 2024
1 parent 7b508cd commit b20d9e0
Showing 1 changed file with 7 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.swmansion.reanimated.keyboard;

import android.view.KeyCharacterMap;
import android.view.KeyEvent;
import androidx.core.view.WindowInsetsCompat;
import com.facebook.react.uimanager.PixelUtil;

Expand All @@ -21,8 +23,11 @@ public int getHeight() {
public void updateHeight(WindowInsetsCompat insets) {
int contentBottomInset = insets.getInsets(CONTENT_TYPE_MASK).bottom;
int systemBarBottomInset = insets.getInsets(SYSTEM_BAR_TYPE_MASK).bottom;
int keyboardHeightDip = Math.max(0, contentBottomInset - systemBarBottomInset);
if (keyboardHeightDip == 0 && mState == KeyboardState.OPEN) {
boolean hasNavigationBar = KeyCharacterMap.deviceHasKey(KeyEvent.KEYCODE_HOME);
int keyboardHeightDip =
hasNavigationBar ? contentBottomInset - systemBarBottomInset : contentBottomInset;
int keyboardHeight = (int) PixelUtil.toDIPFromPixel(Math.max(0, keyboardHeightDip));
if (keyboardHeight == 0 && mState == KeyboardState.OPEN) {
/*
When the keyboard is being canceling, for one frame the insets show a keyboard height of 0,
causing a jump of the keyboard. We can avoid it by ignoring that frame and calling
Expand Down

0 comments on commit b20d9e0

Please sign in to comment.