Skip to content

feat: expose the reduced-motion preference beside colorScheme - #388

Open
YevheniiKotyrlo wants to merge 1 commit into
nativewind:mainfrom
YevheniiKotyrlo:feat/prefers-reduced-motion
Open

YevheniiKotyrlo wants to merge 1 commit into
nativewind:mainfrom
YevheniiKotyrlo:feat/prefers-reduced-motion

Conversation

@YevheniiKotyrlo

@YevheniiKotyrlo YevheniiKotyrlo commented Jul 23, 2026 •

Copy link
Copy Markdown
Contributor

The public API #591 left out, on top of main. Proposed in #507.

Problem

motion-reduce: / motion-safe: now follow the device's reduce-motion setting (#591), but an app can't override it. colorScheme can go in favour of React Native's Appearance.setColorScheme() (docs/v5-engine-contracts.md). Reduce motion has no counterpart: AccessibilityInfo only reads the setting. So an app's own reduce-motion toggle has no supported way to reach these variants.

Solution

import { reducedMotion } from "react-native-css";

reducedMotion.set("reduce"); // holds through the device's changes
reducedMotion.set(null); // follows the device again
reducedMotion.get(); // "reduce" | "no-preference" | undefined until AccessibilityInfo answers
  • Native: reactivity.ts keeps the device's answer (deviceReducedMotion, feat(native): evaluate prefers-reduced-motion so motion-reduce / motion-safe work on native #591's observable renamed) apart from the override. reducedMotion is the override, or else the device's answer, and the media query evaluator reads it unchanged. An override isn't overwritten by reduceMotionChanged, unlike colorScheme's.
  • Web: the browser evaluates @media itself, so get() reads matchMedia on each call and set() changes only what get() returns. A server keeps no override.
  • Jest: the helper's beforeEach clears the override.

Tests

  • src/__tests__/native/media-query.test.tsx: an override holds through a device change and set(null) follows the device again, and an override applies to and clears from a mounted view. The tests that model the device now set deviceReducedMotion.
  • src/__tests__/web/reduced-motion.test.ts: matchMedia's answer both ways, an override until set(null), no matchMedia or a stub returning nothing, a server, and a double whose answer changes.
  • src/__tests__/native/_reduced-motion-types.ts: the type surface on each entry point.

Verification

Every CI job passes locally on the head: lint, typecheck, yarn test (109 suites, 2191 tests), the library and web builds, commitlint, and the iOS dev build.

@YevheniiKotyrlo

YevheniiKotyrlo commented Aug 18, 2026 •

Copy link
Copy Markdown
Contributor Author

Device evidence — before / after

UNFIXED — Both rows paint the same — the media feature evaluates false on every device, so neither variant fires.

FIXED — Exactly one row is green. Which one tracks the OS reduce-motion setting shown above it.

before — 3.1.0-rc.0 after — with this PR

Android 16 emulator (API 36, GLES on the host GPU), 1140×2400 @ 480dpi, both frames from one run. before is the published 3.1.0-rc.0 plus what my test app needs from my other patches to run: the native and native-internal subpath exports, PR 459, cascade-layer ranking, and a shim that compiles a class-qualified :root inert. after adds the rest of my open PRs, this one included. One of them shows on every screen: PR 417 narrows a var()-valued font-family to one family, so the after sets its text in the theme's face where the before falls back to the platform's.

Recording — reduce motion turning on

main on the left, this PR on the right: the library's example app as release builds of main (2421ea77) and of main with this PR merged in, on an Android 16 emulator (API 36), 1140×2400 @ 480dpi. Before each side records, the JavaScript bundle of the APK the device holds is compared byte for byte with the build's. The line on top is React Native's own AccessibilityInfo, the same code on both sides. About 2.5 s in, the transition animation scale React Native reads for reduce motion goes to 0, as Remove animations sets it.

  • main: the motion-safe:animate-spin view never moves, and the animate-spin motion-reduce:animate-none one keeps spinning after the setting turns on.
  • This PR: both spin while the setting is off, and both stop in the frame it turns on. They stop where the animation left them, which is Reanimated 4.5.1's behaviour on Android when a CSS animation is removed (docs/known-issues.md, Reanimated #10507).

screenrecord captured 41 to 43 frames a second while the screen moved; the GIF plays 5 s of each side at 25. The source videos are main and this PR.

reducedMotion — main against this PR

import { reducedMotion } from "react-native-css";

// .card { color: #000; } @media (prefers-reduced-motion: reduce) { .card { color: #020202; } }
reducedMotion.set("reduce"); // the card takes #020202, and keeps it when the device's setting changes
reducedMotion.set(null); // back to the device's answer: #000 under React Native's jest mock
result
main (eda2b286) TypeError: Cannot read properties of undefined (reading 'set'): nothing is exported under that name
this PR the card's style is { color: "#020202" } after set("reduce"), still after the device's setting changes, and { color: "#000" } after set(null)

Run as written, with the class registered and a View rendered, through the repo's jest on Windows with Node 26.

The evaluator's cost — main against this PR

testMediaQuery over one condition, read through a subscribing effect as a render reads it: the median of 21 samples of 1,000,000 evaluations, after 200,000 to warm up, two runs on each side.

