From 790df10fa9bac18a60bd52178cc222f5e368a44b Mon Sep 17 00:00:00 2001 From: baranga Date: Fri, 17 Mar 2023 11:42:54 -0700 Subject: [PATCH] Fix check of "reduce motion" setting on android (#36508) Summary: On Android `AccessibilityInfo.isReduceMotionEnabled()` returns false even when "Disable Animations" is enabled. This fixes https://github.com/facebook/react-native/issues/31221. ## Changelog [ANDROID] [FIXED] - Fix check of "reduce motion" setting on android Pull Request resolved: https://github.com/facebook/react-native/pull/36508 Test Plan: Have some code logging the value of `AccessibilityInfo.isReduceMotionEnabled()` or using it to change the UI. Run that code on Android without and with "Disable Animations" enabled. See the value is always `false` without the fix, but changes to `true` when "Disable Animations" is enabled with the fix. Reviewed By: cortinico, rshest Differential Revision: D44163583 Pulled By: javache fbshipit-source-id: ad239454ea68b381e0c7f024df797b3646aeefd7 --- .../accessibilityinfo/AccessibilityInfoModule.java | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/modules/accessibilityinfo/AccessibilityInfoModule.java b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/modules/accessibilityinfo/AccessibilityInfoModule.java index af15c861c56557..a21b048c97937f 100644 --- a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/modules/accessibilityinfo/AccessibilityInfoModule.java +++ b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/modules/accessibilityinfo/AccessibilityInfoModule.java @@ -100,10 +100,15 @@ public AccessibilityInfoModule(ReactApplicationContext context) { @TargetApi(Build.VERSION_CODES.LOLLIPOP) private boolean getIsReduceMotionEnabledValue() { - String value = + // Disabling animations in developer settings will set the animation scale to "0.0" + // but setting "reduce motion" / "disable animations" will set the animation scale to "0". + String rawValue = Settings.Global.getString(mContentResolver, Settings.Global.TRANSITION_ANIMATION_SCALE); - return value != null && value.equals("0.0"); + // Parse the value as a float so we can check for a single value. + Float parsedValue = rawValue != null ? Float.parseFloat(rawValue) : 1f; + + return parsedValue == 0f; } @Override