Skip to content

[Android] "Remove animations" setting isn't reflected when using AccessibilityInfo #31221

@te-online

Description

@te-online

Description

  • When removing animations through "Android settings" -> "Accessibility" -> "Remove animations", it doesn't seem to result in AccessibilityInfo.isReduceMotionEnabled() returning true or the change event to fire.
  • When going through "Android settings" -> "Developer settings" -> "Animator duration scale" -> "Off", it works as expected.

Note that setting "Remove animations" will also set "Animator duration scale" to "Off", but only manually setting it to "Off" again will result in AccessibilityInfo.isReduceMotionEnabled() to return true

Thus, both settings seem to be in sync somehow, but the setting in Accessibility (available to all users, not just developers) didn't seem to have the desired effect in my tests.

I tested on Android 10 and 11.

React Native version:

0.63.2 (expo SDK 39)

Steps To Reproduce

see description

Expected Results

When setting "Remove animations" in Android's accessibility settings AccessibilityInfo.isReduceMotionEnabled() returns true

Snack, code example, screenshot, or link to a repository:

My best guess is that Settings.Global.TRANSITION_ANIMATION_SCALE is somehow not set to the expected value when using the "Remove animations" switch instead of the related developer setting. See https://github.com/facebook/react-native/blob/0.63-stable/ReactAndroid/src/main/java/com/facebook/react/modules/accessibilityinfo/AccessibilityInfoModule.java#L100

This is the hook I'm using

import { useEffect, useState } from 'react';
import {
  AccessibilityChangeEventHandler,
  AccessibilityInfo,
} from 'react-native';

export function useReduceMotionEnabled(): [boolean] {
  const [reduceMotionEnabled, setReduceMotionEnabled] = useState(false);

  useEffect(() => {
    AccessibilityInfo.addEventListener(
      'reduceMotionChanged',
      handleReduceMotionToggled,
    );
    AccessibilityInfo.isReduceMotionEnabled().then((reduceMotionEnabled) => {
      setReduceMotionEnabled(reduceMotionEnabled);
    });

    return () => {
      AccessibilityInfo.removeEventListener(
        'reduceMotionChanged',
        handleReduceMotionToggled,
      );
    };
  }, []);

  const handleReduceMotionToggled: AccessibilityChangeEventHandler = (
    state,
  ) => {
    setReduceMotionEnabled(state);
  };

  return [reduceMotionEnabled];
}

This issue might be related: #30871

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions