Skip to content

Commit

Permalink
Fix check of "reduce motion" setting on android (#36508)
Browse files Browse the repository at this point in the history
Summary:
On Android `AccessibilityInfo.isReduceMotionEnabled()` returns false even when "Disable Animations" is enabled. This fixes #31221.

## Changelog

<!-- Help reviewers and the release process by writing your own changelog entry.

Pick one each for the category and type tags:

[ANDROID|GENERAL|IOS|INTERNAL] [BREAKING|ADDED|CHANGED|DEPRECATED|REMOVED|FIXED|SECURITY] - Message

For more details, see:
https://reactnative.dev/contributing/changelogs-in-pull-requests
-->
[ANDROID] [FIXED] - Fix check of "reduce motion" setting on android

Pull Request resolved: #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
  • Loading branch information
baranga authored and facebook-github-bot committed Mar 17, 2023
1 parent b0c30ad commit 790df10
Showing 1 changed file with 7 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 790df10

Please sign in to comment.