From 56d5a776362dd2ede9a63ff76bef4a958edc085d Mon Sep 17 00:00:00 2001 From: Joshua Alvarado Date: Tue, 12 Sep 2017 12:38:13 -0700 Subject: [PATCH] Proper support of the accessibilityLabel for components on iOS Summary: **PR changes** The RCTText class originally overrode the accessibilityLabel and returned the raw text of the class ignoring if the accessibilityLabel was set explicitly in code. Example: Hello World // returns "Hello World" instead of "Example" for the accessibility label My update checks if the super's accessibilityLabel is not nil and returns the value else it returns the raw text itself as a default to mirror what a UIKit's UILabel does. The super's accessibilityLabel is nil if the accessibilityLabel is not ever set in code. I don't check the length of the label because if the value was set to an empty purposely then it will respect that and return whatever was set in code. With the new changes: Hello World // returns "Example" for the accessibilityLabel This change doesn't support nested components with both accessibilityLabel's value set respectively. The parent's value will return. Example: // returns "Example" instead of "Example Test" for the accessibility label Hello World The workaround is just to set the only the parent view's accessibilityLabel with the label desired for it and all its nested views or just not nest the views if possible. I believe a bigger change would be needed to support accessibility for nested views, for now the changes I have made should satisfy the requirements. Reviewed By: shergin Differential Revision: D5806097 fbshipit-source-id: aef2d7cec4657317fcd7dd557448905e4b767f1a --- js/AccessibilityIOSExample.js | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/js/AccessibilityIOSExample.js b/js/AccessibilityIOSExample.js index 30902ac6cb1..29c8b16f062 100644 --- a/js/AccessibilityIOSExample.js +++ b/js/AccessibilityIOSExample.js @@ -48,6 +48,13 @@ class AccessibilityIOSExample extends React.Component<{}> { Accessibility traits example + + Text's accessibilityLabel is the raw text itself unless it is set explicitly. + + + This text component's accessibilityLabel is set explicitly. + ); }