AccessibilityInfo
Sometimes it's useful to know whether or not the device 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.
Here's a small example illustrating how to use AccessibilityInfo:
class ScreenReaderStatusExample extends React.Component {
+class AccessibilityStatusExample extends React.Component {
state = {
+ reduceMotionEnabled: false,
screenReaderEnabled: false,
};
componentDidMount() {
AccessibilityInfo.addEventListener(
- 'change',
+ 'reduceMotionChanged',
+ this._handleReduceMotionToggled,
+ );
+ AccessibilityInfo.addEventListener(
+ 'screenReaderChanged',
this._handleScreenReaderToggled,
);
- AccessibilityInfo.fetch().then((isEnabled) => {
- this.setState({
- screenReaderEnabled: isEnabled,
- });
+
+ AccessibilityInfo.isReduceMotionEnabled().then((reduceMotionEnabled) => {
+ this.setState({reduceMotionEnabled});
+ });
+ AccessibilityInfo.isScreenReaderEnabled().then((screenReaderEnabled) => {
+ this.setState({screenReaderEnabled});
});
}
componentWillUnmount() {
AccessibilityInfo.removeEventListener(
- 'change',
+ 'reduceMotionChanged',
+ this._handleReduceMotionToggled,
+ );
+
+ AccessibilityInfo.removeEventListener(
+ 'screenReaderChanged',
this._handleScreenReaderToggled,
);
}
- _handleScreenReaderToggled = (isEnabled) => {
- this.setState({
- screenReaderEnabled: isEnabled,
- });
+ _handleReduceMotionToggled = (reduceMotionEnabled) => {
+ this.setState({reduceMotionEnabled});
+ };
+
+ _handleScreenReaderToggled = (screenReaderEnabled) => {
+ this.setState({screenReaderEnabled});
};
render() {
return (
<View>
+ <Text>
+ The reduce motion is{' '}
+ {this.state.reduceMotionEnabled ? 'enabled' : 'disabled'}.
+ </Text>
<Text>
The screen reader is{' '}
{this.state.screenReaderEnabled ? 'enabled' : 'disabled'}.
@@ -79,7 +97,12 @@
Methods
-fetch
+isBoldTextEnabled
+isGrayscaleEnabled
+isInvertColorsEnabled
+isReduceMotionEnabled
+isReduceTransparencyEnabled
+isScreenReaderEnabled
addEventListener
setAccessibilityFocus
announceForAccessibility
@@ -88,8 +111,28 @@
Reference
Methods
-fetch()
-
static fetch()
+isBoldTextEnabled()
+static isBoldTextEnabled()
+
+iOS-Only. 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.
+isGrayscaleEnabled()
+static isGrayscaleEnabled()
+
+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.
+isInvertColorsEnabled()
+static isInvertColorsEnabled()
+
+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.
+isReduceMotionEnabled()
+static isReduceMotionEnabled()
+
+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.
+isReduceTransparencyEnabled()
+static isReduceTransparencyEnabled()
+
+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.
+isScreenReaderEnabled()
+static isScreenReaderEnabled()
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.
@@ -98,7 +141,12 @@
Add an event handler. Supported events:
-change: 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.
+boldTextChanged: iOS-only event. 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 event. 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 event. 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.
+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.
+reduceTransparencyChanged: iOS-only event. 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.
announcementFinished: iOS-only event. Fires 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.
diff --git a/docs/next/accessibilityinfo/index.html b/docs/next/accessibilityinfo/index.html
index 63804e2c962..737a2c6f5e4 100644
--- a/docs/next/accessibilityinfo/index.html
+++ b/docs/next/accessibilityinfo/index.html
@@ -35,39 +35,57 @@
});
AccessibilityInfo
Sometimes it's useful to know whether or not the device 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.
Here's a small example illustrating how to use AccessibilityInfo:
class ScreenReaderStatusExample extends React.Component {
+class AccessibilityStatusExample extends React.Component {
state = {
+ reduceMotionEnabled: false,
screenReaderEnabled: false,
};
componentDidMount() {
AccessibilityInfo.addEventListener(
- 'change',
+ 'reduceMotionChanged',
+ this._handleReduceMotionToggled,
+ );
+ AccessibilityInfo.addEventListener(
+ 'screenReaderChanged',
this._handleScreenReaderToggled,
);
- AccessibilityInfo.fetch().then((isEnabled) => {
- this.setState({
- screenReaderEnabled: isEnabled,
- });
+
+ AccessibilityInfo.isReduceMotionEnabled().then((reduceMotionEnabled) => {
+ this.setState({reduceMotionEnabled});
+ });
+ AccessibilityInfo.isScreenReaderEnabled().then((screenReaderEnabled) => {
+ this.setState({screenReaderEnabled});
});
}
componentWillUnmount() {
AccessibilityInfo.removeEventListener(
- 'change',
+ 'reduceMotionChanged',
+ this._handleReduceMotionToggled,
+ );
+
+ AccessibilityInfo.removeEventListener(
+ 'screenReaderChanged',
this._handleScreenReaderToggled,
);
}
- _handleScreenReaderToggled = (isEnabled) => {
- this.setState({
- screenReaderEnabled: isEnabled,
- });
+ _handleReduceMotionToggled = (reduceMotionEnabled) => {
+ this.setState({reduceMotionEnabled});
+ };
+
+ _handleScreenReaderToggled = (screenReaderEnabled) => {
+ this.setState({screenReaderEnabled});
};
render() {
return (
<View>
+ <Text>
+ The reduce motion is{' '}
+ {this.state.reduceMotionEnabled ? 'enabled' : 'disabled'}.
+ </Text>
<Text>
The screen reader is{' '}
{this.state.screenReaderEnabled ? 'enabled' : 'disabled'}.
@@ -79,7 +97,12 @@
Methods
-fetch
+isBoldTextEnabled
+isGrayscaleEnabled
+isInvertColorsEnabled
+isReduceMotionEnabled
+isReduceTransparencyEnabled
+isScreenReaderEnabled
addEventListener
setAccessibilityFocus
announceForAccessibility
@@ -88,8 +111,28 @@
Reference
Methods
-fetch()
-
static fetch()
+isBoldTextEnabled()
+static isBoldTextEnabled()
+
+iOS-Only. 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.
+isGrayscaleEnabled()
+static isGrayscaleEnabled()
+
+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.
+isInvertColorsEnabled()
+static isInvertColorsEnabled()
+
+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.
+isReduceMotionEnabled()
+static isReduceMotionEnabled()
+
+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.
+isReduceTransparencyEnabled()
+static isReduceTransparencyEnabled()
+
+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.
+isScreenReaderEnabled()
+static isScreenReaderEnabled()
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.
@@ -98,7 +141,12 @@
Add an event handler. Supported events:
-change: 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.
+boldTextChanged: iOS-only event. 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 event. 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 event. 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.
+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.
+reduceTransparencyChanged: iOS-only event. 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.
announcementFinished: iOS-only event. Fires 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.
diff --git a/docs/next/integration-with-existing-apps.html b/docs/next/integration-with-existing-apps.html
index c12c523a87f..b06fb37ddb0 100644
--- a/docs/next/integration-with-existing-apps.html
+++ b/docs/next/integration-with-existing-apps.html
@@ -151,7 +151,7 @@
"version": "0.0.1",
"private": true,
"scripts": {
- "start": "node node_modules/react-native/local-cli/cli.js start"
+ "start": "yarn react-native start"
}
}
diff --git a/docs/next/integration-with-existing-apps/index.html b/docs/next/integration-with-existing-apps/index.html
index c12c523a87f..b06fb37ddb0 100644
--- a/docs/next/integration-with-existing-apps/index.html
+++ b/docs/next/integration-with-existing-apps/index.html
@@ -151,7 +151,7 @@
"version": "0.0.1",
"private": true,
"scripts": {
- "start": "node node_modules/react-native/local-cli/cli.js start"
+ "start": "yarn react-native start"
}
}
diff --git a/docs/next/performance.html b/docs/next/performance.html
index 0e8be81f849..fbd479c581d 100644
--- a/docs/next/performance.html
+++ b/docs/next/performance.html
@@ -285,7 +285,7 @@ module.exports = config;
]
Finally, you can update "start" under "scripts" on your package.json to use the config:
-"start": "node node_modules/react-native/local-cli/cli.js start --config ../../../../packager/config.js",
"start": "yarn react-native start --config packager/config.js",
Start your package server with npm start. Note that when the dev packager is automatically launched via xcode and react-native run-android, etc, it does not use npm start, so it won't use the config.
Investigating the Loaded Modules
In your root file (index.(ios|android).js) you can add the following after the initial imports:
diff --git a/docs/next/performance/index.html b/docs/next/performance/index.html index 0e8be81f849..fbd479c581d 100644 --- a/docs/next/performance/index.html +++ b/docs/next/performance/index.html @@ -285,7 +285,7 @@ module.exports = config; ]Finally, you can update "start" under "scripts" on your package.json to use the config:
-"start": "node node_modules/react-native/local-cli/cli.js start --config ../../../../packager/config.js",
"start": "yarn react-native start --config packager/config.js",
Start your package server with npm start. Note that when the dev packager is automatically launched via xcode and react-native run-android, etc, it does not use npm start, so it won't use the config.
Investigating the Loaded Modules
In your root file (index.(ios|android).js) you can add the following after the initial imports: