feat(native): evaluate prefers-reduced-motion so motion-reduce / motion-safe work on native#388
Open
YevheniiKotyrlo wants to merge 2 commits into
Open
Conversation
Only prefers-color-scheme was wired into the native media-query evaluator (via Appearance). prefers-reduced-motion had no observable and no evaluator case, so `motion-reduce:` / `motion-safe:` (and any @media (prefers-reduced-motion) rule) compiled cleanly and then resolved to false on every device -- a silent no-op off the web. Mirror the colorScheme wiring: a reduceMotion observable seeded from AccessibilityInfo.isReduceMotionEnabled() and kept live via the reduceMotionChanged event, plus a prefers-reduced-motion case in testComparison handling reduce and no-preference. Also handle the bare `@media (prefers-reduced-motion)` boolean form (per CSS, bare is equivalent to reduce). Adds runtime tests (reduce, no-preference, composition, negation, bare) mirroring the existing color-scheme test, plus a compiler test asserting the emitted media condition.
Note that AccessibilityInfo has no synchronous getter (unlike Appearance.getColorScheme()), so the observable seeds `false` and flips when the async read resolves -- a brief, inherent cold-start window. Comment-only; no behaviour change.
YevheniiKotyrlo
marked this pull request as ready for review
July 23, 2026 12:11
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
react-native-cssevaluatesprefers-color-schemeon native (viaAppearance) but has no wiring forprefers-reduced-motion. So Tailwind'smotion-reduce:/motion-safe:variants — and any authored@media (prefers-reduced-motion)rule — compile correctly and then resolve tofalseon every device, silently. Web works because the browser evaluates the real CSS.This adds the missing feature, mirroring the existing
prefers-color-schemewiring exactly:src/native/reactivity.ts— areduceMotionobservable seeded fromAccessibilityInfo.isReduceMotionEnabled()and kept live via thereduceMotionChangedevent — the mirror ofcolorScheme←Appearance.src/native/conditions/media-query.ts— aprefers-reduced-motioncase intestComparison, handling bothreduce(motion-reduce:) andno-preference(motion-safe:), plus the bare@media (prefers-reduced-motion)boolean form (per CSS, bare(prefers-reduced-motion)≡reduce).get(reduceMotion)subscribes the effect, so a runtime OS toggle re-renders exactly as acolorSchemechange re-rendersdark:.Why it matters
motion-reduce:/motion-safe:are the documented Tailwind way to honour WCAG 2.3.3 (reduced motion). Verified against Tailwind v4.3.2 —motion-reduce:*emits@media (prefers-reduced-motion: reduce)andmotion-safe:*emits@media (prefers-reduced-motion: no-preference). Today both are dead on native: every reduced-motion affordance a consumer writes is a no-op off the web.Notes / platform caveat
AccessibilityInfo.isReduceMotionEnabled()is async-only (no synchronous getter, unlikeAppearance.getColorScheme()), so the observable seedsfalseand flips when it resolves — a one-frame cold-start window, withfalse(motion on) as the safe default.AccessibilityInforeact/react-native#31221); iOS drives it directly. This mirrors React Native's ownAccessibilityInfobehaviour and is out of scope here.Test plan
describe("prefers-reduced-motion")block insrc/__tests__/native/media-query.test.tsx(5 tests), mirroring the existing"color scheme"test:reduce(motion-reduce:) — base style by default, reduced style afterreduceMotion.set(true), and back (reactive both ways).no-preference(motion-safe:) — the inverse.prefers-color-schemeviaand.not (prefers-reduced-motion: reduce).@media (prefers-reduced-motion).prefers-reduced-motiontest insrc/__tests__/compiler/compiler.test.tsx(mirrorslight-dark()) asserting the emitted media condition:["=", "prefers-reduced-motion", "reduce" | "no-preference"]and the bare["!!", "prefers-reduced-motion"].yarn test,yarn typecheck,eslint,prettier --checkall pass. (The three babel suites fail identically on cleanmainin this environment — missing--experimental-vm-modules— and are unrelated to this change.)