Skip to content

Commit

Permalink
fix: prevent stuck state when animation is interrupted
Browse files Browse the repository at this point in the history
  • Loading branch information
gorhom committed Jul 13, 2021
1 parent 26d3b71 commit 01e1e87
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 12 deletions.
24 changes: 12 additions & 12 deletions src/components/bottomSheet/BottomSheet.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -386,8 +386,8 @@ const BottomSheetComponent = forwardRef<BottomSheet, BottomSheetProps>(
// dynamic
const animatedContentHeight = useDerivedValue(() => {
const keyboardHeightInContainer = getKeyboardHeightInContainer();
let contentHeight =
animatedSheetHeight.value - animatedHandleHeight.value;
const handleHeight = Math.max(0, animatedHandleHeight.value);
let contentHeight = animatedSheetHeight.value - handleHeight;

if (
keyboardBehavior === KEYBOARD_BEHAVIOR.extend &&
Expand All @@ -401,11 +401,10 @@ const BottomSheetComponent = forwardRef<BottomSheet, BottomSheetProps>(
if (animatedKeyboardState.value === KEYBOARD_STATE.SHOWN) {
contentHeight =
animatedContainerHeight.value -
animatedHandleHeight.value -
handleHeight -
keyboardHeightInContainer;
} else {
contentHeight =
animatedContainerHeight.value - animatedHandleHeight.value;
contentHeight = animatedContainerHeight.value - handleHeight;
}
} else if (
keyboardBehavior === KEYBOARD_BEHAVIOR.interactive &&
Expand All @@ -422,14 +421,13 @@ const BottomSheetComponent = forwardRef<BottomSheet, BottomSheetProps>(
contentHeight =
animatedContainerHeight.value -
keyboardHeightInContainer -
animatedHandleHeight.value;
handleHeight;
}
} else if (
contentWithKeyboardHeight + animatedHandleHeight.value >
contentWithKeyboardHeight + handleHeight >
animatedContainerHeight.value
) {
contentHeight =
animatedContainerHeight.value - animatedHandleHeight.value;
contentHeight = animatedContainerHeight.value - handleHeight;
} else {
contentHeight = contentWithKeyboardHeight;
}
Expand Down Expand Up @@ -598,6 +596,7 @@ const BottomSheetComponent = forwardRef<BottomSheet, BottomSheetProps>(
const animateToPositionCompleted = useWorkletCallback(
function animateToPositionCompleted(isFinished: boolean) {
if (!isFinished) {
animatedAnimationState.value = ANIMATION_STATE.INTERRUPTED;
return;
}
runOnJS(print)({
Expand All @@ -624,9 +623,10 @@ const BottomSheetComponent = forwardRef<BottomSheet, BottomSheetProps>(
configs?: Animated.WithTimingConfig | Animated.WithSpringConfig
) {
if (
position === animatedPosition.value ||
position === undefined ||
position === animatedNextPosition.value
animatedAnimationState.value !== ANIMATION_STATE.INTERRUPTED &&
(position === animatedPosition.value ||
position === undefined ||
position === animatedNextPosition.value)
) {
return;
}
Expand Down
1 change: 1 addition & 0 deletions src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ enum ANIMATION_STATE {
UNDETERMINED = 0,
RUNNING,
STOPPED,
INTERRUPTED,
}

enum ANIMATION_SOURCE {
Expand Down

0 comments on commit 01e1e87

Please sign in to comment.