Skip to content

Commit 6efd8ae

Browse files
committed
fix: fixed the mount animation with reduce motion enabled (#1560, #1674)
1 parent 8255af6 commit 6efd8ae

File tree

3 files changed

+18
-34
lines changed

3 files changed

+18
-34
lines changed

src/components/bottomSheet/BottomSheet.tsx

+11-21
Original file line numberDiff line numberDiff line change
@@ -753,26 +753,14 @@ const BottomSheetComponent = forwardRef<BottomSheet, BottomSheetProps>(
753753
runOnJS(handleOnAnimate)(position);
754754

755755
/**
756-
* force animation configs from parameters, if provided
756+
* start animation
757757
*/
758-
if (configs !== undefined) {
759-
animatedPosition.value = animate({
760-
point: position,
761-
configs,
762-
velocity,
763-
onComplete: animateToPositionCompleted,
764-
});
765-
} else {
766-
/**
767-
* use animationConfigs callback, if provided
768-
*/
769-
animatedPosition.value = animate({
770-
point: position,
771-
velocity,
772-
configs: _providedAnimationConfigs,
773-
onComplete: animateToPositionCompleted,
774-
});
775-
}
758+
animatedPosition.value = animate({
759+
point: position,
760+
configs: configs || _providedAnimationConfigs,
761+
velocity,
762+
onComplete: animateToPositionCompleted,
763+
});
776764
},
777765
[handleOnAnimate, _providedAnimationConfigs]
778766
);
@@ -1332,7 +1320,7 @@ const BottomSheetComponent = forwardRef<BottomSheet, BottomSheetProps>(
13321320
return;
13331321
}
13341322

1335-
let nextPosition;
1323+
let nextPosition: number;
13361324
if (_providedIndex === -1) {
13371325
nextPosition = animatedClosedPosition.value;
13381326
animatedNextPositionIndex.value = -1;
@@ -1365,7 +1353,9 @@ const BottomSheetComponent = forwardRef<BottomSheet, BottomSheetProps>(
13651353
}
13661354

13671355
if (animateOnMount) {
1368-
animateToPosition(nextPosition, ANIMATION_SOURCE.MOUNT);
1356+
requestAnimationFrame(() => {
1357+
animateToPosition(nextPosition, ANIMATION_SOURCE.MOUNT);
1358+
});
13691359
} else {
13701360
animatedPosition.value = nextPosition;
13711361
}
+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
};

0 commit comments

Comments
 (0)