|
1 | 1 | --- |
2 | 2 | id: apis/AccessibilityInfo |
3 | 3 | title: AccessibilityInfo |
4 | | -wip: true |
| 4 | +officialDoc: https://facebook.github.io/react-native/docs/accessibilityinfo |
5 | 5 | --- |
6 | 6 |
|
| 7 | +## Types |
| 8 | + |
| 9 | +### `announcementResult` |
| 10 | + |
| 11 | +Passed to the handler of the `` `announcementFinished `` event. |
| 12 | + |
7 | 13 | ```reason |
8 | 14 | type announcementResult = { |
9 | 15 | . |
10 | 16 | "announcement": string, |
11 | 17 | "success": bool, |
12 | | -}; |
| 18 | +} |
| 19 | +``` |
| 20 | + |
| 21 | +where `announcement` is the string announced by the screen reader and `success` |
| 22 | +is a `bool` indicating whether the announcement was successfully made. |
| 23 | + |
| 24 | +## Methods |
| 25 | + |
| 26 | +### `isBoldTextEnabled` |
13 | 27 |
|
14 | | -[@bs.scope "AccessibilityInfo"] [@bs.module "react-native"] |
15 | | -external isBoldTextEnabled: unit => Js.Promise.t(bool) = ""; |
| 28 | +_iOS only_ |
16 | 29 |
|
17 | | -[@bs.scope "AccessibilityInfo"] [@bs.module "react-native"] |
18 | | -external isGrayscaleEnabled: unit => Js.Promise.t(bool) = ""; |
| 30 | +To query whether bold text is currently enabled. Promise resolves to `true` when |
| 31 | +bold text is enabled and `false` otherwise. |
19 | 32 |
|
20 | | -[@bs.scope "AccessibilityInfo"] [@bs.module "react-native"] |
21 | | -external isInvertColorsEnabled: unit => Js.Promise.t(bool) = ""; |
| 33 | +```reason |
| 34 | +isBoldTextEnabled: unit => Js.Promise.t(bool) |
| 35 | +``` |
| 36 | + |
| 37 | +### `isGrayscaleEnabled` |
| 38 | + |
| 39 | +_iOS only_ |
22 | 40 |
|
23 | | -[@bs.scope "AccessibilityInfo"] [@bs.module "react-native"] |
| 41 | +To query whether grayscale is currently enabled. Promise resolves to `true` when |
| 42 | +grayscale is enabled and `false` otherwise. |
| 43 | + |
| 44 | +```reason |
| 45 | +isGrayscaleEnabled: unit => Js.Promise.t(bool) |
| 46 | +``` |
| 47 | + |
| 48 | +### `isInvertColorsEnabled` |
| 49 | + |
| 50 | +_iOS only_ |
| 51 | + |
| 52 | +To query whether invert colors is currently enabled. Promise resolves to `true` |
| 53 | +when invert colors is enabled and `false` otherwise. |
| 54 | + |
| 55 | +```reason |
| 56 | +isInvertColorsEnabled: unit => Js.Promise.t(bool) |
| 57 | +``` |
| 58 | + |
| 59 | +### `isReduceMotionEnabled` |
| 60 | + |
| 61 | +To query whether reduce motion is currently enabled. Promise resolves to `true` |
| 62 | +when reduce motion is enabled and `false` otherwise. |
| 63 | + |
| 64 | +```reason |
| 65 | +[@bs.scope "AccesibilityInfo"] [@bs.module "react-native"] |
24 | 66 | external isReduceMotionEnabled: unit => Js.Promise.t(bool) = ""; |
| 67 | +``` |
| 68 | + |
| 69 | +### `isReduceTransparencyEnabled` |
| 70 | + |
| 71 | +_iOS only_ |
25 | 72 |
|
26 | | -[@bs.scope "AccessibilityInfo"] [@bs.module "react-native"] |
| 73 | +To query whether reduce transparency is currently enabled. Promise resolves to |
| 74 | +`true` when reduce transparency is enabled and `false` otherwise. |
| 75 | + |
| 76 | +```reason |
| 77 | +[@bs.scope "AccesibilityInfo"] [@bs.module "react-native"] |
27 | 78 | external isReduceTransparencyEnabled: unit => Js.Promise.t(bool) = ""; |
| 79 | +``` |
| 80 | + |
| 81 | +### `isScreenReaderEnabled` |
28 | 82 |
|
29 | | -[@bs.scope "AccessibilityInfo"] [@bs.module "react-native"] |
| 83 | +To query whether screen reader is currently enabled. Promise resolves to `true` |
| 84 | +when screen reader is enabled and `false` otherwise. |
| 85 | + |
| 86 | +```reason |
| 87 | +[@bs.scope "AccesibilityInfo"] [@bs.module "react-native"] |
30 | 88 | external isScreenReaderEnabled: unit => Js.Promise.t(bool) = ""; |
| 89 | +``` |
31 | 90 |
|
32 | | -[@bs.scope "AccessibilityInfo"] [@bs.module "react-native"] |
33 | | -external setAccessibilityFocus: NativeTypes.nodeHandle => unit = ""; |
| 91 | +### `setAccessibilityFocus` |
34 | 92 |
|
35 | | -[@bs.scope "AccessibilityInfo"] [@bs.module "react-native"] |
36 | | -external announceForAccessibility: string => unit = ""; |
| 93 | +To set accessibility focus to a React component, identified by its `nodeHandle`. |
| 94 | +On Android, this is equivalent to |
| 95 | +`UIManager.sendAccessibilityEvent(reactTag, UIManager.AccessibilityEventTypes.typeViewFocused)`; |
37 | 96 |
|
38 | | -[@bs.scope "AccessibilityInfo"] [@bs.module "react-native"] |
39 | | -external addEventListener: |
40 | | - ( |
41 | | - [@bs.string] |
42 | | - [ |
| 97 | +```reason |
| 98 | +setAccessibilityFocus: NativeTypes.nodeHandle => unit |
| 99 | +``` |
| 100 | + |
| 101 | +### `announceForAccessibility` |
| 102 | + |
| 103 | +To post a string to be announced by the screen reader. |
| 104 | + |
| 105 | +```reason |
| 106 | +announceForAccessibility: string => unit |
| 107 | +``` |
| 108 | + |
| 109 | +### `addEventListener` |
| 110 | + |
| 111 | +Add an event handler. |
| 112 | + |
| 113 | +```reason |
| 114 | +addEventListener: [ |
43 | 115 | | `boldTextChanged(bool => unit) |
44 | 116 | | `grayscaleChanged(bool => unit) |
45 | 117 | | `invertColorsChanged(bool => unit) |
46 | 118 | | `reduceMotionChanged(bool => unit) |
47 | 119 | | `screenReaderChanged(bool => unit) |
48 | 120 | | `reduceTransparencyChanged(bool => unit) |
49 | 121 | | `announcementFinished(announcementResult => unit) |
50 | | - ] |
51 | | - ) => |
52 | | - unit = |
53 | | - ""; |
54 | | -
|
55 | | -[@bs.scope "AccessibilityInfo"] [@bs.module "react-native"] |
56 | | -external removeEventListener: |
57 | | - ( |
58 | | - [@bs.string] |
59 | | - [ |
| 122 | + ] => unit |
| 123 | +``` |
| 124 | + |
| 125 | +Supported events: |
| 126 | + |
| 127 | +- `boldTextChanged(bool => unit)`: _iOS only_. Fires when state of the bold text |
| 128 | + toggle changes. The argument to the event handler is a `bool` which is `true` |
| 129 | + when bold text is enabled and `false` otherwise. |
| 130 | +- `grayscaleChanged(bool => unit)`: _iOS only_. Fires when state of the gray |
| 131 | + scale toggle changes. The argument to the event handler is a `bool` which is |
| 132 | + `true` when gray scale is enabled and `false` otherwise. |
| 133 | +- `invertColorsChanged(bool => unit)`: _iOS only_. Fires when state of the |
| 134 | + invert colors toggle changes. The argument to the event handler is a `bool` |
| 135 | + which is `true` when invert colors is enabled and `false` otherwise. |
| 136 | +- `reduceMotionChanged(bool => unit)`: Fires when state of the reduce motion |
| 137 | + toggle changes. The argument to the event handler is a `bool` which is `true` |
| 138 | + when reduce motion is enabled (or when "Transition Animation Scale" in |
| 139 | + "Developer options" is "Animation off") and `false` otherwise. |
| 140 | +- `screenReaderChanged(bool => unit)`: Fires when state of the screen reader |
| 141 | + changes. The argument to the event handler is a `bool` which is `true` when a |
| 142 | + screen reader is enabled and `false` otherwise. |
| 143 | +- `reduceTransparencyChanged(bool => unit)`: _iOS only_. Fires when state of the |
| 144 | + reduce transparency toggle changes. The argument to the event handler is a |
| 145 | + `bool` which is `true` when reduce transparency is enabled and `false` |
| 146 | + otherwise. |
| 147 | +- `announcementFinished(announcementResult => unit)`: _iOS only_. Fires when the |
| 148 | + screen reader has finished making an announcement. The argument to the event |
| 149 | + handler is of type [`announcementResult`](#announcementResult). |
| 150 | + |
| 151 | +### `removeEventListener` |
| 152 | + |
| 153 | +To remove an event handler. |
| 154 | + |
| 155 | +```reason |
| 156 | +addEventListener: [ |
60 | 157 | | `boldTextChanged(bool => unit) |
61 | 158 | | `grayscaleChanged(bool => unit) |
62 | 159 | | `invertColorsChanged(bool => unit) |
63 | 160 | | `reduceMotionChanged(bool => unit) |
64 | 161 | | `screenReaderChanged(bool => unit) |
65 | 162 | | `reduceTransparencyChanged(bool => unit) |
66 | 163 | | `announcementFinished(announcementResult => unit) |
67 | | - ] |
68 | | - ) => |
69 | | - unit = |
70 | | - ""; |
71 | | -
|
| 164 | + ] => unit |
72 | 165 | ``` |
| 166 | + |
| 167 | +See [`addEventListener`](#addEventListener) for more details on supported |
| 168 | +events. |
0 commit comments