Skip to content

Commit f35d18c

Browse files
okwasniewskifacebook-github-bot
authored andcommitted
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: #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
1 parent ee9c1a5 commit f35d18c

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

ReactAndroid/src/main/java/com/facebook/react/uimanager/BaseViewManager.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,9 @@ public void setViewState(@NonNull T view, @Nullable ReadableMap accessibilitySta
287287
view.setSelected(false);
288288
}
289289
view.setTag(R.id.accessibility_state, accessibilityState);
290-
view.setEnabled(true);
290+
if (accessibilityState.hasKey("disabled") && !accessibilityState.getBoolean("disabled")) {
291+
view.setEnabled(true);
292+
}
291293

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

0 commit comments

Comments
 (0)