Skip to content

Commit

Permalink
fix(#1119): fixed race condition between onmount and keyboard animations
Browse files Browse the repository at this point in the history
  • Loading branch information
gorhom committed Oct 3, 2022
1 parent 6a4d296 commit a1ec74d
Showing 1 changed file with 46 additions and 25 deletions.
71 changes: 46 additions & 25 deletions src/components/bottomSheet/BottomSheet.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -567,6 +567,10 @@ const BottomSheetComponent = forwardRef<BottomSheet, BottomSheetProps>(
return animatedPosition.value;
}

if (!isAnimatedOnMount.value) {
return snapPoints[_providedIndex];
}

return snapPoints[currentIndex];
},
[
Expand All @@ -579,8 +583,10 @@ const BottomSheetComponent = forwardRef<BottomSheet, BottomSheetProps>(
animatedPosition,
animatedSnapPoints,
isInTemporaryPosition,
isAnimatedOnMount,
keyboardBehavior,
keyboardBlurBehavior,
_providedIndex,
]
);
const handleOnChange = useCallback(
Expand Down Expand Up @@ -1238,7 +1244,7 @@ const BottomSheetComponent = forwardRef<BottomSheet, BottomSheetProps>(
nextPosition = animatedClosedPosition.value;
animatedNextPositionIndex.value = -1;
} else {
nextPosition = animatedSnapPoints.value[_providedIndex];
nextPosition = getNextPosition();
}

runOnJS(print)({
Expand Down Expand Up @@ -1371,37 +1377,52 @@ const BottomSheetComponent = forwardRef<BottomSheet, BottomSheetProps>(
)
: Math.abs(_keyboardHeight - animatedContainerOffset.value.bottom);

/**
* if keyboard state is equal to the previous state, then exit the method
*/
if (
_keyboardState === _previousKeyboardState &&
_keyboardHeight === _previousKeyboardHeight
) {
return;
}

/**
* if user is interacting with sheet, then exit the method
*/
const hasActiveGesture =
animatedContentGestureState.value === State.ACTIVE ||
animatedContentGestureState.value === State.BEGAN ||
animatedHandleGestureState.value === State.ACTIVE ||
animatedHandleGestureState.value === State.BEGAN;
if (hasActiveGesture) {
return;
}

/**
* if sheet not animated on mount yet, then exit the method
*/
if (!isAnimatedOnMount.value) {
return;
}

/**
* if new keyboard state is hidden and blur behavior is none, then exit the method
*/
if (
_keyboardState === KEYBOARD_STATE.HIDDEN &&
keyboardBlurBehavior === KEYBOARD_BLUR_BEHAVIOR.none
) {
return;
}

/**
* if platform is android and the input mode is resize, then exit the method
*/
if (
/**
* if keyboard state is equal to the previous state, then exit the method
*/
(_keyboardState === _previousKeyboardState &&
_keyboardHeight === _previousKeyboardHeight) ||
/**
* if user is interacting with sheet, then exit the method
*/
hasActiveGesture ||
/**
* if sheet not animated on mount yet, then exit the method
*/
!isAnimatedOnMount.value ||
/**
* if new keyboard state is hidden and blur behavior is none, then exit the method
*/
(_keyboardState === KEYBOARD_STATE.HIDDEN &&
keyboardBlurBehavior === KEYBOARD_BLUR_BEHAVIOR.none) ||
/**
* if platform is android and the input mode is resize, then exit the method
*/
(Platform.OS === 'android' &&
keyboardBehavior === KEYBOARD_BEHAVIOR.interactive &&
android_keyboardInputMode === KEYBOARD_INPUT_MODE.adjustResize)
Platform.OS === 'android' &&
keyboardBehavior === KEYBOARD_BEHAVIOR.interactive &&
android_keyboardInputMode === KEYBOARD_INPUT_MODE.adjustResize
) {
animatedKeyboardHeightInContainer.value = 0;
return;
Expand Down

0 comments on commit a1ec74d

Please sign in to comment.