Skip to main content

AccessibilityInfo

Sometimes it's useful to know whether or not the machine has a screen reader that is currently active. The AccessibilityInfo API is designed for this purpose. You can use it to query the current state of the screen reader as well as to register to be notified when the state of the screen reader changes.

info

The accessibility settings are read from the operating system. On macOS they come from the accessibility preferences. On Windows isScreenReaderEnabled, isReduceMotionEnabled and isDarkerSystemColorsEnabled follow the screen reader flag, the client-area animation setting and the high contrast theme, and isReduceTransparencyEnabled follows the Transparency effects setting. On Linux they follow GNOME's gsettings keys for the screen reader, animations and high contrast; isReduceTransparencyEnabled is always false there. On Windows and Linux the settings are polled every two seconds and the change events fire when a value differs, so a change can take up to that long to show. The remaining settings (isBoldTextEnabled, isGrayscaleEnabled, isInvertColorsEnabled) report false there. announceForAccessibility has no effect on Windows and Linux.

Example​

React JSX
import { useState, useEffect } from 'react';
import { AccessibilityInfo, StyleSheet, Text, View } from 'react-native';

const App = () => {
const [reduceMotionEnabled, setReduceMotionEnabled] = useState(false);
const [screenReaderEnabled, setScreenReaderEnabled] = useState(false);

useEffect(() => {
const reduceMotionChangedSubscription = AccessibilityInfo.addEventListener(
'reduceMotionChanged',
isReduceMotionEnabled => {
setReduceMotionEnabled(isReduceMotionEnabled);
},
);
const screenReaderChangedSubscription = AccessibilityInfo.addEventListener(
'screenReaderChanged',
isScreenReaderEnabled => {
setScreenReaderEnabled(isScreenReaderEnabled);
},
);

AccessibilityInfo.isReduceMotionEnabled().then(isReduceMotionEnabled => {
setReduceMotionEnabled(isReduceMotionEnabled);
});
AccessibilityInfo.isScreenReaderEnabled().then(isScreenReaderEnabled => {
setScreenReaderEnabled(isScreenReaderEnabled);
});

return () => {
reduceMotionChangedSubscription.remove();
screenReaderChangedSubscription.remove();
};
}, []);

return (
<View style={styles.container}>
<Text style={styles.status}>
The reduce motion is {reduceMotionEnabled ? 'enabled' : 'disabled'}.
</Text>
<Text style={styles.status}>
The screen reader is {screenReaderEnabled ? 'enabled' : 'disabled'}.
</Text>
</View>
);
};

const styles = StyleSheet.create({
container: {
flex: 1,
alignItems: 'center',
justifyContent: 'center',
},
status: {
margin: 30,
},
});

export default App;

Reference

Methods​

addEventListener()​

React TSX
static addEventListener(
eventName: AccessibilityChangeEventName | AccessibilityAnnouncementEventName,
handler: (
event: AccessibilityChangeEvent | AccessibilityAnnouncementFinishedEvent,
) => void,
): EventSubscription;

Add an event handler. Supported events:

Event nameDescription
announcementFinishedFires when the screen reader has finished making an announcement. The argument to the event handler is a dictionary with these keys:
  • announcement: The string announced by the screen reader.
  • success: A boolean indicating whether the announcement was successfully made.
boldTextChangedFires when the state of the bold text toggle changes. The argument to the event handler is a boolean. The boolean is true when bold text is enabled and false otherwise.
grayscaleChangedFires when the state of the gray scale toggle changes. The argument to the event handler is a boolean. The boolean is true when a gray scale is enabled and false otherwise.
invertColorsChangedFires when the state of the invert colors toggle changes. The argument to the event handler is a boolean. The boolean is true when invert colors is enabled and false otherwise.
reduceMotionChangedFires when the state of the reduce motion toggle changes. The argument to the event handler is a boolean. The boolean is true when a reduce motion is enabled (or when "Transition Animation Scale" in "Developer options" is "Animation off") and false otherwise.
reduceTransparencyChangedFires when the state of the reduce transparency toggle changes. The argument to the event handler is a boolean. The boolean is true when reduce transparency is enabled and false otherwise.
screenReaderChangedFires when the state of the screen reader changes. The argument to the event handler is a boolean. The boolean is true when a screen reader is enabled and false otherwise.

announceForAccessibility()​

React TSX
static announceForAccessibility(announcement: string);

