Skip to content

Commit cce1f7e

Browse files
committed
fix: prevent the bottom sheet from closing when over dragging while keyboard is open
1 parent c68edac commit cce1f7e

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

src/components/bottomSheet/BottomSheet.tsx

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -632,15 +632,22 @@ const BottomSheetComponent = forwardRef<BottomSheet, BottomSheetProps>(
632632
* offset the position if keyboard is shown and behavior not extend.
633633
*/
634634
let offset = 0;
635+
635636
const { status, heightWithinContainer } = animatedKeyboardState.get();
637+
const sheetState = animatedSheetState.get();
636638
if (
637639
status === KEYBOARD_STATUS.SHOWN &&
638640
keyboardBehavior !== KEYBOARD_BEHAVIOR.extend &&
639-
[ANIMATION_SOURCE.KEYBOARD, ANIMATION_SOURCE.SNAP_POINT_CHANGE].includes(source)
641+
([
642+
ANIMATION_SOURCE.KEYBOARD,
643+
ANIMATION_SOURCE.SNAP_POINT_CHANGE,
644+
].includes(source) ||
645+
sheetState === SHEET_STATE.OVER_EXTENDED)
640646
) {
641647
offset = heightWithinContainer;
642648
}
643-
const { detents } = animatedDetentsState.get();
649+
const { detents, closedDetentPosition, highestDetentPosition } =
650+
animatedDetentsState.get();
644651
let index = detents?.indexOf(position + offset) ?? -1;
645652

646653
/**
@@ -650,11 +657,9 @@ const BottomSheetComponent = forwardRef<BottomSheet, BottomSheetProps>(
650657
if (
651658
index === -1 &&
652659
status === KEYBOARD_STATUS.SHOWN &&
653-
source === ANIMATION_SOURCE.KEYBOARD
660+
position !== closedDetentPosition
654661
) {
655-
index =
656-
animatedDetentsState.get().highestDetentPosition ??
657-
DEFAULT_KEYBOARD_INDEX;
662+
index = highestDetentPosition ?? DEFAULT_KEYBOARD_INDEX;
658663
}
659664

660665
/**
@@ -698,6 +703,7 @@ const BottomSheetComponent = forwardRef<BottomSheet, BottomSheetProps>(
698703
animatedAnimationState,
699704
animatedKeyboardState,
700705
animatedPosition,
706+
animatedSheetState,
701707
]
702708
);
703709
/**

0 commit comments

Comments
 (0)