Skip to content

Commit f8cd4fe

Browse files
committed
fix(#2449): adjust next index to the highest detent index when animating by keyboard
1 parent 20de151 commit f8cd4fe

File tree

2 files changed

+10
-12
lines changed

2 files changed

+10
-12
lines changed

src/components/bottomSheet/BottomSheet.tsx

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ import {
7777
DEFAULT_ENABLE_PAN_DOWN_TO_CLOSE,
7878
DEFAULT_KEYBOARD_BEHAVIOR,
7979
DEFAULT_KEYBOARD_BLUR_BEHAVIOR,
80+
DEFAULT_KEYBOARD_INDEX,
8081
DEFAULT_KEYBOARD_INPUT_MODE,
8182
DEFAULT_OVER_DRAG_RESISTANCE_FACTOR,
8283
INITIAL_POSITION,
@@ -552,10 +553,6 @@ const BottomSheetComponent = forwardRef<BottomSheet, BottomSheetProps>(
552553
return;
553554
}
554555

555-
if (animatedAnimationState.get().source === ANIMATION_SOURCE.MOUNT) {
556-
isAnimatedOnMount.value = true;
557-
}
558-
559556
// callbacks
560557
if (nextIndex !== animatedCurrentIndex.get()) {
561558
runOnJS(handleOnChange)(nextIndex, nextPosition);
@@ -568,14 +565,15 @@ const BottomSheetComponent = forwardRef<BottomSheet, BottomSheetProps>(
568565
animatedCurrentIndex.set(nextIndex);
569566

570567
// reset values
568+
animatedContainerHeightDidChange.set(false);
569+
isAnimatedOnMount.set(true);
571570
animatedAnimationState.set({
572571
status: ANIMATION_STATUS.STOPPED,
573572
source: ANIMATION_SOURCE.NONE,
574573
nextIndex: undefined,
575574
nextPosition: undefined,
576575
isForcedClosing: undefined,
577576
});
578-
animatedContainerHeightDidChange.value = false;
579577
},
580578
[
581579
handleOnChange,
@@ -642,21 +640,21 @@ const BottomSheetComponent = forwardRef<BottomSheet, BottomSheetProps>(
642640
) {
643641
offset = heightWithinContainer;
644642
}
645-
646643
const { detents } = animatedDetentsState.get();
647644
let index = detents?.indexOf(position + offset) ?? -1;
648645

649646
/**
650647
* because keyboard position is not part of the detents array,
651-
* we need to keep the index to the current index.
648+
* we will need to manually set the index to the highest detent index.
652649
*/
653650
if (
654651
index === -1 &&
655652
status === KEYBOARD_STATUS.SHOWN &&
656-
source === ANIMATION_SOURCE.KEYBOARD &&
657-
isInTemporaryPosition.get()
653+
source === ANIMATION_SOURCE.KEYBOARD
658654
) {
659-
index = animatedCurrentIndex.value;
655+
index =
656+
animatedDetentsState.get().highestDetentPosition ??
657+
DEFAULT_KEYBOARD_INDEX;
660658
}
661659

662660
/**
@@ -700,8 +698,6 @@ const BottomSheetComponent = forwardRef<BottomSheet, BottomSheetProps>(
700698
animatedAnimationState,
701699
animatedKeyboardState,
702700
animatedPosition,
703-
animatedCurrentIndex,
704-
isInTemporaryPosition,
705701
]
706702
);
707703
/**

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_BEHAVIOR = KEYBOARD_BEHAVIOR.interactive;
2020
const DEFAULT_KEYBOARD_BLUR_BEHAVIOR = KEYBOARD_BLUR_BEHAVIOR.none;
2121
const DEFAULT_KEYBOARD_INPUT_MODE = KEYBOARD_INPUT_MODE.adjustPan;
2222
const DEFAULT_ENABLE_BLUR_KEYBOARD_ON_GESTURE = false;
23+
const DEFAULT_KEYBOARD_INDEX = -998;
2324

2425
// initial values
2526
const INITIAL_VALUE = Number.NEGATIVE_INFINITY;
@@ -45,6 +46,7 @@ export {
4546
DEFAULT_KEYBOARD_BLUR_BEHAVIOR,
4647
DEFAULT_KEYBOARD_INPUT_MODE,
4748
DEFAULT_ENABLE_BLUR_KEYBOARD_ON_GESTURE,
49+
DEFAULT_KEYBOARD_INDEX,
4850
// layout
4951
INITIAL_POSITION,
5052
INITIAL_SNAP_POINT,

0 commit comments

Comments
 (0)