Accessibility
Both Android and iOS provide APIs for integrating apps with assistive technologies like the bundled screen readers VoiceOver (iOS) and TalkBack (Android). React Native has complementary APIs that let your app accommodate all users.
Android and iOS differ slightly in their approaches, and thus the React Native implementations may vary by platform.
Accessibility properties
accessible
When true, indicates that the view is discoverable by assistive technologies such as screen readers and hardware keyboards. Note that this does not necessarily mean that the view will be focused by VoiceOver or TalkBack. There are a number of reasons for this, such as VoiceOver disallowing nested accessibility elements, or TalkBack opting to focus some parent element instead.
By default, all touchable elements are accessible.
On Android, accessible will be translated into native focusable. On iOS, it translates into native isAccessibilityElement.
<View>
<View accessible={true} />
<View />
</View>
In the above example, accessibility focus is only available on the first child view with the accessible property, and not for the parent or sibling without accessible.
accessibilityLabel
When a view is marked as accessible, it is a good practice to set an accessibilityLabel on the view, so that people who use VoiceOver or TalkBack know what element they have selected. A screen reader will verbalize this string when the associated element is selected.
To use, set the accessibilityLabel property to a custom string on your View, Text, or Touchable:
<TouchableOpacity
accessible={true}
accessibilityLabel="Tap me!"
onPress={onPress}>
<View style={styles.button}>
<Text style={styles.buttonText}>Press me!</Text>
</View>
</TouchableOpacity>
In the above example, the accessibilityLabel on the TouchableOpacity element would default to "Press me!". The label is constructed by concatenating all Text node children separated by spaces.
accessibilityLabelledBy Android
A reference to another element nativeID used to build complex forms.
The value of accessibilityLabelledBy should match the nativeID of the related element:
<View>
<Text nativeID="formLabel">Label for Input Field</Text>
<TextInput
accessibilityLabel="input"
accessibilityLabelledBy="formLabel"
/>
</View>
In the above example, the screen reader announces Input, Edit Box for Label for Input Field when focusing on the TextInput.
accessibilityHint
An accessibility hint can be used to provide additional context to the user on the result of the action when it is not clear from the accessibility label alone.
Provide the accessibilityHint property a custom string on your View, Text, or Touchable:
<TouchableOpacity
accessible={true}
accessibilityLabel="Go back"
accessibilityHint="Navigates to the previous screen"
onPress={onPress}>
<View style={styles.button}>
<Text style={styles.buttonText}>Back</Text>
</View>
</TouchableOpacity>
In the above example, VoiceOver will read the hint after the label, if the user has hints enabled in the device's VoiceOver settings. Read more about guidelines for accessibilityHint in the iOS Developer Docs
In the above example, TalkBack will read the hint after the label. At this time, hints cannot be turned off on Android.
accessibilityLanguage iOS
By using the accessibilityLanguage property, the screen reader will understand which language to use while reading the element's label, value, and hint. The provided string value must follow the BCP 47 specification.
<View
accessible={true}
accessibilityLabel="Pizza"
accessibilityLanguage="it-IT">
<Text>🍕</Text>
</View>
accessibilityIgnoresInvertColors iOS
Inverting screen colors is an accessibility feature available in iOS and iPadOS for people with color blindness, low vision, or vision impairment. If there's a view you don't want to invert when this setting is on, possibly a photo, set this property to true.
accessibilityLiveRegion Android
When components dynamically change, we want TalkBack to alert the end user. This is made possible by the accessibilityLiveRegion property. It can be set to none, polite, and assertive:
- none Accessibility services should not announce changes to this view.
- polite Accessibility services should announce changes to this view.
- assertive Accessibility services should interrupt ongoing speech to immediately announce changes to this view.
<TouchableWithoutFeedback onPress={addOne}>
<View style={styles.embedded}>
<Text>Click me</Text>
</View>
</TouchableWithoutFeedback>
<Text accessibilityLiveRegion="polite">
Clicked {count} times
</Text>
In the above example method addOne changes the state variable count. When the TouchableWithoutFeedback is triggered, TalkBack reads the text in the Text view because of its accessibilityLiveRegion="polite" property.
accessibilityRole
accessibilityRole communicates the purpose of a component to the user of assistive technology.
accessibilityRole can be one of the following:
- adjustable Used when an element can be "adjusted" (e.g. a slider).
- alert Used when an element contains important text to be presented to the user.
- button Used when the element should be treated as a button.
- checkbox Used when an element represents a checkbox that can be checked, unchecked, or have a mixed checked state.
- combobox Used when an element represents a combo box, which allows the user to select among several choices.
- header Used when an element acts as a header for a content section (e.g. the title of a navigation bar).
- image Used when the element should be treated as an image. Can be combined with a button or link.
- imagebutton Used when the element should be treated as a button and is also an image.
- keyboardkey Used when the element acts as a keyboard key.
- link Used when the element should be treated as a link, specifically for interactive elements that open an external URL or web page in a browser. For in-app screen navigation or actions, use
buttoninstead. - menu Used when the component is a menu of choices.
- menubar Used when a component is a container of multiple menus.