From 400d7b93caa0a46f678db2978e7e5f95cc87ee99 Mon Sep 17 00:00:00 2001 From: Mo Gorhom Date: Sun, 16 May 2021 12:25:09 +0100 Subject: [PATCH] fix: prevent animatedPosition from becoming undefined --- src/components/bottomSheet/BottomSheet.tsx | 76 +++++++++++----------- 1 file changed, 39 insertions(+), 37 deletions(-) diff --git a/src/components/bottomSheet/BottomSheet.tsx b/src/components/bottomSheet/BottomSheet.tsx index 1ef531858..56b432c0e 100644 --- a/src/components/bottomSheet/BottomSheet.tsx +++ b/src/components/bottomSheet/BottomSheet.tsx @@ -85,7 +85,8 @@ const BottomSheetComponent = forwardRef( //#region extract props const { // animations configurations - animationDuration: _providedAnimationDuration = DEFAULT_ANIMATION_DURATION, + animationDuration: + _providedAnimationDuration = DEFAULT_ANIMATION_DURATION, animationEasing: _providedAnimationEasing = DEFAULT_ANIMATION_EASING, animationConfigs: _providedAnimationConfigs, @@ -501,41 +502,37 @@ const BottomSheetComponent = forwardRef( //#endregion //#region gesture interaction hooks - const [ - contentPanGestureHandler, - contentPanGestureState, - ] = useInteractivePanGestureHandler({ - type: GESTURE.CONTENT, - enableOverDrag, - enablePanDownToClose, - overDragResistanceFactor, - keyboardState, - keyboardHeight, - keyboardBehavior: keyboardBehavior, - animatedPosition, - animatedSnapPoints, - animatedContainerHeight, - isExtendedByKeyboard: isInTemporaryPosition, - scrollableContentOffsetY, - animateToPoint: animateToPosition, - }); - const [ - handlePanGestureHandler, - handlePanGestureState, - ] = useInteractivePanGestureHandler({ - type: GESTURE.HANDLE, - enableOverDrag, - enablePanDownToClose, - overDragResistanceFactor, - keyboardState, - keyboardHeight, - keyboardBehavior, - animatedPosition, - animatedSnapPoints, - animatedContainerHeight, - isExtendedByKeyboard: isInTemporaryPosition, - animateToPoint: animateToPosition, - }); + const [contentPanGestureHandler, contentPanGestureState] = + useInteractivePanGestureHandler({ + type: GESTURE.CONTENT, + enableOverDrag, + enablePanDownToClose, + overDragResistanceFactor, + keyboardState, + keyboardHeight, + keyboardBehavior: keyboardBehavior, + animatedPosition, + animatedSnapPoints, + animatedContainerHeight, + isExtendedByKeyboard: isInTemporaryPosition, + scrollableContentOffsetY, + animateToPoint: animateToPosition, + }); + const [handlePanGestureHandler, handlePanGestureState] = + useInteractivePanGestureHandler({ + type: GESTURE.HANDLE, + enableOverDrag, + enablePanDownToClose, + overDragResistanceFactor, + keyboardState, + keyboardHeight, + keyboardBehavior, + animatedPosition, + animatedSnapPoints, + animatedContainerHeight, + isExtendedByKeyboard: isInTemporaryPosition, + animateToPoint: animateToPosition, + }); //#endregion //#region public methods @@ -847,7 +844,12 @@ const BottomSheetComponent = forwardRef( }, }); - const nextPosition = _animatedSnapPoints[animatedCurrentIndex.value]; + let nextPosition; + if (animatedCurrentIndex.value === -1) { + nextPosition = animatedContainerHeight.value; + } else { + nextPosition = _animatedSnapPoints[animatedCurrentIndex.value]; + } animateToPosition(nextPosition); } );