React Native / Inclusive native systems and release evidence / Lesson 21
Reduced motion preference and lifecycle
Observe the native reduced-motion preference safely and choose an appropriate presentation for each state.
On this page
Lesson goals
- Read and subscribe to a native accessibility preference.
- Avoid stale initial results and clean up listeners.
- Verify behavior on actual target environments.
Define the preference contract
Motion can make an interface uncomfortable or difficult for some users. React Native exposes a reduced-motion setting through AccessibilityInfo, but the application must decide how each animation adapts. Provide a useful nonanimated path and preserve the meaning of the interaction. The setting is a preference signal, not proof that every accessibility need has been met or that all motion must be treated identically.
Subscribe and read safely
This Hook subscribes before requesting the initial value. If an event arrives while the initial request is pending, the older result cannot overwrite that event. Cleanup removes the exact subscription and prevents a late promise from publishing after unmount. The conservative failure branch selects reduced motion; a real application should also consider how to report or recover from a platform failure.
import { useEffect, useState } from "react";
import { AccessibilityInfo } from "react-native";
export function useReducedMotion() {
const [reduced, setReduced] = useState(null);
useEffect(() => {
let active = true;
let changed = false;
const subscription = AccessibilityInfo.addEventListener("reduceMotionChanged", value => { changed = true; if (active) setReduced(value); });
AccessibilityInfo.isReduceMotionEnabled().then(value => { if (active && !changed) setReduced(value); }).catch(() => { if (active && !changed) setReduced(true); });
return () => { active = false; subscription.remove(); };
}, []);
return reduced;
}
The Hook reflects a current preference event without accepting an older initial result.
The Hook returns null while checking, a boolean afterward, and cleans up its native listener.
Render each state
The consumer distinguishes an unresolved preference from false, so it does not start motion while the native query is pending. This example only displays the decision; an actual animation component must use it to choose an appropriate presentation. It requires a compatible React Native host and platform APIs. A successful JavaScript render does not establish the device setting or screen-reader experience.
import { Text } from "react-native";
import { useReducedMotion } from "./useReducedMotion";
export default function MotionPreference() {
const reduced = useReducedMotion();
if (reduced === null) return <Text>Checking motion preference.</Text>;
return <Text>{reduced ? "Reduced motion requested." : "Standard motion permitted."}</Text>;
}
While pending, the component displays Checking motion preference.
The component reports the pending, reduced-motion and standard-motion branches.
Design the reduced-motion path
For each animation, decide whether to remove movement, shorten it or replace it with a meaningful nonmoving state. Do not make a transition the only indication that a task completed. Keep the same controls and result available in both modes. Verify the current API and event support for the installed version and platforms, including how settings changes are delivered while the application is active.
Verify lifecycle and targets
Use controlled tests to resolve the initial query after a preference-change event and confirm that the event wins. Unmount before the promise resolves and verify cleanup. Then change the system setting on each intended target and observe the actual interaction and alternative presentation. Record device or simulator, platform and build; a mocked event proves the ownership logic but not native delivery.
Common errors and fixes
The UI reverts to an old preference.
- Why it happens
- A delayed initial query overwrote a newer change event.
- How to fix it
- Track whether an event arrived before applying the initial result.
- Prevent it next time
- Test out-of-order query and event completion.
A listener remains after the screen closes.
- Why it happens
- The subscription was not removed by its owner.
- How to fix it
- Remove the returned subscription during cleanup.
- Prevent it next time
- Test mount, unmount and late completion.
The reduced-motion path loses essential feedback.
- Why it happens
- Meaning was conveyed only by animation.
- How to fix it
- Provide equivalent visible or accessible status.
- Prevent it next time
- Test the complete task in both preference modes.
2 practice exercises
1. Why is null separate from false in the example?
Show worked solution
Null means the initial native query is unresolved. Treating it as false could start motion before the user preference is known.
2. What if a change event arrives before the initial query resolves?
Show worked solution
The Hook marks the event as newer and ignores the later initial result. Verify that ordering with a controlled promise and event.
Key takeaways
- Observe preference changes with owned cleanup.
- Prevent stale initial values from replacing newer events.
- Test meaningful alternatives on native targets.