@@ -22,8 +22,9 @@ import Animated, {
22
22
useWorkletCallback ,
23
23
type WithSpringConfig ,
24
24
type WithTimingConfig ,
25
+ useReducedMotion ,
26
+ ReduceMotion ,
25
27
} from 'react-native-reanimated' ;
26
- // import BottomSheetDebugView from '../bottomSheetDebugView';
27
28
import {
28
29
ANIMATION_SOURCE ,
29
30
ANIMATION_STATE ,
@@ -56,6 +57,7 @@ import {
56
57
import BottomSheetBackdropContainer from '../bottomSheetBackdropContainer' ;
57
58
import BottomSheetBackgroundContainer from '../bottomSheetBackgroundContainer' ;
58
59
import BottomSheetContainer from '../bottomSheetContainer' ;
60
+ // import BottomSheetDebugView from '../bottomSheetDebugView';
59
61
import BottomSheetDraggableView from '../bottomSheetDraggableView' ;
60
62
import BottomSheetFooterContainer from '../bottomSheetFooterContainer/BottomSheetFooterContainer' ;
61
63
import BottomSheetGestureHandlersProvider from '../bottomSheetGestureHandlersProvider' ;
@@ -106,6 +108,7 @@ const BottomSheetComponent = forwardRef<BottomSheet, BottomSheetProps>(
106
108
enablePanDownToClose = DEFAULT_ENABLE_PAN_DOWN_TO_CLOSE ,
107
109
enableDynamicSizing = DEFAULT_DYNAMIC_SIZING ,
108
110
overDragResistanceFactor = DEFAULT_OVER_DRAG_RESISTANCE_FACTOR ,
111
+ overrideReduceMotion : _providedOverrideReduceMotion ,
109
112
110
113
// styles
111
114
style : _providedStyle ,
@@ -318,6 +321,13 @@ const BottomSheetComponent = forwardRef<BottomSheet, BottomSheetProps>(
318
321
shouldHandleKeyboardEvents,
319
322
} = useKeyboard ( ) ;
320
323
const animatedKeyboardHeightInContainer = useSharedValue ( 0 ) ;
324
+ const userReduceMotionSetting = useReducedMotion ( ) ;
325
+ const reduceMotion = useMemo ( ( ) => {
326
+ return ! _providedOverrideReduceMotion ||
327
+ _providedOverrideReduceMotion === ReduceMotion . System
328
+ ? userReduceMotionSetting
329
+ : _providedOverrideReduceMotion === ReduceMotion . Always ;
330
+ } , [ userReduceMotionSetting , _providedOverrideReduceMotion ] ) ;
321
331
//#endregion
322
332
323
333
//#region state/dynamic variables
@@ -640,9 +650,8 @@ const BottomSheetComponent = forwardRef<BottomSheet, BottomSheetProps>(
640
650
isAnimatedOnMount . value = true ;
641
651
}
642
652
643
- isForcedClosing . value = false ;
644
-
645
653
// reset values
654
+ isForcedClosing . value = false ;
646
655
animatedAnimationSource . value = ANIMATION_SOURCE . NONE ;
647
656
animatedAnimationState . value = ANIMATION_STATE . STOPPED ;
648
657
animatedNextPosition . value = INITIAL_VALUE ;
@@ -717,10 +726,15 @@ const BottomSheetComponent = forwardRef<BottomSheet, BottomSheetProps>(
717
726
point : position ,
718
727
configs : configs || _providedAnimationConfigs ,
719
728
velocity,
729
+ overrideReduceMotion : _providedOverrideReduceMotion ,
720
730
onComplete : animateToPositionCompleted ,
721
731
} ) ;
722
732
} ,
723
- [ handleOnAnimate , _providedAnimationConfigs ]
733
+ [
734
+ handleOnAnimate ,
735
+ _providedAnimationConfigs ,
736
+ _providedOverrideReduceMotion ,
737
+ ]
724
738
) ;
725
739
/**
726
740
* Set to position without animation.
@@ -963,6 +977,16 @@ const BottomSheetComponent = forwardRef<BottomSheet, BottomSheetProps>(
963
977
animatedAnimationState . value !== ANIMATION_STATE . RUNNING &&
964
978
animatedCurrentIndex . value === - 1
965
979
) {
980
+ /**
981
+ * early exit if reduce motion is enabled and index is out of sync with position.
982
+ */
983
+ if (
984
+ reduceMotion &&
985
+ animatedSnapPoints . value [ animatedIndex . value ] !==
986
+ animatedPosition . value
987
+ ) {
988
+ return ;
989
+ }
966
990
setToPosition ( animatedClosedPosition . value ) ;
967
991
return ;
968
992
}
@@ -987,7 +1011,7 @@ const BottomSheetComponent = forwardRef<BottomSheet, BottomSheetProps>(
987
1011
animationConfigs
988
1012
) ;
989
1013
} ,
990
- [ getEvaluatedPosition , animateToPosition , setToPosition ]
1014
+ [ getEvaluatedPosition , animateToPosition , setToPosition , reduceMotion ]
991
1015
) ;
992
1016
//#endregion
993
1017
@@ -1469,12 +1493,14 @@ const BottomSheetComponent = forwardRef<BottomSheet, BottomSheetProps>(
1469
1493
height : animate ( {
1470
1494
point : animatedContentHeightMax . value ,
1471
1495
configs : _providedAnimationConfigs ,
1496
+ overrideReduceMotion : _providedOverrideReduceMotion ,
1472
1497
} ) ,
1473
1498
} ;
1474
1499
} , [
1475
1500
enableDynamicSizing ,
1476
1501
animatedContentHeight . value ,
1477
1502
animatedContentHeightMax . value ,
1503
+ _providedOverrideReduceMotion ,
1478
1504
_providedAnimationConfigs ,
1479
1505
] ) ;
1480
1506
const contentContainerStyle = useMemo (
@@ -1771,6 +1797,19 @@ const BottomSheetComponent = forwardRef<BottomSheet, BottomSheetProps>(
1771
1797
return ;
1772
1798
}
1773
1799
1800
+ /**
1801
+ * exit the method if the animated index is out of sync with the
1802
+ * animated position. this happened when the user enable reduce
1803
+ * motion setting only.
1804
+ */
1805
+ if (
1806
+ reduceMotion &&
1807
+ _animatedIndex === animatedCurrentIndex . value &&
1808
+ animatedSnapPoints . value [ _animatedIndex ] !== _animatedPosition
1809
+ ) {
1810
+ return ;
1811
+ }
1812
+
1774
1813
/**
1775
1814
* if the index is not equal to the current index,
1776
1815
* than the sheet position had changed and we trigger
@@ -1811,7 +1850,7 @@ const BottomSheetComponent = forwardRef<BottomSheet, BottomSheetProps>(
1811
1850
runOnJS ( _providedOnClose ) ( ) ;
1812
1851
}
1813
1852
} ,
1814
- [ handleOnChange , _providedOnClose ]
1853
+ [ reduceMotion , handleOnChange , _providedOnClose ]
1815
1854
) ;
1816
1855
1817
1856
/**
0 commit comments