Skip to content

Commit

Permalink
fix(regression): updated keyboard handling reaction (by @yusufyildirim)…
Browse files Browse the repository at this point in the history
… (#979)

* fix: keyboard handling reaction

* fix: coverted animatedKeyboardHeightInContainer from derived to shared value

Co-authored-by: Yusuf YILDIRIM <yusuf@tinythin.gs>
Co-authored-by: gorhom <gorhom.dev@gmail.com>
  • Loading branch information
3 people committed Jun 13, 2022
1 parent 46f5087 commit 1811239
Showing 1 changed file with 15 additions and 30 deletions.
45 changes: 15 additions & 30 deletions src/components/bottomSheet/BottomSheet.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -291,36 +291,7 @@ const BottomSheetComponent = forwardRef<BottomSheet, BottomSheetProps>(
animationEasing: keyboardAnimationEasing,
shouldHandleKeyboardEvents,
} = useKeyboard();
/**
* Returns keyboard height that in the root container.
*/
const animatedKeyboardHeightInContainer = useDerivedValue(() => {
/**
* if android software input mode is not `adjustPan`, than keyboard
* height will be 0 all the time.
*/
if (
Platform.OS === 'android' &&
android_keyboardInputMode === KEYBOARD_INPUT_MODE.adjustResize
) {
return 0;
}

return $modal
? Math.abs(
animatedKeyboardHeight.value -
Math.abs(bottomInset - animatedContainerOffset.value.bottom)
)
: Math.abs(
animatedKeyboardHeight.value - animatedContainerOffset.value.bottom
);
}, [
$modal,
android_keyboardInputMode,
bottomInset,
animatedKeyboardHeight,
animatedContainerOffset,
]);
const animatedKeyboardHeightInContainer = useSharedValue(0);
//#endregion

//#region state/dynamic variables
Expand Down Expand Up @@ -1385,6 +1356,16 @@ const BottomSheetComponent = forwardRef<BottomSheet, BottomSheetProps>(
const _previousKeyboardState = _previousResult?._keyboardState;
const _previousKeyboardHeight = _previousResult?._keyboardHeight;

/**
* Calculate the keyboard height in the container.
*/
animatedKeyboardHeightInContainer.value = $modal
? Math.abs(
_keyboardHeight -
Math.abs(bottomInset - animatedContainerOffset.value.bottom)
)
: Math.abs(_keyboardHeight - animatedContainerOffset.value.bottom);

const hasActiveGesture =
animatedContentGestureState.value === State.ACTIVE ||
animatedContentGestureState.value === State.BEGAN ||
Expand Down Expand Up @@ -1417,6 +1398,7 @@ const BottomSheetComponent = forwardRef<BottomSheet, BottomSheetProps>(
keyboardBehavior === KEYBOARD_BEHAVIOR.interactive &&
android_keyboardInputMode === KEYBOARD_INPUT_MODE.adjustResize)
) {
animatedKeyboardHeightInContainer.value = 0;
return;
}

Expand All @@ -1442,9 +1424,12 @@ const BottomSheetComponent = forwardRef<BottomSheet, BottomSheetProps>(
);
},
[
$modal,
bottomInset,
keyboardBehavior,
keyboardBlurBehavior,
android_keyboardInputMode,
animatedContainerOffset,
getNextPosition,
]
);
Expand Down

0 comments on commit 1811239

Please sign in to comment.