You.i React Native allows app developers to support screen reader (text-to-speech) functionality using various RN props, methods, and modules. This topic covers the supported props, methods, modules, gesture support, screen reader settings, and best practices for creating accessible apps.
We support screen reader functionality for the following target platforms:
Refer to RNSampleApp, located at youiengine/<version>/samples/RNSampleApp
, for an example of how accessibility is implemented with You.i React Native.
In general, to know more about the accessibility feature in React Native, see Facebook’s Accessibility topic.
Before we begin, we should define two terms used in this topic: accessibility focus and navigation focus.
The following props are supported in You.i React Native for accessibility:
Props Supported | For Which Components | Details | Facebook RN Docs |
---|---|---|---|
accessible |
Button, ButtonRef, Image, ImageRef, Text, TextInput, TextInputRef, TextRef, TouchableHighlight, TouchableOpacity, TouchableWithoutFeedback, View, and ViewRef | When true , indicates that the view is an accessibility element. |
accessible |
accessibilityActions |
View and ViewRef | Allows an assistive technology to programmatically invoke the actions of a component. | accessibilityActions |
accessibilityHint |
Text, TextRef, TouchableWithoutFeedback, View, and ViewRef | Helps users understand what will happen when they perform an action on the accessibility element when that result is not clear from the accessibility label. | accessibilityHint |
accessibilityLabel |
Button, ButtonRef, Image, ImageRef, Text, TextRef, TouchableWithoutFeedback, View, and ViewRef | A screen reader reads this string when a user selects the associated element. See also How accessibilityLabel works below. | accessibilityLabel |
accessibilityRole |
TouchableWithoutFeedback, View, and ViewRef | Communicates the purpose of a component to the user of an assistive technology. You.i React Native supports every role listed for accessibilityRole. | accessibilityRole |
accessibilityStates 1
|
TouchableWithoutFeedback, View, and ViewRef | Describes the current state of a component to the user of an assistive technology. You.i React Native supports every state listed for accessibilityStates. | accessibilityStates |
onAccessibilityAction |
View, and ViewRef | The following standard actions are supported: - activate - escape - magicTap - increment - decrement Custom actions are not supported. |
onAccessibilityAction |
onAccessibilityEscape |
View, and ViewRef | onAccessibilityEscape | |
onAccessibilityTap |
View, and ViewRef | onAccessibilityTap | |
onMagicTap |
View, and ViewRef | onMagicTap |
accessibilityState
mentioned in the Facebook RN documentation should be accessibilityStates
.The following is an example of how to add accessibility props to your application. To see this example in context, see our Quick Start Guide.
<View style={styles.buttonContainer}
focusable={true}
accessible={true}
accessibilityLabel="My button"
accessibilityHint="Button in your first app"
accessibilityRole="button"
>
<Button
onPress={this.onMyButtonPress}
title="My button"
/>
</View>
A screen reader reads the accessibilityLabel
string when a user selects the associated element.
accessibilityLabel
is set for an accessible component, the label value is read.
Note that if you pass a string whose contents are whitespace to the accessibilityLabel
, the screen reader reads out the whitespace.accessibilityLabel
isn’t set for an accessible component, the contents of the component are read.accessibilityLabel
is set to an empty string for an accessible component, the contents of the component are read.
Facebook RN, by contrast, reads nothing in this situation.You.i React Native supports the Facebook RN AccessibilityInfo module, which allows you to confirm whether the screen reader functionality on the device is currently active. To know more about the methods supported by You.i React Native for each target platform, see AccessibilityInfo.
Screen reader functionality is supported for screen elements like buttons, scrolling lists, and static images created within an After Effects layout. Be aware that some elements like buttons and text inputs have default accessibility behaviors, while others don’t. If you don’t specify accessibility attributes as described in this section, you may see the default behaviors in some screen elements in your apps, and none in others.
You can specify attributes for this functionality in After Effects by adding accessibility properties to your layer comments for each element before you export. All you have to do is type in the property for the associated attribute in the layer comment field.
For example, the following image shows a Back button with accessibility attributes set within layer comments in the After Effects timeline view.
These accessibility comments are React Native props that are picked up from After Effects when generating an RN or a C++ app:
accessibilityLabel
accessibilityHint
accessibilityStates
accessibilityRole
When a screen element is activated via a gesture from a user, screen reader capability in the device reads the attributes aloud in this order: label
, states
, role
, hint
.
Depending on the component you’re creating in After Effects, you’ll need to input a particular, preset accessibilityRole
, such as button
for a button.
The same applies to accessibilityStates
.
You.i Platform supports all of the roles available in React Native; accessibilityStates
supported include disabled
, checked
, and expanded
.
For the full list of accessibility roles, see Facebook’s RN documentation on accessibilityRole.
For hints and labels, consider the needs of the user and the design of the final app.
Typically, the accessibilityHint
tells a user the action performed by the element they’re activating.
For example, a back button hint might be “navigates to the previous screen.”
The accessibilityLabel
performs a similar function, except that the label for a back button might be “go back.”
If a user requests the whole screen to be read one element at a time, both the accessibilityLabel
and the accessibilityHint
are read.
However, if the entire screen is being read, attributes are read in this order: label, states, role (hint is not read).
This might affect your decisions about what you want the label and the hint to be.
The tags associated with each designation, such as accessibilityLabel: “Back”
, allow the screen reader feature to read that tag for each screen element in a view.
For more on how these props work, see Facebook’s Accessibility documentation. And for more examples like the one above, refer to RNSampleApp in the You.i Platform package files.
Layer comments in After Effects work similarly for both C++ apps and React Native apps.
For a C++ application, CYIAccessibilityAttributes
is the class you’d interface with directly to enable screen reading functionality, whereas the React Native framework interfaces with that class for you when developing a React Native application.
See our API documentation on CYIAccessibilityAttributes
for more information.
Generally, any screen element that you create in After Effects that has accessibility information listed in the layer comments for that element is read. One exception involves scrolling lists: when creating a scrolling list, the list must use a row or column arrangement if you want the list item’s index to be read.
While React Native allows you to create variable strings that refer to other props, in After Effects the layer comments are static strings that can’t reference other props. To handle this limitation, rather than inserting your comments in AE, use the Ref component associated with the screen element in AE, and set any applicable RN accessibility props within that Ref component.
Follow these best practices for developing accessible apps using You.i React Native:
Annotate your app code with appropriate labels or hints using accessibilityHint
and accessibilityLabel
to control the announcement of special characters.
For example, in our Quick Start Guide we annotate You.i TV as You I TV.
<Text
style={[styles.bodyText, themeStyles.bodyText]}
accessibilityLabel="https://developer dot you i dot tv"
>
https://developer.youi.tv
</Text>
accessibilityRole
to announce the purpose of a component and accessibilityStates
to announce a component’s current state.AccessibilityInfo
module that provides methods, such as setAccessibilityFocus
and announceForAccessibility
, to customize the accessibility features in your app.accessibilityLabel
with any text in the image that you want announced.If the screen reader is turned on after an app is launched, You.i Platform automatically moves the accessibility focus to the currently focused item if it’s accessible. If there’s currently no focus, or if the focused item isn’t accessible, You.i Platform searches for an accessible focus item from the top-left corner, in left-to-right reading order. As a result, it’s a good idea for your app to handle the state change when the screen reader is enabled by explicitly setting the accessibility focus to a specific location.
You can use addEventListener
and setAccessibilityFocus
to listen for the screen reader state change and set the accessibility focus; see AccessibilityInfo in the Facebook RN docs.
Focus behavior differs by platform; consult the accessibility topic for your target platform. You can see the list of topics in the left-hand navigation menu.
accessibilityHint
on the relevant view for a screen reader to provide navigation hints.accessibilityHint
to configure hints based on the platform the app is running on.Use accessibilityHint
, accessibilityLabel
, and accessibilityRole
to configure the screen reader for search results or search text.
The following are the current limitations and known issues for using accessibility with You.i React Native: