@@ -683,9 +683,9 @@ const BottomSheetComponent = forwardRef<BottomSheet, BottomSheetProps>(
683
683
method : animateToPosition . name ,
684
684
params : {
685
685
currentPosition : animatedPosition . value ,
686
- position,
686
+ nextPosition : position ,
687
687
velocity,
688
- animatedContainerHeight : animatedContainerHeight . value ,
688
+ source ,
689
689
} ,
690
690
} ) ;
691
691
@@ -733,6 +733,47 @@ const BottomSheetComponent = forwardRef<BottomSheet, BottomSheetProps>(
733
733
} ,
734
734
[ handleOnAnimate , _providedAnimationConfigs ]
735
735
) ;
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
+ [ ] ) ;
736
777
//#endregion
737
778
738
779
//#region public methods
@@ -1311,16 +1352,8 @@ const BottomSheetComponent = forwardRef<BottomSheet, BottomSheetProps>(
1311
1352
animatedNextPositionIndex . value === - 1 &&
1312
1353
_previousContainerHeight !== containerHeight
1313
1354
) {
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 ;
1324
1357
}
1325
1358
1326
1359
if (
@@ -1361,13 +1394,11 @@ const BottomSheetComponent = forwardRef<BottomSheet, BottomSheetProps>(
1361
1394
1362
1395
/**
1363
1396
* 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 .
1365
1398
*/
1366
1399
if ( containerHeight !== _previousContainerHeight ) {
1367
- animationSource = ANIMATION_SOURCE . CONTAINER_RESIZE ;
1368
- animationConfig = {
1369
- duration : 0 ,
1370
- } ;
1400
+ setToPosition ( nextPosition ) ;
1401
+ return ;
1371
1402
}
1372
1403
}
1373
1404
animateToPosition ( nextPosition , animationSource , 0 , animationConfig ) ;
@@ -1524,6 +1555,7 @@ const BottomSheetComponent = forwardRef<BottomSheet, BottomSheetProps>(
1524
1555
} ) ,
1525
1556
( {
1526
1557
_animatedIndex,
1558
+ _animatedPosition,
1527
1559
_animationState,
1528
1560
_contentGestureState,
1529
1561
_handleGestureState,
@@ -1535,6 +1567,21 @@ const BottomSheetComponent = forwardRef<BottomSheet, BottomSheetProps>(
1535
1567
return ;
1536
1568
}
1537
1569
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
+
1538
1585
/**
1539
1586
* exit the method if animated index value
1540
1587
* has fraction, e.g. 1.99, 0.52
0 commit comments