Fix accessibilityState overwriting view's disabled state on Android (#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: https://github.com/facebook/react-native/pull/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
This commit is contained in:
Oskar Kwaśniewski
2022-07-29 03:56:44 -07:00
committed by Facebook GitHub Bot
parent ee9c1a5260
commit f35d18caa3
@@ -287,7 +287,9 @@ public abstract class BaseViewManager<T extends View, C extends LayoutShadowNode
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