@@ -683,9 +683,9 @@ const BottomSheetComponent = forwardRef<BottomSheet, BottomSheetProps>(
683683 method : animateToPosition . name ,
684684 params : {
685685 currentPosition : animatedPosition . value ,
686- position,
686+ nextPosition : position ,
687687 velocity,
688- animatedContainerHeight : animatedContainerHeight . value ,
688+ source ,
689689 } ,
690690 } ) ;
691691
@@ -733,6 +733,47 @@ const BottomSheetComponent = forwardRef<BottomSheet, BottomSheetProps>(
733733 } ,
734734 [ handleOnAnimate , _providedAnimationConfigs ]
735735 ) ;
736+ /**
737+ * Set to position without animation.
738+ *
739+ * @param targetPosition position to be set.
740+ */
741+ const setToPosition = useWorkletCallback ( function setToPosition (
742+ targetPosition : number
743+ ) {
744+ if (
745+ targetPosition === animatedPosition . value ||
746+ targetPosition === undefined ||
747+ ( animatedAnimationState . value === ANIMATION_STATE . RUNNING &&
748+ targetPosition === animatedNextPosition . value )
749+ ) {
750+ return ;
751+ }
752+
753+ runOnJS ( print ) ( {
754+ component : BottomSheet . name ,
755+ method : setToPosition . name ,
756+ params : {
757+ currentPosition : animatedPosition . value ,
758+ targetPosition,
759+ } ,
760+ } ) ;
761+
762+ /**
763+ * store next position
764+ */
765+ animatedNextPosition . value = targetPosition ;
766+ animatedNextPositionIndex . value =
767+ animatedSnapPoints . value . indexOf ( targetPosition ) ;
768+
769+ stopAnimation ( ) ;
770+
771+ /**
772+ * set position.
773+ */
774+ animatedPosition . value = targetPosition ;
775+ } ,
776+ [ ] ) ;
736777 //#endregion
737778
738779 //#region public methods
@@ -1311,16 +1352,8 @@ const BottomSheetComponent = forwardRef<BottomSheet, BottomSheetProps>(
13111352 animatedNextPositionIndex . value === - 1 &&
13121353 _previousContainerHeight !== containerHeight
13131354 ) {
1314- animationSource = ANIMATION_SOURCE . CONTAINER_RESIZE ;
1315- animationConfig = {
1316- duration : 0 ,
1317- } ;
1318- animateToPosition (
1319- containerHeight ,
1320- animationSource ,
1321- 0 ,
1322- animationConfig
1323- ) ;
1355+ setToPosition ( containerHeight ) ;
1356+ return ;
13241357 }
13251358
13261359 if (
@@ -1361,13 +1394,11 @@ const BottomSheetComponent = forwardRef<BottomSheet, BottomSheetProps>(
13611394
13621395 /**
13631396 * if snap points changes because of the container height change,
1364- * then we skip the snap animation by setting the duration to 0 .
1397+ * then we set the new position without animation .
13651398 */
13661399 if ( containerHeight !== _previousContainerHeight ) {
1367- animationSource = ANIMATION_SOURCE . CONTAINER_RESIZE ;
1368- animationConfig = {
1369- duration : 0 ,
1370- } ;
1400+ setToPosition ( nextPosition ) ;
1401+ return ;
13711402 }
13721403 }
13731404 animateToPosition ( nextPosition , animationSource , 0 , animationConfig ) ;
@@ -1524,6 +1555,7 @@ const BottomSheetComponent = forwardRef<BottomSheet, BottomSheetProps>(
15241555 } ) ,
15251556 ( {
15261557 _animatedIndex,
1558+ _animatedPosition,
15271559 _animationState,
15281560 _contentGestureState,
15291561 _handleGestureState,
@@ -1535,6 +1567,21 @@ const BottomSheetComponent = forwardRef<BottomSheet, BottomSheetProps>(
15351567 return ;
15361568 }
15371569
1570+ /**
1571+ * exit the method if index value is not synced with
1572+ * position value.
1573+ *
1574+ * [read more](https://github.com/gorhom/react-native-bottom-sheet/issues/1356)
1575+ */
1576+ if (
1577+ animatedNextPosition . value !== INITIAL_VALUE &&
1578+ animatedNextPositionIndex . value !== INITIAL_VALUE &&
1579+ ( _animatedPosition !== animatedNextPosition . value ||
1580+ _animatedIndex !== animatedNextPositionIndex . value )
1581+ ) {
1582+ return ;
1583+ }
1584+
15381585 /**
15391586 * exit the method if animated index value
15401587 * has fraction, e.g. 1.99, 0.52
0 commit comments