@@ -713,9 +713,9 @@ const BottomSheetComponent = forwardRef<BottomSheet, BottomSheetProps>(
713713 method : animateToPosition . name ,
714714 params : {
715715 currentPosition : animatedPosition . value ,
716- position,
716+ nextPosition : position ,
717717 velocity,
718- animatedContainerHeight : animatedContainerHeight . value ,
718+ source ,
719719 } ,
720720 } ) ;
721721
@@ -763,6 +763,47 @@ const BottomSheetComponent = forwardRef<BottomSheet, BottomSheetProps>(
763763 } ,
764764 [ handleOnAnimate , _providedAnimationConfigs ]
765765 ) ;
766+ /**
767+ * Set to position without animation.
768+ *
769+ * @param targetPosition position to be set.
770+ */
771+ const setToPosition = useWorkletCallback ( function setToPosition (
772+ targetPosition : number
773+ ) {
774+ if (
775+ targetPosition === animatedPosition . value ||
776+ targetPosition === undefined ||
777+ ( animatedAnimationState . value === ANIMATION_STATE . RUNNING &&
778+ targetPosition === animatedNextPosition . value )
779+ ) {
780+ return ;
781+ }
782+
783+ runOnJS ( print ) ( {
784+ component : BottomSheet . name ,
785+ method : setToPosition . name ,
786+ params : {
787+ currentPosition : animatedPosition . value ,
788+ targetPosition,
789+ } ,
790+ } ) ;
791+
792+ /**
793+ * store next position
794+ */
795+ animatedNextPosition . value = targetPosition ;
796+ animatedNextPositionIndex . value =
797+ animatedSnapPoints . value . indexOf ( targetPosition ) ;
798+
799+ stopAnimation ( ) ;
800+
801+ /**
802+ * set position.
803+ */
804+ animatedPosition . value = targetPosition ;
805+ } ,
806+ [ ] ) ;
766807 //#endregion
767808
768809 //#region public methods
@@ -1343,16 +1384,8 @@ const BottomSheetComponent = forwardRef<BottomSheet, BottomSheetProps>(
13431384 animatedNextPositionIndex . value === - 1 &&
13441385 _previousContainerHeight !== containerHeight
13451386 ) {
1346- animationSource = ANIMATION_SOURCE . CONTAINER_RESIZE ;
1347- animationConfig = {
1348- duration : 0 ,
1349- } ;
1350- animateToPosition (
1351- containerHeight ,
1352- animationSource ,
1353- 0 ,
1354- animationConfig
1355- ) ;
1387+ setToPosition ( containerHeight ) ;
1388+ return ;
13561389 }
13571390
13581391 if (
@@ -1393,13 +1426,11 @@ const BottomSheetComponent = forwardRef<BottomSheet, BottomSheetProps>(
13931426
13941427 /**
13951428 * if snap points changes because of the container height change,
1396- * then we skip the snap animation by setting the duration to 0 .
1429+ * then we set the new position without animation .
13971430 */
13981431 if ( containerHeight !== _previousContainerHeight ) {
1399- animationSource = ANIMATION_SOURCE . CONTAINER_RESIZE ;
1400- animationConfig = {
1401- duration : 0 ,
1402- } ;
1432+ setToPosition ( nextPosition ) ;
1433+ return ;
14031434 }
14041435 }
14051436 animateToPosition ( nextPosition , animationSource , 0 , animationConfig ) ;
@@ -1553,6 +1584,7 @@ const BottomSheetComponent = forwardRef<BottomSheet, BottomSheetProps>(
15531584 } ) ,
15541585 ( {
15551586 _animatedIndex,
1587+ _animatedPosition,
15561588 _animationState,
15571589 _contentGestureState,
15581590 _handleGestureState,
@@ -1564,6 +1596,21 @@ const BottomSheetComponent = forwardRef<BottomSheet, BottomSheetProps>(
15641596 return ;
15651597 }
15661598
1599+ /**
1600+ * exit the method if index value is not synced with
1601+ * position value.
1602+ *
1603+ * [read more](https://github.com/gorhom/react-native-bottom-sheet/issues/1356)
1604+ */
1605+ if (
1606+ animatedNextPosition . value !== INITIAL_VALUE &&
1607+ animatedNextPositionIndex . value !== INITIAL_VALUE &&
1608+ ( _animatedPosition !== animatedNextPosition . value ||
1609+ _animatedIndex !== animatedNextPositionIndex . value )
1610+ ) {
1611+ return ;
1612+ }
1613+
15671614 /**
15681615 * exit the method if animated index value
15691616 * has fraction, e.g. 1.99, 0.52
0 commit comments