Skip to content

feat(native): evaluate prefers-reduced-motion so motion-reduce / motion-safe work on native - #591

Merged
danstepanov merged 5 commits into
nativewind:mainfrom
sammoore:fix/reduced-motion
Nov 30, 2026
Merged

danstepanov merged 5 commits into
nativewind:mainfrom
sammoore:fix/reduced-motion

Conversation

@sammoore

@sammoore sammoore commented Nov 30, 2026 •

Copy link
Copy Markdown
Contributor

A subset of #388: This rebases the original commit, and the follow-up commits on top cut it down to the evaluator, removing:

  • The public reducedMotion API: still unsure if we want to add this yet in it's current shape (tracked via Expose the reduced-motion preference beside colorScheme #507).
  • The guards for a test double without AccessibilityInfo, its getter or its change event: React Native always exports them, and the Appearance and Dimensions subscriptions have nothing similar. The handler for a rejected read stays.
  • The compiler tests: its unchanged, every row already passes on main, and the tests in media-query.test.tsx already 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 globalThis pin outlives jest.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) and motion-safe:* to @media (prefers-reduced-motion: no-preference). The native media query evaluator had no case for prefers-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.ts gains a reducedMotion observable in the pinned reactivity state (fix(native): share reactivity state across a dual-package split #427), read from AccessibilityInfo.isReduceMotionEnabled() and kept live by reduceMotionChanged, as colorScheme follows Appearance.
  • React Native reads the setting only through a callback, so the preference is unknown until it answers, and neither variant matches before then: a first paint never starts a 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 is no-preference.
  • The evaluator compares the prefers-reduced-motion keyword, as it does prefers-color-scheme, and (prefers-reduced-motion) alone matches reduce (MQ5 §2.4.2).
  • media-query.ts drops its file-wide eslint-disable, which it no longer needs, and returns boolean rather than the Boolean wrapper type.

Regression status

  • Tailwind utilities: a new feature. motion-reduce: and motion-safe: never applied in Nativewind v4 (verified with Tailwind 3 through renderCurrentTest, preference off and on) or in any v5 release.
  • Other CSS: a v4 regression fix for the boolean form only. v4's react-native-css-interop evaluated (prefers-reduced-motion); (prefers-reduced-motion: reduce) and : no-preference never 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. On main'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

  • Tailwind (12 class sets, rendered at the answer, under reduce and under no-preference): on main no motion-* variant applies; here motion-reduce:* applies under reduce only and motion-safe:* under no-preference only. Output is identical to feat(native): evaluate prefers-reduced-motion so motion-reduce / motion-safe work on native #388 as written. dark:, md: and animate-spin controls are unchanged.
  • Only whether a rule applies changes, not any style value, so no React Native style validator can newly throw.
  • Typecheck clean; yarn test 105 suites, 2056 tests pass. The one yarn lint error (node/babel.mjs) is on main too.
  • Performance on Hermes against main: the full suite's 14 scenarios are within −3.6%…+1.3% (the media query scenario −0.5%), which is noise.

YevheniiKotyrlo and others added 5 commits November 29, 2026 19:50
…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
danstepanov merged commit e9e2b73 into nativewind:main Nov 30, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants