From c7f2ce26fdaf525951b70b76cd857e0b63cb4865 Mon Sep 17 00:00:00 2001 From: Mo Gorhom Date: Sun, 31 Jul 2022 18:04:35 +0100 Subject: [PATCH] fix: closed bottom sheet snap point (by @eastroot1590) (#1043, #1035) * fix: closed bottom sheet snap point closed bottom sheet can't directly snap to 100% because initial animatedNextPosition is 0 and 100%'s nextPosition is 0 too. * refactor: extracted initial next value to constants file Co-authored-by: Bran --- src/components/bottomSheet/BottomSheet.tsx | 7 ++++--- src/components/bottomSheet/constants.ts | 2 ++ 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/components/bottomSheet/BottomSheet.tsx b/src/components/bottomSheet/BottomSheet.tsx index 7ac1bbf53..74442cde3 100644 --- a/src/components/bottomSheet/BottomSheet.tsx +++ b/src/components/bottomSheet/BottomSheet.tsx @@ -73,6 +73,7 @@ import { INITIAL_SNAP_POINT, DEFAULT_ENABLE_PAN_DOWN_TO_CLOSE, INITIAL_CONTAINER_OFFSET, + INITIAL_VALUE, } from './constants'; import type { BottomSheetMethods, Insets } from '../../types'; import type { BottomSheetProps, AnimateToPositionType } from './types'; @@ -210,7 +211,7 @@ const BottomSheetComponent = forwardRef( animateOnMount ? -1 : _providedIndex ); const animatedPosition = useSharedValue(INITIAL_POSITION); - const animatedNextPosition = useSharedValue(0); + const animatedNextPosition = useSharedValue(INITIAL_VALUE); const animatedNextPositionIndex = useSharedValue(0); // conditional @@ -651,8 +652,8 @@ const BottomSheetComponent = forwardRef( animatedAnimationSource.value = ANIMATION_SOURCE.NONE; animatedAnimationState.value = ANIMATION_STATE.STOPPED; - animatedNextPosition.value = Number.NEGATIVE_INFINITY; - animatedNextPositionIndex.value = Number.NEGATIVE_INFINITY; + animatedNextPosition.value = INITIAL_VALUE; + animatedNextPositionIndex.value = INITIAL_VALUE; } ); const animateToPosition: AnimateToPositionType = useWorkletCallback( diff --git a/src/components/bottomSheet/constants.ts b/src/components/bottomSheet/constants.ts index a30aaaecd..a08599191 100644 --- a/src/components/bottomSheet/constants.ts +++ b/src/components/bottomSheet/constants.ts @@ -20,6 +20,7 @@ const DEFAULT_KEYBOARD_BLUR_BEHAVIOR = KEYBOARD_BLUR_BEHAVIOR.none; const DEFAULT_KEYBOARD_INPUT_MODE = KEYBOARD_INPUT_MODE.adjustPan; // initial values +const INITIAL_VALUE = Number.NEGATIVE_INFINITY; const INITIAL_SNAP_POINT = -999; const INITIAL_CONTAINER_HEIGHT = -999; const INITIAL_CONTAINER_OFFSET = { @@ -49,4 +50,5 @@ export { INITIAL_CONTAINER_OFFSET, INITIAL_HANDLE_HEIGHT, INITIAL_SNAP_POINT, + INITIAL_VALUE, };