Repository navigation
feat: expose the reduced-motion preference beside colorScheme - #388
YevheniiKotyrlo wants to merge 1 commit into
Conversation
Device evidence — before / afterUNFIXED — 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.
Android 16 emulator (API 36, GLES on the host GPU), 1140×2400 @ 480dpi, both frames from one run. Recording — reduce motion turning on
|
| 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.
|
Outdated: the pairs are re-shot on 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. |
0757e09 to
5987763
Compare
8951326 to
48eb155
Compare
|
@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.
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. |
|
The attached patch is the guard commit rather than the API: it puts back the On keeping the API: I'll replace this PR's contents and description with the API alone on top of |
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.
48eb155 to
a1495ad
Compare
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>
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. |



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.colorSchemecan go in favour of React Native'sAppearance.setColorScheme()(docs/v5-engine-contracts.md). Reduce motion has no counterpart:AccessibilityInfoonly reads the setting. So an app's own reduce-motion toggle has no supported way to reach these variants.Solution
reactivity.tskeeps 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.reducedMotionis the override, or else the device's answer, and the media query evaluator reads it unchanged. An override isn't overwritten byreduceMotionChanged, unlikecolorScheme's.@mediaitself, soget()readsmatchMediaon each call andset()changes only whatget()returns. A server keeps no override.beforeEachclears the override.Tests
src/__tests__/native/media-query.test.tsx: an override holds through a device change andset(null)follows the device again, and an override applies to and clears from a mounted view. The tests that model the device now setdeviceReducedMotion.src/__tests__/web/reduced-motion.test.ts:matchMedia's answer both ways, an override untilset(null), nomatchMediaor 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.