Repository navigation
feat(native): evaluate prefers-reduced-motion so motion-reduce / motion-safe work on native - #591
Merged
Merged
Conversation
…on-safe work on native The native runtime evaluated prefers-color-scheme but not prefers-reduced-motion, so Tailwind's motion-reduce: and motion-safe: variants compiled and then never applied on a device. devicePreference() keeps a user preference as the device reports it apart from the app's override, which holds until it is cleared. The reduced-motion preference is built on it: the device's answer comes from AccessibilityInfo.isReduceMotionEnabled() and follows reduceMotionChanged from import, as colorScheme follows Appearance. React Native reads the setting only through a callback, so the preference is unknown until it answers, and a reduced-motion query does not match before then. The evaluator compares the prefers-reduced-motion keyword, and (prefers-reduced-motion) alone matches reduce. reducedMotion joins colorScheme in the API: get() returns the preference, and set() overrides it until set(null). On web get() reads matchMedia on each call and set() changes only what get() returns. The jest helper's reset clears an override and puts the device back to AccessibilityInfo's answer.
… re-import it 427 pins the reactivity state on globalThis, which jest.resetModules() leaves in place, so each re-import in reduce-motion-init.test.ts read the first test's preference and six of its nine cases failed once the PR was rebased onto main.
… API The motion-reduce: and motion-safe: variants need only the evaluator to read the device's preference. The public reducedMotion getter and setter, the device/override split behind it (devicePreference() and the stored AccessibilityInfo answer), the web browserPreference() wrapper, the jest helper's move to reset.ts through the package entries, and the type test all serve the override, which nativewind#507 still asks the maintainer about. Their removal leaves one reducedMotion observable in the pinned reactivity state, which the internal tests set directly. Tailwind output under both preferences is identical before and after this commit.
…me subscribes to Appearance React Native always exports AccessibilityInfo with isReduceMotionEnabled() and addEventListener(), and the Appearance and Dimensions subscriptions beside this one carry no guard for a test double that leaves them out, so the guard and its three test cases go. The handler for a rejected read stays: React Native rejects where the platform has no accessibility module. No suite in the repo needs the guard.
The table pins the condition each reduced-motion query compiles to, and every row already passes on main: the compiler is unchanged here, so the table documents existing output rather than testing this fix. The runtime table in media-query.test.tsx still covers each query end to end.
danstepanov
approved these changes
Nov 30, 2026
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.
A subset of #388: This rebases the original commit, and the follow-up commits on top cut it down to the evaluator, removing:
reducedMotionAPI: still unsure if we want to add this yet in it's current shape (tracked via Expose the reduced-motion preference beside colorScheme #507).AccessibilityInfo, its getter or its change event: React Native always exports them, and theAppearanceandDimensionssubscriptions have nothing similar. The handler for a rejected read stays.main, and the tests inmedia-query.test.tsxalready do the same end-to-end.New in this PR: The init tests clear the pinned reactivity state before each re-import, since #427's
globalThispin outlivesjest.resetModules().Source diff: +183/−19 in 9 files as written, +49/−5 in 3 files here.
Problem
Tailwind compiles
motion-reduce:*to@media (prefers-reduced-motion: reduce)andmotion-safe:*to@media (prefers-reduced-motion: no-preference). The native media query evaluator had no case forprefers-reduced-motion, so both variants compiled and then never applied on a device, whatever its accessibility setting. Negations were wrong the other way:not (prefers-reduced-motion: reduce)matched everyone, including users who turned motion off.Solution
reactivity.tsgains areducedMotionobservable in the pinned reactivity state (fix(native): share reactivity state across a dual-package split #427), read fromAccessibilityInfo.isReduceMotionEnabled()and kept live byreduceMotionChanged, ascolorSchemefollowsAppearance.motion-safe:animation for someone who turned motion off. A change event that arrives before the answer wins over it. Where React Native rejects for want of an accessibility module, the preference isno-preference.prefers-reduced-motionkeyword, as it doesprefers-color-scheme, and(prefers-reduced-motion)alone matchesreduce(MQ5 §2.4.2).media-query.tsdrops its file-wideeslint-disable, which it no longer needs, and returnsbooleanrather than theBooleanwrapper type.Regression status
motion-reduce:andmotion-safe:never applied in Nativewind v4 (verified with Tailwind 3 throughrenderCurrentTest, preference off and on) or in any v5 release.react-native-css-interopevaluated(prefers-reduced-motion);(prefers-reduced-motion: reduce)and: no-preferencenever matched there either.Tests
src/__tests__/native/media-query.test.tsx: before the answer no reduced-motion query matches and a mounted view takes the answer when it arrives; a mounted view follows the preference both ways; and a table of 31 queries under each motion preference in each colour scheme, as Chromium, Firefox and WebKit evaluate them. Onmain's evaluator 41 of those cells and both behaviour tests fail.src/__tests__/native/reduce-motion-init.test.ts: unknown until the answer, the answer then a change event, a change event before the answer, and a rejecting getter.Verification
reduceand underno-preference): onmainnomotion-*variant applies; heremotion-reduce:*applies underreduceonly andmotion-safe:*underno-preferenceonly. Output is identical to feat(native): evaluate prefers-reduced-motion so motion-reduce / motion-safe work on native #388 as written.dark:,md:andanimate-spincontrols are unchanged.yarn test105 suites, 2056 tests pass. The oneyarn linterror (node/babel.mjs) is onmaintoo.main: the full suite's 14 scenarios are within −3.6%…+1.3% (the media query scenario −0.5%), which is noise.