From 9d6fb6c7cc46c9479b53e4ecddc9b60b88b86bd1 Mon Sep 17 00:00:00 2001 From: Mo Gorhom Date: Sat, 26 Sep 2020 22:21:41 +0200 Subject: [PATCH] fix: updated decelerationRate per platform (#36) --- src/components/bottomSheet/BottomSheet.tsx | 13 +++++++++---- src/constants.ts | 6 ++++++ 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/src/components/bottomSheet/BottomSheet.tsx b/src/components/bottomSheet/BottomSheet.tsx index 6f6b4d8de..af5c34bd7 100644 --- a/src/components/bottomSheet/BottomSheet.tsx +++ b/src/components/bottomSheet/BottomSheet.tsx @@ -45,6 +45,7 @@ import { BottomSheetProvider, } from '../../contexts'; import { + NORMAL_DECELERATION_RATE, DEFAULT_ANIMATION_EASING, DEFAULT_ANIMATION_DURATION, GESTURE, @@ -219,7 +220,11 @@ const BottomSheetComponent = forwardRef( /** * Scrollable animated props. */ - const decelerationRate = cond(greaterThan(position, 0), 0.001, 0.999); + const decelerationRate = cond( + greaterThan(position, 0), + 0.001, + NORMAL_DECELERATION_RATE + ); //#endregion //#region styles @@ -291,11 +296,11 @@ const BottomSheetComponent = forwardRef( const handleExpand = useCallback(() => { manualSnapToPoint.setValue(snapPoints[snapPoints.length - 1]); // eslint-disable-next-line react-hooks/exhaustive-deps - }, [sheetHeight]); + }, [snapPoints]); const handleCollapse = useCallback(() => { manualSnapToPoint.setValue(snapPoints[0]); // eslint-disable-next-line react-hooks/exhaustive-deps - }, [sheetHeight]); + }, [snapPoints]); //#endregion //#region @@ -357,8 +362,8 @@ const BottomSheetComponent = forwardRef( return; } currentPositionIndexRef.current = currentPositionIndex; - handleOnChange(currentPositionIndex); refreshUIElements(); + handleOnChange(currentPositionIndex); }), ]), [snapPoints, refreshUIElements] diff --git a/src/constants.ts b/src/constants.ts index 6c7b5986b..ff0710673 100644 --- a/src/constants.ts +++ b/src/constants.ts @@ -1,3 +1,4 @@ +import { Platform } from 'react-native'; import Animated from 'react-native-reanimated'; const { @@ -11,6 +12,11 @@ export const DEFAULT_ANIMATION_EASING: Animated.EasingFunction = Easing.out( ); export const DEFAULT_ANIMATION_DURATION = 500; +export const NORMAL_DECELERATION_RATE = Platform.select({ + ios: 0.998, + android: 0.985, +}); + export enum GESTURE { UNDETERMINED = 0, CONTENT,