A screen reader user operates an app through gestures such as swipes and double taps, so a feature that depends on a drag or on a visual change needs another way in. React Native lets a component declare actions the screen reader can trigger and lets the app speak when something changes. Through AccessibilityInfo, it also exposes the settings the user picked, such as reduce motion, so the app can respect them.
Key terms
- accessibilityActions: the list of actions a component supports, each an object with a required
nameand an optionallabel. - onAccessibilityAction: the handler that runs when assistive technology requests one of those actions.
- accessibilityLiveRegion: an Android prop that makes TalkBack announce changes to a view.
- AccessibilityInfo: a module, imported from
react-native, that queries the screen reader state and other accessibility settings and subscribes to their changes.
Actions a screen reader can run
To support actions, a component does two things. It lists them in accessibilityActions, and it handles them in onAccessibilityAction. The handler receives a single event, and the requested action's name is in event.nativeEvent.actionName.
Standard actions have fixed names and come from the screen reader's own gestures:
activateruns when the user double taps the component.incrementanddecrementadjust a component. On iOS, VoiceOver generates them when a component with theadjustablerole has focus and the user swipes up or down. On Android, the Adjust Reading Control gesture sends them, swiping up forincrementfrom TalkBack 9.1 and down fordecrementfrom TalkBack 9.2.longpress(Android) comes from a double tap and hold on the focused component.expandandcollapse(Android) make TalkBack announce an expanded or collapsed hint.magicTapandescapeare iOS only.
Any other name is a custom action. name is required for every action, while label is optional for standard actions. For a custom action, the label is the localized description shown to the user. On Android, a label can also replace TalkBack's default "Double tap to activate" announcement.
Swipe actions on a message row
If archiving a message takes a horizontal drag, a screen reader user needs another route to it. The MessageRow example adds archive and markUnread as custom actions with the labels "Archive" and "Mark as unread", and handleAction dispatches on the name:
tsxswitch (event.nativeEvent.actionName) { case 'archive': onArchive(); break;
The row stays a Pressable, so it is already an accessibility element and opening the message works as before.
Announcing changes
Two tools make the screen reader speak when content changes, for example a cart count after a tap.
On Android, accessibilityLiveRegion on a view makes TalkBack announce its changes. polite announces them, assertive interrupts ongoing speech to announce them right away, and none keeps quiet. A Text with accessibilityLiveRegion="polite" showing {count} items in cart is read again each time the count changes. Its alias, aria-live, takes off, polite or assertive, defaults to off, and maps off to none.
AccessibilityInfo.announceForAccessibility(message) posts a string for the screen reader to announce. It calls the native module of the platform it runs on, so it works on iOS and Android. announceForAccessibilityWithOptions(message, options) takes queue (a boolean) and priority (low, default or high). It interrupts existing speech by default, and queue: true waits behind it instead. Both options are iOS only. On Android the call ignores them and runs the plain announceForAccessibility. On iOS, the announcementFinished event fires when an announcement ends, with announcement and success keys.
Reading the user's settings
The queries on AccessibilityInfo return Promises, and they don't all work on both platforms:
| Method | Resolves to true when | Platforms |
|---|---|---|
isReduceMotionEnabled() | reduce motion is on | iOS and Android |
isScreenReaderEnabled() | VoiceOver, or TalkBack's touch exploration, is on | iOS and Android |
prefersCrossFadeTransitions() | reduce motion and prefer cross-fade transitions are both on | iOS, always false on Android |
isAccessibilityServiceEnabled() | any accessibility service is on, TalkBack or a third-party app | Android, rejects with an error on iOS |
To check for TalkBack alone, use isScreenReaderEnabled(), since isAccessibilityServiceEnabled() also counts third-party accessibility apps.
A setting can change while the app runs, so read it once and then subscribe. AccessibilityInfo.addEventListener('reduceMotionChanged', handler) calls the handler with a boolean. It is true when reduce motion is on, or on Android when Transition Animation Scale in Developer options is set to Animation off. addEventListener returns an EventSubscription, and you call remove() on it in the effect cleanup. The useReduceMotion hook does both steps, and a screen can then write if (!reduceMotion) startParallax().
An event name the current platform doesn't support fails quietly. addEventListener returns a subscription whose remove() does nothing, and the handler never fires, so check the platform of each event before you rely on it.
Code Examples
import {Pressable, Text} from 'react-native';
import type {AccessibilityActionEvent} from 'react-native';
type Props = {
sender: string;
preview: string;
onOpen: () => void;
onArchive: () => void;
onMarkUnread: () => void;
};
export function MessageRow({
sender,
preview,
onOpen,
onArchive,
onMarkUnread,
}: Props) {
function handleAction(event: AccessibilityActionEvent) {
switch (event.nativeEvent.actionName) {
case 'archive':
onArchive();
break;
case 'markUnread':
onMarkUnread();
break;
}
}
return (
<Pressable
onPress={onOpen}
accessibilityActions={[
{name: 'archive', label: 'Archive'},
{name: 'markUnread', label: 'Mark as unread'},
]}
onAccessibilityAction={handleAction}>
<Text>{sender}</Text>
<Text>{preview}</Text>
</Pressable>
);
}import {useEffect, useState} from 'react';
import {AccessibilityInfo} from 'react-native';
export function useReduceMotion(): boolean {
const [reduceMotion, setReduceMotion] = useState(false);
useEffect(() => {
AccessibilityInfo.isReduceMotionEnabled().then(setReduceMotion);
const subscription = AccessibilityInfo.addEventListener(
'reduceMotionChanged',
setReduceMotion,
);
return () => subscription.remove();
}, []);
return reduceMotion;
}