Skip to content

Commit 70e2ab2

Browse files
Marc Mulcahyfacebook-github-bot
Marc Mulcahy
authored andcommitted
Update Android view state when accessibility states are changed. (#24678)
Summary: In #24095, we removed the code that changes the underlying Android view's enabled state to false when "disabled" is included in the accessibility states, which seems correct. The Android view's state shouldn't mirror the accessibility state, it should be the other way round-- the accessibility state should represent the state of the view. It seems that the existing test is brokenly setting the disabled state in the Javascript object, and then querying the Android view's enabled state to confirm the change. If the Button implementation is actually the culprit, then IMHO, the correct fix would be to have the Button implementation manipulate the Android View's enabled state, not the accessibilityStates code. [android] [fix] - Fix internal test case around disabled state of buttons Pull Request resolved: #24678 Differential Revision: D15237590 Pulled By: cpojer fbshipit-source-id: d7ebefbcba9d4d9425da4285175302e4b6435df7
1 parent 2becfab commit 70e2ab2

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

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

+12-1
Original file line numberDiff line numberDiff line change
@@ -146,11 +146,22 @@ public void setViewStates(@Nonnull T view, @Nullable ReadableArray accessibility
146146
return;
147147
}
148148
view.setTag(R.id.accessibility_states, accessibilityStates);
149+
view.setSelected(false);
150+
view.setEnabled(true);
151+
boolean shouldUpdateContentDescription = false;
149152
for (int i = 0; i < accessibilityStates.size(); i++) {
150153
String state = accessibilityStates.getString(i);
151154
if (sStateDescription.containsKey(state)) {
152-
updateViewContentDescription(view);
155+
shouldUpdateContentDescription = true;
153156
}
157+
if (state.equals("selected")) {
158+
view.setSelected(true);
159+
} else if (state.equals("disabled")) {
160+
view.setEnabled(false);
161+
}
162+
}
163+
if (shouldUpdateContentDescription) {
164+
updateViewContentDescription(view);
154165
}
155166
}
156167

0 commit comments

Comments
 (0)