condition main 2421ea77 this PR
(min-width: 640px) 13.78 ns, 13.99 ns 13.93 ns, 13.64 ns
(prefers-color-scheme: dark) 13.53 ns, 13.45 ns 13.33 ns, 13.51 ns
(prefers-reduced-motion: reduce) 7.82 ns, 7.88 ns 13.49 ns, 13.25 ns

The first two differ across the sides by less than two runs of one side differ, at most 0.29 ns. The reduced-motion condition now reads the preference as the colour-scheme one reads the scheme, where main read nothing and answered false. Windows 11 on an AMD Ryzen 9 9950X3D, Node 26.12.1, through the repo's jest.

@YevheniiKotyrlo

YevheniiKotyrlo commented Aug 18, 2026 •

Copy link
Copy Markdown
Contributor Author

Outdated: the pairs are re-shot on 3.1.0-rc.0, each in its own PR's evidence comment.

The original note

@danstepanov — I've added before/after device captures to 19 of my 26 open PRs here. Each pair is the same device in the same run, differing only in whether the patch is applied, so the difference should be quick to eyeball.

The other seven (#390, #410, #427, #428, #429, #430, #432) have nothing visual to show — they're build, typing and resolution fixes.

No rush at all, and happy to rebase or split any of them if that makes them easier to take.

@YevheniiKotyrlo
YevheniiKotyrlo force-pushed the feat/prefers-reduced-motion branch from 0757e09 to 5987763 Compare October 11, 2026 12:35
@YevheniiKotyrlo
YevheniiKotyrlo marked this pull request as draft October 19, 2026 21:53
@YevheniiKotyrlo
YevheniiKotyrlo force-pushed the feat/prefers-reduced-motion branch from 8951326 to 48eb155 Compare October 27, 2026 00:43
@YevheniiKotyrlo
YevheniiKotyrlo marked this pull request as ready for review October 27, 2026 05:00
@sammoore

Copy link
Copy Markdown
Contributor

@YevheniiKotyrlo I removed the public-facing API from my replacement PR -- the patch in your name is below (applies onto the aforementioned PR, #591). Still determining if we want to make that public, and, if we do, if it's the right shape.

  • this was private/internal in react-native-css-interop / Nativewind 4
  • the plan as I understand it was to deprecate colorScheme, the most similar API
  • if you have thoughts on that or a strong reason to keep, we should discuss!

Feel free to either close this PR and open a new one, or replace the contents and description with on the patch contents, making this the potential public API PR.

388-accessibility-info-guard.patch

@YevheniiKotyrlo
YevheniiKotyrlo marked this pull request as draft November 30, 2026 14:43
@YevheniiKotyrlo

Copy link
Copy Markdown
Contributor Author

The attached patch is the guard commit rather than the API: it puts back the AccessibilityInfo guards for a test double that #591 removed. I'm fine leaving those out, for the reason #591 gives.

On keeping the API: colorScheme can go because React Native has its own override, Appearance.setColorScheme(), which docs/v5-engine-contracts.md already points to and the runtime follows through Appearance's change event. Reduce motion has no counterpart: AccessibilityInfo only reads the setting. Without reducedMotion.set(), an app's own reduce-motion toggle has no supported way to reach motion-reduce: / motion-safe:; only the OS setting does. Keeping the observable internal cost v4 nothing, because v4 never matched (prefers-reduced-motion: reduce) or : no-preference in the first place.

I'll replace this PR's contents and description with the API alone on top of main, so its shape can be judged against #507.

React Native has no setter for the reduce-motion setting, unlike Appearance.setColorScheme()
for the scheme, so an app's own reduce-motion toggle had no supported way to reach
motion-reduce: and motion-safe:.

reducedMotion.set() overrides the device's preference until set(null) and holds through the
device's changes. On native the override is kept apart from AccessibilityInfo's answer, which
the media queries read when no override is set. On web, where the browser evaluates @media
itself, get() reads matchMedia and set() changes only what get() returns. The jest helper
clears the override between tests.
@YevheniiKotyrlo
YevheniiKotyrlo force-pushed the feat/prefers-reduced-motion branch from 48eb155 to a1495ad Compare November 30, 2026 15:14
@YevheniiKotyrlo YevheniiKotyrlo changed the title feat(native): evaluate prefers-reduced-motion so motion-reduce / motion-safe work on native feat: expose the reduced-motion preference beside colorScheme Nov 30, 2026
@YevheniiKotyrlo
YevheniiKotyrlo marked this pull request as ready for review November 30, 2026 16:33
sammoore added a commit to sammoore/react-native-css that referenced this pull request Nov 30, 2026
React Native always exports AccessibilityInfo, and a runtime that reads the reduced-motion preference (nativewind#388) calls isReduceMotionEnabled() and addEventListener() on import. The stand-in answers as React Native's jest setup does: reduce motion is off, and no change fires.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@sammoore

sammoore commented Dec 1, 2026

Copy link
Copy Markdown
Contributor

The attached patch is the guard commit rather than the API

Sorry about that, had a bunch of things happening at once 😅

Thanks for adapting this PR to just the public facing API! I'll return to it after some other 5.0 stabilization priorities.

@danstepanov danstepanov added the deferred (post-5.0) Not required for the 5.0 latest release; revisit after label Dec 1, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

deferred (post-5.0) Not required for the 5.0 latest release; revisit after

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants