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.import React, { useState, useEffect } from 'react'; import { AccessibilityInfo, View, Text, StyleSheet } from 'react-native'; const App = () => { const [reduceMotionEnabled, setReduceMotionEnabled] = useState(false); const [screenReaderEnabled, setScreenReaderEnabled] = useState(false); useEffect(() => { AccessibilityInfo.addEventListener('reduceMotionChanged', handleReduceMotionToggled); AccessibilityInfo.addEventListener('screenReaderChanged', handleScreenReaderToggled); AccessibilityInfo.isReduceMotionEnabled().then(reduceMotionEnabled => { setReduceMotionEnabled(reduceMotionEnabled); }); AccessibilityInfo.isScreenReaderEnabled().then(screenReaderEnabled => { setScreenReaderEnabled(screenReaderEnabled); }); return () => { AccessibilityInfo.removeEventListener('reduceMotionChanged', handleReduceMotionToggled); AccessibilityInfo.removeEventListener('screenReaderChanged', handleScreenReaderToggled); }; }, []); const handleReduceMotionToggled = reduceMotionEnabled => { setReduceMotionEnabled(reduceMotionEnabled); }; const handleScreenReaderToggled = screenReaderEnabled => { setScreenReaderEnabled(screenReaderEnabled); }; 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;
static addEventListener(eventName, handler)
Event name | Description |
---|---|
announcementFinished iOS-only | Fires when the screen reader has finished making an announcement. The argument to the event handler is a dictionary with these keys:
|
boldTextChanged iOS-only | Fires 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. |
grayscaleChanged iOS-only | Fires 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. |
invertColorsChanged iOS-only | Fires 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. |
reduceMotionChanged | Fires 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. |
reduceTransparencyChanged iOS-only | Fires 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. |
screenReaderChanged | Fires 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. |
static announceForAccessibility(announcement)
static isBoldTextEnabled()
true
when bold text is enabled and false
otherwise.static isGrayscaleEnabled()
true
when grayscale is enabled and false
otherwise.static isInvertColorsEnabled()
true
when invert colors is enabled and false
otherwise.static isReduceMotionEnabled()
true
when reduce motion is enabled and false
otherwise.static isReduceTransparencyEnabled()
true
when a reduce transparency is enabled and false
otherwise.static isScreenReaderEnabled()
true
when a screen reader is enabled and false
otherwise.static removeEventListener(eventName, handler)
static setAccessibilityFocus(reactTag)
UIManager.sendAccessibilityEvent
method with passed reactTag
and UIManager.AccessibilityEventTypes.typeViewFocused
arguments.Note: Make sure that anyView
you want to receive the accessibility focus hasaccessible={true}
.