Skip to content

Expose the reduced-motion preference beside colorScheme #507

Open

Description

@YevheniiKotyrlo

#388 makes native evaluate prefers-reduced-motion, reading the device's setting from AccessibilityInfo. A consumer then needs two things:

  • An app with its own "Reduce motion" setting has to override the device's preference, and keep its choice when the device's setting changes.
  • A test suite has to put a test in reduce mode: react-native-css/jest resets the preference before each test, and nothing public sets it.

#388 adds reducedMotion to the API, beside colorScheme:

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

reducedMotion.get(); // "reduce", "no-preference", or undefined until the device answers
reducedMotion.set("reduce"); // overrides the device, through any change of its setting
reducedMotion.set(null); // follows the device again

The override holds until it is cleared, as Appearance.setColorScheme(), iOS's overrideUserInterfaceStyle and Android's setDefaultNightMode() hold theirs, and as Media Queries 5 §13 shapes the web's navigator.preferences.reducedMotion.requestOverride() and clearOverride(). Internally it is one devicePreference() that keeps the device's answer apart from the app's override, which a later preference the platform reports but does not let an app set, such as contrast or reduced transparency, can share. On main, colorScheme.set() writes a value the next change of the device's scheme replaces; #415 keeps the scheme's override in Appearance, which holds it on the platform itself.

On web the browser evaluates @media in the stylesheet itself, so get() reads matchMedia and set() changes only what get() returns, not the CSS or matchMedia(). navigator.preferences would carry the override into the CSS, but no browser ships it yet (csswg-drafts#14493); once one does, the web set() can call it.

Is this the shape you would want, or would you rather keep the setter in the jest helper only?

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions