Skip to content

Commit c7f2ce2

Browse files
gorhomeastroot1590
andauthored
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 <[email protected]>
1 parent 5281041 commit c7f2ce2

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed

src/components/bottomSheet/BottomSheet.tsx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ import {
7373
INITIAL_SNAP_POINT,
7474
DEFAULT_ENABLE_PAN_DOWN_TO_CLOSE,
7575
INITIAL_CONTAINER_OFFSET,
76+
INITIAL_VALUE,
7677
} from './constants';
7778
import type { BottomSheetMethods, Insets } from '../../types';
7879
import type { BottomSheetProps, AnimateToPositionType } from './types';
@@ -210,7 +211,7 @@ const BottomSheetComponent = forwardRef<BottomSheet, BottomSheetProps>(
210211
animateOnMount ? -1 : _providedIndex
211212
);
212213
const animatedPosition = useSharedValue(INITIAL_POSITION);
213-
const animatedNextPosition = useSharedValue(0);
214+
const animatedNextPosition = useSharedValue(INITIAL_VALUE);
214215
const animatedNextPositionIndex = useSharedValue(0);
215216

216217
// conditional
@@ -651,8 +652,8 @@ const BottomSheetComponent = forwardRef<BottomSheet, BottomSheetProps>(
651652

652653
animatedAnimationSource.value = ANIMATION_SOURCE.NONE;
653654
animatedAnimationState.value = ANIMATION_STATE.STOPPED;
654-
animatedNextPosition.value = Number.NEGATIVE_INFINITY;
655-
animatedNextPositionIndex.value = Number.NEGATIVE_INFINITY;
655+
animatedNextPosition.value = INITIAL_VALUE;
656+
animatedNextPositionIndex.value = INITIAL_VALUE;
656657
}
657658
);
658659
const animateToPosition: AnimateToPositionType = useWorkletCallback(

src/components/bottomSheet/constants.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ const DEFAULT_KEYBOARD_BLUR_BEHAVIOR = KEYBOARD_BLUR_BEHAVIOR.none;
2020
const DEFAULT_KEYBOARD_INPUT_MODE = KEYBOARD_INPUT_MODE.adjustPan;
2121

2222
// initial values
23+
const INITIAL_VALUE = Number.NEGATIVE_INFINITY;
2324
const INITIAL_SNAP_POINT = -999;
2425
const INITIAL_CONTAINER_HEIGHT = -999;
2526
const INITIAL_CONTAINER_OFFSET = {
@@ -49,4 +50,5 @@ export {
4950
INITIAL_CONTAINER_OFFSET,
5051
INITIAL_HANDLE_HEIGHT,
5152
INITIAL_SNAP_POINT,
53+
INITIAL_VALUE,
5254
};

0 commit comments

Comments
 (0)