From f35d18caa302351319840ec85337182f4f148e5e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Oskar=20Kwa=C5=9Bniewski?= Date: Fri, 29 Jul 2022 03:56:44 -0700 Subject: [PATCH] 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`
Video showing the bug in RNTester (using Switch component) https://user-images.githubusercontent.com/52801365/181287547-964f50e2-55dc-450f-b413-0d1c14d4bb83.mp4
Reviewed By: NickGerleman Differential Revision: D38209232 Pulled By: dmitryrykun fbshipit-source-id: 93d423716f89b45251be9d5aefcf01f7bd776f2c --- .../java/com/facebook/react/uimanager/BaseViewManager.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/ReactAndroid/src/main/java/com/facebook/react/uimanager/BaseViewManager.java b/ReactAndroid/src/main/java/com/facebook/react/uimanager/BaseViewManager.java index 16b6b3abb26aab..1d8b484b2058c9 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/uimanager/BaseViewManager.java +++ b/ReactAndroid/src/main/java/com/facebook/react/uimanager/BaseViewManager.java @@ -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