Skip to content

Commit 8515fdb

Browse files
gorhomyayvery
authored andcommitted
fix: fixed the mount animation with reduce motion enabled (gorhom#1560, gorhom#1674)
fix: bottom sheet not appearing for users that have reduced motion turned on (gorhom#1743)(by @fobos531)
1 parent ed75bb7 commit 8515fdb

File tree

4 files changed

+24
-34
lines changed

4 files changed

+24
-34
lines changed

src/components/bottomSheet/BottomSheet.tsx

+11-21
Original file line numberDiff line numberDiff line change
@@ -740,26 +740,14 @@ const BottomSheetComponent = forwardRef<BottomSheet, BottomSheetProps>(
740740
runOnJS(handleOnAnimate)(position, source, animatedSnapPoints.value);
741741

742742
/**
743-
* force animation configs from parameters, if provided
743+
* start animation
744744
*/
745-
if (configs !== undefined) {
746-
animatedPosition.value = animate({
747-
point: position,
748-
configs,
749-
velocity,
750-
onComplete: animateToPositionCompleted,
751-
});
752-
} else {
753-
/**
754-
* use animationConfigs callback, if provided
755-
*/
756-
animatedPosition.value = animate({
757-
point: position,
758-
velocity,
759-
configs: _providedAnimationConfigs,
760-
onComplete: animateToPositionCompleted,
761-
});
762-
}
745+
animatedPosition.value = animate({
746+
point: position,
747+
configs: configs || _providedAnimationConfigs,
748+
velocity,
749+
onComplete: animateToPositionCompleted,
750+
});
763751
},
764752
[handleOnAnimate, _providedAnimationConfigs]
765753
);
@@ -1313,7 +1301,7 @@ const BottomSheetComponent = forwardRef<BottomSheet, BottomSheetProps>(
13131301
return;
13141302
}
13151303

1316-
let nextPosition;
1304+
let nextPosition: number;
13171305
if (_providedIndex === -1) {
13181306
nextPosition = animatedClosedPosition.value;
13191307
animatedNextPositionIndex.value = -1;
@@ -1346,7 +1334,9 @@ const BottomSheetComponent = forwardRef<BottomSheet, BottomSheetProps>(
13461334
}
13471335

13481336
if (animateOnMount) {
1349-
animateToPosition(nextPosition, ANIMATION_SOURCE.MOUNT);
1337+
requestAnimationFrame(() => {
1338+
animateToPosition(nextPosition, ANIMATION_SOURCE.MOUNT);
1339+
});
13501340
} else {
13511341
animatedPosition.value = nextPosition;
13521342
}
+1-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import { useMemo } from 'react';
21
import type { WithSpringConfig } from 'react-native-reanimated';
32

43
/**
@@ -8,5 +7,5 @@ import type { WithSpringConfig } from 'react-native-reanimated';
87
export const useBottomSheetSpringConfigs = (
98
configs: Omit<WithSpringConfig, 'velocity'>
109
) => {
11-
return useMemo(() => configs, [configs]);
10+
return configs;
1211
};
+6-11
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,22 @@
11
import { useMemo } from 'react';
2-
import type { EasingFunction } from 'react-native';
3-
import type { EasingFunctionFactory } from 'react-native-reanimated';
2+
import { type WithTimingConfig } from 'react-native-reanimated';
43
import { ANIMATION_DURATION, ANIMATION_EASING } from '../constants';
54

6-
interface TimingConfig {
7-
duration?: number;
8-
easing?: EasingFunction | EasingFunctionFactory;
9-
}
10-
115
/**
126
* Generate timing animation configs.
137
* @default
148
* - easing: Easing.out(Easing.exp)
15-
* - duration 250
9+
* - duration: 250
1610
* @param configs overridable configs.
1711
*/
18-
export const useBottomSheetTimingConfigs = (configs: TimingConfig) => {
12+
export const useBottomSheetTimingConfigs = (configs: WithTimingConfig) => {
1913
return useMemo(() => {
20-
const _configs: TimingConfig = {
14+
const _configs: WithTimingConfig = {
2115
easing: configs.easing || ANIMATION_EASING,
2216
duration: configs.duration || ANIMATION_DURATION,
17+
reduceMotion: configs.reduceMotion,
2318
};
2419

2520
return _configs;
26-
}, [configs.duration, configs.easing]);
21+
}, [configs.duration, configs.easing, configs.reduceMotion]);
2722
};

src/utilities/animate.ts

+6
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import {
44
withTiming,
55
withSpring,
66
AnimationCallback,
7+
ReduceMotion,
78
} from 'react-native-reanimated';
89
import { ANIMATION_CONFIGS, ANIMATION_METHOD } from '../constants';
910

@@ -26,6 +27,11 @@ export const animate = ({
2627
configs = ANIMATION_CONFIGS;
2728
}
2829

30+
// Users might have an accessibililty setting to reduce motion turned on.
31+
// This prevents the animation from running when presenting the sheet, which results in
32+
// the bottom sheet not even appearing so we need to override it to ensure the animation runs.
33+
configs.reduceMotion = ReduceMotion.Never;
34+
2935
// detect animation type
3036
const type =
3137
'duration' in configs || 'easing' in configs

0 commit comments

Comments
 (0)