diff --git a/src/components/CrossFadeIcon.tsx b/src/components/CrossFadeIcon.tsx
index 1f67aa7843..926066a6f4 100644
--- a/src/components/CrossFadeIcon.tsx
+++ b/src/components/CrossFadeIcon.tsx
@@ -14,7 +14,10 @@ import Animated, {
import Icon, { isEqualIcon, isValidIcon } from './Icon';
import type { IconSource } from './Icon';
import { useInternalTheme } from '../core/theming';
-import { useMotionDuration } from '../theme/accessibility/ReduceMotionContext';
+import {
+ useMotionDuration,
+ useReduceMotion,
+} from '../theme/accessibility/ReduceMotionContext';
import type { ThemeProp } from '../theme/types';
type Props = {
@@ -58,14 +61,22 @@ const CrossFadeIcon = ({
const fade = useSharedValue(1);
+ const reduceMotion = useReduceMotion();
+ const reduceMotionRef = React.useRef(reduceMotion);
+ reduceMotionRef.current = reduceMotion;
const getDuration = useMotionDuration();
if (currentIcon !== source) {
- setPreviousIcon(() => currentIcon);
+ setPreviousIcon(() => (reduceMotion ? null : currentIcon));
setCurrentIcon(() => source);
}
React.useEffect(() => {
+ if (reduceMotionRef.current) {
+ fade.value = 0;
+ return;
+ }
+
if (isValidIcon(previousIcon) && !isEqualIcon(previousIcon, currentIcon)) {
fade.value = 1;
diff --git a/src/components/Drawer/DrawerCollapsedItem.tsx b/src/components/Drawer/DrawerCollapsedItem.tsx
index 94fd60286b..9015571d20 100644
--- a/src/components/Drawer/DrawerCollapsedItem.tsx
+++ b/src/components/Drawer/DrawerCollapsedItem.tsx
@@ -20,7 +20,10 @@ import useLatestCallback from 'use-latest-callback';
import { DrawerCollapsedItemTokens } from './tokens';
import { getDestinationA11yProps } from './utils';
import { useInternalTheme } from '../../core/theming';
-import { useMotionDuration } from '../../theme/accessibility/ReduceMotionContext';
+import {
+ useMotionDuration,
+ useReduceMotion,
+} from '../../theme/accessibility/ReduceMotionContext';
import { tokens } from '../../theme/tokens';
import type { ThemeProp } from '../../theme/types';
import { resolveCornerRadius } from '../../theme/utils/shape';
@@ -125,6 +128,7 @@ const DrawerCollapsedItem = ({
...rest
}: Props) => {
const theme = useInternalTheme(themeOverrides);
+ const reduceMotion = useReduceMotion();
const getDuration = useMotionDuration();
// MD3 rings a navigation rail item as a whole (icon and label) with a
@@ -149,7 +153,16 @@ const DrawerCollapsedItem = ({
const outlineScale = useSharedValue(active ? 1 : 0.5);
+ if (reduceMotion) {
+ outlineScale.value = active ? 1 : 0.5;
+ }
+
const expandOutline = useLatestCallback(() => {
+ if (reduceMotion) {
+ outlineScale.value = 1;
+ return;
+ }
+
outlineScale.value = withTiming(1, {
duration: getDuration(
theme.motion.duration[DrawerCollapsedItemTokens.activeIndicatorDuration]
diff --git a/src/components/__tests__/CrossFadeIcon.test.tsx b/src/components/__tests__/CrossFadeIcon.test.tsx
index 3e148541d3..05edbf0123 100644
--- a/src/components/__tests__/CrossFadeIcon.test.tsx
+++ b/src/components/__tests__/CrossFadeIcon.test.tsx
@@ -26,27 +26,33 @@ beforeEach(() => {
withTiming.mockClear();
});
-it.each([
- { reduceMotion: 'off', duration: 200 },
- { reduceMotion: 'on', duration: 0 },
-] as const)(
- 'cross-fades to a new icon in $duration ms when reduceMotion is "$reduceMotion"',
- async ({ reduceMotion, duration }) => {
- const makeIcon = (source: string) => (
-
-
-
- );
+it('cross-fades to a new icon in 200 ms when reduceMotion is "off"', async () => {
+ const makeIcon = (source: string) => (
+
+
+
+ );
- await render(makeIcon('plus'));
- expect(withTiming).not.toHaveBeenCalled();
+ await render(makeIcon('plus'));
+ expect(withTiming).not.toHaveBeenCalled();
- await screen.rerender(makeIcon('minus'));
- expect(withTiming.mock.calls.map(([, config]) => config?.duration)).toEqual(
- [duration]
- );
- }
-);
+ await screen.rerender(makeIcon('minus'));
+ expect(withTiming.mock.calls.map(([, config]) => config?.duration)).toEqual([
+ 200,
+ ]);
+});
+
+it('switches immediately without animating when reduceMotion is "on"', async () => {
+ const makeIcon = (source: string) => (
+
+
+
+ );
+
+ await render(makeIcon('plus'));
+ await screen.rerender(makeIcon('minus'));
+ expect(withTiming).not.toHaveBeenCalled();
+});
it('does not replay the last icon change when the OS setting changes', async () => {
const addEventListener = jest.mocked(AccessibilityInfo.addEventListener);