Post a string to be announced by the screen reader.

On macOS the system speaks it. On Windows and Linux the window exposes it as a live region that Narrator or Orca reads when it changes. announceForAccessibilityWithOptions treats the low priority as polite and the others as assertive; queue has no effect there. announcementFinished is not sent on Windows or Linux. These have not been checked against a real screen reader.


announceForAccessibilityWithOptions()​

React TSX
static announceForAccessibilityWithOptions(
announcement: string,
options: {
queue?: boolean;
priority?: 'low' | 'default' | 'high';
},
);

Post a string to be announced by the screen reader with modification options. By default announcements will interrupt any existing speech, but they can be queued behind existing speech by setting queue to true in the options object. An optional priority can also be specified on iOS.

Parameters:

NameTypeDescription
announcement
Required
stringThe string to be announced
options
Required
objectOptions object with the following keys:
  • queue: Queue the announcement behind existing speech.
  • priority: The priority of the announcement ('low', 'default', or 'high'). High priority announcements will interrupt any ongoing speech and cannot be interrupted. Default priority announcements will interrupt any ongoing speech but can be interrupted. Low priority announcements will not interrupt ongoing speech and can be interrupted.

isInvertColorsEnabled()
Desktop
​

React TSX
static isInvertColorsEnabled(): Promise<boolean>;

Query whether invert colors is currently enabled. Returns a promise which resolves to a boolean. The result is true when invert colors is enabled and false otherwise.


isBoldTextEnabled()
Desktop
​

React TSX
static isBoldTextEnabled(): Promise<boolean>:

Query whether a bold text is currently enabled. Returns a promise which resolves to a boolean. The result is true when bold text is enabled and false otherwise.


isDarkerSystemColorsEnabled()
Desktop
​

React TSX
static isDarkerSystemColorsEnabled(): Promise<boolean>

Query whether dark system colors is currently enabled. Returns a promise which resolves to a boolean. The result is true when dark system colors is enabled and false otherwise.


isGrayscaleEnabled()
Desktop
​

React TSX
static isGrayscaleEnabled(): Promise<boolean>;

Query whether grayscale is currently enabled. Returns a promise which resolves to a boolean. The result is true when grayscale is enabled and false otherwise.


isReduceTransparencyEnabled()
Desktop
​

React TSX
static isReduceTransparencyEnabled(): Promise<boolean>;

Query whether reduce transparency is currently enabled. Returns a promise which resolves to a boolean. The result is true when a reduce transparency is enabled and false otherwise.


prefersCrossFadeTransitions()
Desktop
​

React TSX
static prefersCrossFadeTransitions(): Promise<boolean>;

Query whether reduce motion and prefer cross-fade transitions settings are currently enabled. Returns a promise which resolves to a boolean. The result is true when prefer cross-fade transitions is enabled and false otherwise.


isReduceMotionEnabled()​

React TSX
static isReduceMotionEnabled(): Promise<boolean>;

Query whether reduce motion is currently enabled. Returns a promise which resolves to a boolean. The result is true when reduce motion is enabled and false otherwise.


isScreenReaderEnabled()​

React TSX
static isScreenReaderEnabled(): Promise<boolean>;

Query whether a screen reader is currently enabled. Returns a promise which resolves to a boolean. The result is true when a screen reader is enabled and false otherwise.


isHighTextContrastEnabled()
Desktop
​

React TSX
static isHighTextContrastEnabled(): Promise<boolean>

Query whether high text contrast is currently enabled. Returns a promise which resolves to a boolean. The result is true when high text contrast is enabled and false otherwise.


🗑️ setAccessibilityFocus()​

Deprecated

Prefer using sendAccessibilityEvent with eventType focus instead.

React TSX
static setAccessibilityFocus(reactTag: number);

Set accessibility focus to a React component.

note

Make sure that any View you want to receive the accessibility focus has accessible={true}.


sendAccessibilityEvent()​

React TSX
static sendAccessibilityEvent(host: HostInstance, eventType: AccessibilityEventTypes);

Imperatively trigger an accessibility event on a React component, like changing the focused element for a screen reader.

note

Make sure that any View you want to receive the accessibility focus has accessible={true}.

NameTypeDescription
host
Required
HostInstanceThe component ref to send the event to.
eventType
Required
AccessibilityEventTypes'focus': move the screen reader focus to the component.