Skip to content

Commit

Permalink
fix: closed bottom sheet snap point (by @eastroot1590) (#1043, #1035)
Browse files Browse the repository at this point in the history
* 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 <eastroot1590@gmail.com>
  • Loading branch information
gorhom and eastroot1590 committed Jul 31, 2022
1 parent 5281041 commit c7f2ce2
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
7 changes: 4 additions & 3 deletions src/components/bottomSheet/BottomSheet.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -210,7 +211,7 @@ const BottomSheetComponent = forwardRef<BottomSheet, BottomSheetProps>(
animateOnMount ? -1 : _providedIndex
);
const animatedPosition = useSharedValue(INITIAL_POSITION);
const animatedNextPosition = useSharedValue(0);
const animatedNextPosition = useSharedValue(INITIAL_VALUE);
const animatedNextPositionIndex = useSharedValue(0);

// conditional
Expand Down Expand Up @@ -651,8 +652,8 @@ const BottomSheetComponent = forwardRef<BottomSheet, BottomSheetProps>(

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(
Expand Down
2 changes: 2 additions & 0 deletions src/components/bottomSheet/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down Expand Up @@ -49,4 +50,5 @@ export {
INITIAL_CONTAINER_OFFSET,
INITIAL_HANDLE_HEIGHT,
INITIAL_SNAP_POINT,
INITIAL_VALUE,
};

0 comments on commit c7f2ce2

Please sign in to comment.