Skip to content

Commit a1ec74d

Browse files
committed
fix(#1119): fixed race condition between onmount and keyboard animations
1 parent 6a4d296 commit a1ec74d

File tree

1 file changed

+46
-25
lines changed

1 file changed

+46
-25
lines changed

src/components/bottomSheet/BottomSheet.tsx

+46-25
Original file line numberDiff line numberDiff line change
@@ -567,6 +567,10 @@ const BottomSheetComponent = forwardRef<BottomSheet, BottomSheetProps>(
567567
return animatedPosition.value;
568568
}
569569

570+
if (!isAnimatedOnMount.value) {
571+
return snapPoints[_providedIndex];
572+
}
573+
570574
return snapPoints[currentIndex];
571575
},
572576
[
@@ -579,8 +583,10 @@ const BottomSheetComponent = forwardRef<BottomSheet, BottomSheetProps>(
579583
animatedPosition,
580584
animatedSnapPoints,
581585
isInTemporaryPosition,
586+
isAnimatedOnMount,
582587
keyboardBehavior,
583588
keyboardBlurBehavior,
589+
_providedIndex,
584590
]
585591
);
586592
const handleOnChange = useCallback(
@@ -1238,7 +1244,7 @@ const BottomSheetComponent = forwardRef<BottomSheet, BottomSheetProps>(
12381244
nextPosition = animatedClosedPosition.value;
12391245
animatedNextPositionIndex.value = -1;
12401246
} else {
1241-
nextPosition = animatedSnapPoints.value[_providedIndex];
1247+
nextPosition = getNextPosition();
12421248
}
12431249

12441250
runOnJS(print)({
@@ -1371,37 +1377,52 @@ const BottomSheetComponent = forwardRef<BottomSheet, BottomSheetProps>(
13711377
)
13721378
: Math.abs(_keyboardHeight - animatedContainerOffset.value.bottom);
13731379

1380+
/**
1381+
* if keyboard state is equal to the previous state, then exit the method
1382+
*/
1383+
if (
1384+
_keyboardState === _previousKeyboardState &&
1385+
_keyboardHeight === _previousKeyboardHeight
1386+
) {
1387+
return;
1388+
}
1389+
1390+
/**
1391+
* if user is interacting with sheet, then exit the method
1392+
*/
13741393
const hasActiveGesture =
13751394
animatedContentGestureState.value === State.ACTIVE ||
13761395
animatedContentGestureState.value === State.BEGAN ||
13771396
animatedHandleGestureState.value === State.ACTIVE ||
13781397
animatedHandleGestureState.value === State.BEGAN;
1398+
if (hasActiveGesture) {
1399+
return;
1400+
}
1401+
1402+
/**
1403+
* if sheet not animated on mount yet, then exit the method
1404+
*/
1405+
if (!isAnimatedOnMount.value) {
1406+
return;
1407+
}
1408+
1409+
/**
1410+
* if new keyboard state is hidden and blur behavior is none, then exit the method
1411+
*/
1412+
if (
1413+
_keyboardState === KEYBOARD_STATE.HIDDEN &&
1414+
keyboardBlurBehavior === KEYBOARD_BLUR_BEHAVIOR.none
1415+
) {
1416+
return;
1417+
}
13791418

1419+
/**
1420+
* if platform is android and the input mode is resize, then exit the method
1421+
*/
13801422
if (
1381-
/**
1382-
* if keyboard state is equal to the previous state, then exit the method
1383-
*/
1384-
(_keyboardState === _previousKeyboardState &&
1385-
_keyboardHeight === _previousKeyboardHeight) ||
1386-
/**
1387-
* if user is interacting with sheet, then exit the method
1388-
*/
1389-
hasActiveGesture ||
1390-
/**
1391-
* if sheet not animated on mount yet, then exit the method
1392-
*/
1393-
!isAnimatedOnMount.value ||
1394-
/**
1395-
* if new keyboard state is hidden and blur behavior is none, then exit the method
1396-
*/
1397-
(_keyboardState === KEYBOARD_STATE.HIDDEN &&
1398-
keyboardBlurBehavior === KEYBOARD_BLUR_BEHAVIOR.none) ||
1399-
/**
1400-
* if platform is android and the input mode is resize, then exit the method
1401-
*/
1402-
(Platform.OS === 'android' &&
1403-
keyboardBehavior === KEYBOARD_BEHAVIOR.interactive &&
1404-
android_keyboardInputMode === KEYBOARD_INPUT_MODE.adjustResize)
1423+
Platform.OS === 'android' &&
1424+
keyboardBehavior === KEYBOARD_BEHAVIOR.interactive &&
1425+
android_keyboardInputMode === KEYBOARD_INPUT_MODE.adjustResize
14051426
) {
14061427
animatedKeyboardHeightInContainer.value = 0;
14071428
return;

0 commit comments

Comments
 (0)