Skip to content

Commit 333b46c

Browse files
fabOnReactfacebook-github-bot
authored andcommitted
Fix Image does not announce "disabled" (#31252)
Summary: This issue fixes #30935 screenreader does not announce Image disabled accessibilityState. As stated in AOSP View.java, the framework will handle routine focus movement, views indicate their willingness to take focus through the `isFocusable` method https://bit.ly/3dCnyHb ``` * <p>The framework will handle routine focus movement in response to user input. This includes * changing the focus as views are removed or hidden, or as new views become available. Views * indicate their willingness to take focus through the {link #isFocusable} method. To change * whether a view can take focus, call {link #setFocusable(boolean)}. ``` The property is updated through its shadow node `ReactImageManager` method `setAccessible` https://bit.ly/3dDuK5L ```java * <p>Instances of this class receive property updates from JS via @{link UIManagerModule}. * Subclasses may use {link #updateShadowNode} to persist some of the updated fields in the node * instance that corresponds to a particular view type. ``` ## Changelog <!-- Help reviewers and the release process by writing your own changelog entry. For an example, see: https://github.com/facebook/react-native/wiki/Changelog --> [Android] [Fixed] - adding setAccessible to ReactImageManager to allow screenreader announce Image accessibilityState of "disabled" Pull Request resolved: #31252 Test Plan: **<details><summary>CLICK TO OPEN TESTS RESULTS</summary>** <p> Enable audio to hear the screenreader TEST SCENARIO - The user moves the screenreader focus to an image and the screenreader reads the Image accessibilityLabel "plain network image" RESULT - The screenreader announces the accessibilityState disabled after reading the Image accessibilityLabel "plain network image" ```javascript <Image accessible={true} accessibilityLabel="plain network image" accessibilityState={{disabled: true}} source={fullImage} style={styles.base} /> ``` <video src="https://user-images.githubusercontent.com/24992535/112670432-2f366d00-8e61-11eb-843f-4b56f4a06a91.mp4" width="700" /> </p> </details> Reviewed By: kacieb Differential Revision: D28194597 Pulled By: lunaleaps fbshipit-source-id: 5f89ce5c714405506261885ac6fea2c15c2e1f23
1 parent e0aec42 commit 333b46c

File tree

3 files changed

+32
-0
lines changed

3 files changed

+32
-0
lines changed

ReactAndroid/src/main/java/com/facebook/react/views/image/ReactImageManager.java

+5
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,11 @@ public ReactImageView createViewInstance(ThemedReactContext context) {
113113
context, getDraweeControllerBuilder(), mGlobalImageLoadListener, callerContext);
114114
}
115115

116+
@ReactProp(name = "accessible")
117+
public void setAccessible(ReactImageView view, boolean accessible) {
118+
view.setFocusable(accessible);
119+
}
120+
116121
// In JS this is Image.props.source
117122
@ReactProp(name = "src")
118123
public void setSource(ReactImageView view, @Nullable ReadableArray sources) {

ReactAndroid/src/test/java/com/facebook/react/views/image/ReactImagePropertyTest.java

+8
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,14 @@ public void testRoundedCorners() {
120120
viewManager.updateProperties(view, buildStyles("borderRadius", null));
121121
}
122122

123+
@Test
124+
public void testAccessibilityFocus() {
125+
ReactImageManager viewManager = new ReactImageManager();
126+
ReactImageView view = viewManager.createViewInstance(mThemeContext);
127+
viewManager.setAccessible(view, true);
128+
assertEquals(true, view.isFocusable());
129+
}
130+
123131
@Test
124132
public void testTintColor() {
125133
ReactImageManager viewManager = new ReactImageManager();

packages/rn-tester/js/examples/Accessibility/AccessibilityExample.js

+19
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,10 @@ const styles = StyleSheet.create({
5555
resizeMode: 'contain',
5656
marginRight: 10,
5757
},
58+
disabledImage: {
59+
width: 120,
60+
height: 120,
61+
},
5862
containerAlignCenter: {
5963
display: 'flex',
6064
flexDirection: 'column',
@@ -978,4 +982,19 @@ exports.examples = [
978982
return <EnabledExamples />;
979983
},
980984
},
985+
{
986+
title:
987+
'Check if accessibilityState disabled is announced when the screenreader focus moves on the image',
988+
render(): React.Element<typeof Image> {
989+
return (
990+
<Image
991+
accessible={true}
992+
accessibilityLabel="plain local image"
993+
accessibilityState={{disabled: true}}
994+
source={require('../../assets/like.png')}
995+
style={styles.disabledImage}
996+
/>
997+
);
998+
},
999+
},
9811000
];

0 commit comments

Comments
 (0)