Skip to content

Commit

Permalink
Fix accessibilityState overwriting view's disabled state on Android (f…
Browse files Browse the repository at this point in the history
…acebook#34287)

Summary:
While I was working on rewriting `react-native-slider` to Fabric I found a weird bug that prevented the slider to be set as disabled (to be exact: call the method `slider.setEnabled(false)`. As it turned out the `accessibilityState` (with value: `accessibilityState={{disabled: true}}` prop occurred after the `enabled={false}` prop that I was passing to the slider, which lead to both of this props overwrite each other.

Handling of `accessibilityState` props inside view leads to always overwriting the enabled prop to true (even if we explicitly set it to `{disabled: false}`.

Workaround for this was to reorder the props, so that the `accesibilityState` occur before `disabled`, but I think it's better to not set `view.setEnabled(true)` if we are passing a disabled property.

## Changelog

[Android] [Fixed] - Fix accessibilityState overwriting view's disabled state on Android

Pull Request resolved: facebook#34287

Test Plan:
Change order of props inside native component implementation (that `disabled` occurs before `accesibilityState`). For example: `Libraries/Components/Slider/Slider.js`

<details>
  <summary>Video showing the bug in RNTester (using Switch component)</summary>

https://user-images.githubusercontent.com/52801365/181287547-964f50e2-55dc-450f-b413-0d1c14d4bb83.mp4
</details>

Reviewed By: NickGerleman

Differential Revision: D38209232

Pulled By: dmitryrykun

fbshipit-source-id: 93d423716f89b45251be9d5aefcf01f7bd776f2c
  • Loading branch information
okwasniewski authored and roryabraham committed Aug 17, 2022
1 parent 4b158f0 commit 32e5be5
Showing 1 changed file with 3 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,9 @@ public void setViewState(@NonNull T view, @Nullable ReadableMap accessibilitySta
view.setSelected(false);
}
view.setTag(R.id.accessibility_state, accessibilityState);
view.setEnabled(true);
if (accessibilityState.hasKey("disabled") && !accessibilityState.getBoolean("disabled")) {
view.setEnabled(true);
}

// For states which don't have corresponding methods in
// AccessibilityNodeInfo, update the view's content description
Expand Down

0 comments on commit 32e5be5

Please sign in to comment.