@react-native-oh/react-native-harmony 0.72.23-3 → 0.72.27-1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (44) hide show
  1. package/Libraries/Alert/Alert.harmony.js +71 -71
  2. package/Libraries/Alert/AlertManager.ts +35 -35
  3. package/Libraries/Animated/NativeAnimatedHelper.harmony.js +601 -601
  4. package/Libraries/Components/AccessibilityInfo/AccessibilityInfo.harmony.js +445 -426
  5. package/Libraries/Components/AccessibilityInfo/NativeAccessibilityManager.harmony.js +30 -0
  6. package/Libraries/Components/AccessibilityInfo/legacySendAccessibilityEvent.harmony.js +26 -0
  7. package/Libraries/Components/Button/Button.harmony.js +450 -450
  8. package/Libraries/Components/Image/Image.flow.harmony.js +53 -0
  9. package/Libraries/Components/Image/Image.harmony.js +299 -0
  10. package/Libraries/Components/Image/NativeImageLoaderHarmony.js +38 -0
  11. package/Libraries/Components/RefreshControl/RefreshControl.harmony.js +210 -210
  12. package/Libraries/Components/SafeAreaView/SafeAreaView.harmony.tsx +76 -75
  13. package/Libraries/Components/ScrollView/ScrollView.harmony.js +1951 -1951
  14. package/Libraries/Components/ScrollView/processDecelerationRate.harmony.js +24 -24
  15. package/Libraries/Components/StatusBar/NativeStatusBarManagerHarmony.js +71 -68
  16. package/Libraries/Components/StatusBar/StatusBar.harmony.js +447 -447
  17. package/Libraries/Components/TextInput/TextInput.harmony.js +1707 -1707
  18. package/Libraries/Components/TextInput/TextInputState.harmony.js +220 -220
  19. package/Libraries/Components/Touchable/TouchableHighlight.harmony.js +396 -396
  20. package/Libraries/Components/Touchable/TouchableNativeFeedback.harmony.js +364 -364
  21. package/Libraries/Components/Touchable/TouchableWithoutFeedback.harmony.js +227 -227
  22. package/Libraries/Components/View/View.harmony.js +149 -149
  23. package/Libraries/Core/setUpReactDevTools.harmony.js +93 -93
  24. package/Libraries/Image/AssetSourceResolver.harmony.ts +78 -78
  25. package/Libraries/NativeComponent/BaseViewConfig.harmony.js +337 -337
  26. package/Libraries/ReactNative/UIManager.harmony.js +210 -210
  27. package/Libraries/Settings/Settings.harmony.js +15 -15
  28. package/Libraries/Share/Share.harmony.js +174 -174
  29. package/Libraries/StyleSheet/NativePlatformColor.ts +8 -8
  30. package/Libraries/StyleSheet/PlatformColorValueTypes.harmony.ts +14 -14
  31. package/Libraries/Utilities/BackHandler.harmony.js +109 -109
  32. package/Libraries/Utilities/{NativePlatformConstantsHarmony.ts → NativePlatformConstants.harmony.ts} +8 -8
  33. package/Libraries/Utilities/Platform.d.ts +117 -117
  34. package/Libraries/Utilities/Platform.harmony.ts +33 -33
  35. package/Libraries/Utilities/createPerformanceLogger.harmony.js +328 -328
  36. package/Libraries/Vibration/Vibration.harmony.js +88 -88
  37. package/index.js +212 -212
  38. package/jest.config.js +5 -5
  39. package/metro.config.js +348 -348
  40. package/package.json +57 -57
  41. package/react-native.config.js +10 -10
  42. package/react_native_openharmony.har +0 -0
  43. package/tsconfig.json +13 -13
  44. package/types/index.d.ts +101 -101
@@ -1,426 +1,445 @@
1
- /**
2
- * Copyright (c) Meta Platforms, Inc. and affiliates.
3
- *
4
- * This source code is licensed under the MIT license found in the
5
- * LICENSE file in the root directory of this source tree.
6
- *
7
- * @flow strict-local
8
- * @format
9
- */
10
-
11
- // RNOH: patch
12
- // COPIED FROM: https://github.com/facebook/react-native/blob/main/packages/react-native/Libraries/Components/AccessibilityInfo/AccessibilityInfo.js
13
-
14
- import type { HostComponent } from "react-native/Libraries/Renderer/shims/ReactNativeTypes";
15
- import type { EventSubscription } from "react-native/Libraries/vendor/emitter/EventEmitter";
16
- import type { ElementRef } from "react";
17
-
18
- // RNOH: patch - imports fixed
19
- import RCTDeviceEventEmitter from "react-native/Libraries/EventEmitter/RCTDeviceEventEmitter";
20
- import { sendAccessibilityEvent } from "react-native/Libraries/ReactNative/RendererProxy";
21
- import Platform from "../../Utilities/Platform";
22
- import legacySendAccessibilityEvent from "react-native/Libraries/Components/AccessibilityInfo/legacySendAccessibilityEvent";
23
- import NativeAccessibilityInfoAndroid from "react-native/Libraries/Components/AccessibilityInfo/NativeAccessibilityInfo";
24
- import NativeAccessibilityManagerIOS from "react-native/Libraries/Components/AccessibilityInfo/NativeAccessibilityManager";
25
-
26
- // Events that are only supported on Android.
27
- type AccessibilityEventDefinitionsAndroid = {
28
- accessibilityServiceChanged: [boolean],
29
- };
30
-
31
- // Events that are only supported on iOS.
32
- type AccessibilityEventDefinitionsIOS = {
33
- announcementFinished: [{ announcement: string, success: boolean }],
34
- boldTextChanged: [boolean],
35
- grayscaleChanged: [boolean],
36
- invertColorsChanged: [boolean],
37
- reduceTransparencyChanged: [boolean],
38
- };
39
-
40
- type AccessibilityEventDefinitions = {
41
- ...AccessibilityEventDefinitionsAndroid,
42
- ...AccessibilityEventDefinitionsIOS,
43
- change: [boolean], // screenReaderChanged
44
- reduceMotionChanged: [boolean],
45
- screenReaderChanged: [boolean],
46
- };
47
-
48
- type AccessibilityEventTypes = "click" | "focus" | "viewHoverEnter";
49
-
50
- // Mapping of public event names to platform-specific event names.
51
- const EventNames: Map<
52
- $Keys<AccessibilityEventDefinitions>,
53
- string
54
- > = Platform.OS === "android"
55
- ? new Map([
56
- ["change", "touchExplorationDidChange"],
57
- ["reduceMotionChanged", "reduceMotionDidChange"],
58
- ["screenReaderChanged", "touchExplorationDidChange"],
59
- ["accessibilityServiceChanged", "accessibilityServiceDidChange"],
60
- ])
61
- : new Map([
62
- ["announcementFinished", "announcementFinished"],
63
- ["boldTextChanged", "boldTextChanged"],
64
- ["change", "screenReaderChanged"],
65
- ["grayscaleChanged", "grayscaleChanged"],
66
- ["invertColorsChanged", "invertColorsChanged"],
67
- ["reduceMotionChanged", "reduceMotionChanged"],
68
- ["reduceTransparencyChanged", "reduceTransparencyChanged"],
69
- ["screenReaderChanged", "screenReaderChanged"],
70
- ]);
71
-
72
- /**
73
- * Sometimes it's useful to know whether or not the device has a screen reader
74
- * that is currently active. The `AccessibilityInfo` API is designed for this
75
- * purpose. You can use it to query the current state of the screen reader as
76
- * well as to register to be notified when the state of the screen reader
77
- * changes.
78
- *
79
- * See https://reactnative.dev/docs/accessibilityinfo
80
- */
81
- const AccessibilityInfo = {
82
- /**
83
- * Query whether bold text is currently enabled.
84
- *
85
- * Returns a promise which resolves to a boolean.
86
- * The result is `true` when bold text is enabled and `false` otherwise.
87
- *
88
- * See https://reactnative.dev/docs/accessibilityinfo#isBoldTextEnabled
89
- */
90
- isBoldTextEnabled(): Promise<boolean> {
91
- if (Platform.OS === "android") {
92
- return Promise.resolve(false);
93
- } else {
94
- return new Promise((resolve, reject) => {
95
- if (NativeAccessibilityManagerIOS != null) {
96
- NativeAccessibilityManagerIOS.getCurrentBoldTextState(
97
- resolve,
98
- reject
99
- );
100
- } else {
101
- reject(null);
102
- }
103
- });
104
- }
105
- },
106
-
107
- /**
108
- * Query whether grayscale is currently enabled.
109
- *
110
- * Returns a promise which resolves to a boolean.
111
- * The result is `true` when grayscale is enabled and `false` otherwise.
112
- *
113
- * See https://reactnative.dev/docs/accessibilityinfo#isGrayscaleEnabled
114
- */
115
- isGrayscaleEnabled(): Promise<boolean> {
116
- if (Platform.OS === "android") {
117
- return Promise.resolve(false);
118
- } else {
119
- return new Promise((resolve, reject) => {
120
- if (NativeAccessibilityManagerIOS != null) {
121
- NativeAccessibilityManagerIOS.getCurrentGrayscaleState(
122
- resolve,
123
- reject
124
- );
125
- } else {
126
- reject(null);
127
- }
128
- });
129
- }
130
- },
131
-
132
- /**
133
- * Query whether inverted colors are currently enabled.
134
- *
135
- * Returns a promise which resolves to a boolean.
136
- * The result is `true` when invert color is enabled and `false` otherwise.
137
- *
138
- * See https://reactnative.dev/docs/accessibilityinfo#isInvertColorsEnabled
139
- */
140
- isInvertColorsEnabled(): Promise<boolean> {
141
- if (Platform.OS === "android") {
142
- return Promise.resolve(false);
143
- } else {
144
- return new Promise((resolve, reject) => {
145
- if (NativeAccessibilityManagerIOS != null) {
146
- NativeAccessibilityManagerIOS.getCurrentInvertColorsState(
147
- resolve,
148
- reject
149
- );
150
- } else {
151
- reject(null);
152
- }
153
- });
154
- }
155
- },
156
-
157
- /**
158
- * Query whether reduced motion is currently enabled.
159
- *
160
- * Returns a promise which resolves to a boolean.
161
- * The result is `true` when a reduce motion is enabled and `false` otherwise.
162
- *
163
- * See https://reactnative.dev/docs/accessibilityinfo#isReduceMotionEnabled
164
- */
165
- isReduceMotionEnabled(): Promise<boolean> {
166
- return new Promise((resolve, reject) => {
167
- if (Platform.OS === "android") {
168
- if (NativeAccessibilityInfoAndroid != null) {
169
- NativeAccessibilityInfoAndroid.isReduceMotionEnabled(resolve);
170
- } else {
171
- reject(null);
172
- }
173
- } else {
174
- if (NativeAccessibilityManagerIOS != null) {
175
- NativeAccessibilityManagerIOS.getCurrentReduceMotionState(
176
- resolve,
177
- reject
178
- );
179
- } else {
180
- reject(null);
181
- }
182
- }
183
- });
184
- },
185
-
186
- /**
187
- * Query whether reduce motion and prefer cross-fade transitions settings are currently enabled.
188
- *
189
- * Returns a promise which resolves to a boolean.
190
- * The result is `true` when prefer cross-fade transitions is enabled and `false` otherwise.
191
- *
192
- * See https://reactnative.dev/docs/accessibilityinfo#prefersCrossFadeTransitions
193
- */
194
- prefersCrossFadeTransitions(): Promise<boolean> {
195
- return new Promise((resolve, reject) => {
196
- if (Platform.OS === "android") {
197
- return Promise.resolve(false);
198
- } else {
199
- if (
200
- NativeAccessibilityManagerIOS?.getCurrentPrefersCrossFadeTransitionsState !=
201
- null
202
- ) {
203
- NativeAccessibilityManagerIOS.getCurrentPrefersCrossFadeTransitionsState(
204
- resolve,
205
- reject
206
- );
207
- } else {
208
- reject(null);
209
- }
210
- }
211
- });
212
- },
213
-
214
- /**
215
- * Query whether reduced transparency is currently enabled.
216
- *
217
- * Returns a promise which resolves to a boolean.
218
- * The result is `true` when a reduce transparency is enabled and `false` otherwise.
219
- *
220
- * See https://reactnative.dev/docs/accessibilityinfo#isReduceTransparencyEnabled
221
- */
222
- isReduceTransparencyEnabled(): Promise<boolean> {
223
- if (Platform.OS === "android") {
224
- return Promise.resolve(false);
225
- } else {
226
- return new Promise((resolve, reject) => {
227
- if (NativeAccessibilityManagerIOS != null) {
228
- NativeAccessibilityManagerIOS.getCurrentReduceTransparencyState(
229
- resolve,
230
- reject
231
- );
232
- } else {
233
- reject(null);
234
- }
235
- });
236
- }
237
- },
238
-
239
- /**
240
- * Query whether a screen reader is currently enabled.
241
- *
242
- * Returns a promise which resolves to a boolean.
243
- * The result is `true` when a screen reader is enabled and `false` otherwise.
244
- *
245
- * See https://reactnative.dev/docs/accessibilityinfo#isScreenReaderEnabled
246
- */
247
- isScreenReaderEnabled(): Promise<boolean> {
248
- return new Promise((resolve, reject) => {
249
- // RNOH: path to support open harmony
250
- if (Platform.OS === "android" || Platform.OS === "harmony") {
251
- if (NativeAccessibilityInfoAndroid != null) {
252
- NativeAccessibilityInfoAndroid.isTouchExplorationEnabled(resolve);
253
- } else {
254
- reject(null);
255
- }
256
- } else {
257
- if (NativeAccessibilityManagerIOS != null) {
258
- NativeAccessibilityManagerIOS.getCurrentVoiceOverState(
259
- resolve,
260
- reject
261
- );
262
- } else {
263
- reject(null);
264
- }
265
- }
266
- });
267
- },
268
-
269
- /**
270
- * Query whether Accessibility Service is currently enabled.
271
- *
272
- * Returns a promise which resolves to a boolean.
273
- * The result is `true` when any service is enabled and `false` otherwise.
274
- *
275
- * @platform android
276
- *
277
- * See https://reactnative.dev/docs/accessibilityinfo/#isaccessibilityserviceenabled-android
278
- */
279
- isAccessibilityServiceEnabled(): Promise<boolean> {
280
- return new Promise((resolve, reject) => {
281
- if (Platform.OS === "android") {
282
- if (
283
- NativeAccessibilityInfoAndroid != null &&
284
- NativeAccessibilityInfoAndroid.isAccessibilityServiceEnabled != null
285
- ) {
286
- NativeAccessibilityInfoAndroid.isAccessibilityServiceEnabled(resolve);
287
- } else {
288
- reject(null);
289
- }
290
- } else {
291
- reject(null);
292
- }
293
- });
294
- },
295
-
296
- /**
297
- * Add an event handler. Supported events:
298
- *
299
- * - `reduceMotionChanged`: Fires when the state of the reduce motion toggle changes.
300
- * The argument to the event handler is a boolean. The boolean is `true` when a reduce
301
- * motion is enabled (or when "Transition Animation Scale" in "Developer options" is
302
- * "Animation off") and `false` otherwise.
303
- * - `screenReaderChanged`: Fires when the state of the screen reader changes. The argument
304
- * to the event handler is a boolean. The boolean is `true` when a screen
305
- * reader is enabled and `false` otherwise.
306
- *
307
- * These events are only supported on iOS:
308
- *
309
- * - `boldTextChanged`: iOS-only event. Fires when the state of the bold text toggle changes.
310
- * The argument to the event handler is a boolean. The boolean is `true` when a bold text
311
- * is enabled and `false` otherwise.
312
- * - `grayscaleChanged`: iOS-only event. Fires when the state of the gray scale toggle changes.
313
- * The argument to the event handler is a boolean. The boolean is `true` when a gray scale
314
- * is enabled and `false` otherwise.
315
- * - `invertColorsChanged`: iOS-only event. Fires when the state of the invert colors toggle
316
- * changes. The argument to the event handler is a boolean. The boolean is `true` when a invert
317
- * colors is enabled and `false` otherwise.
318
- * - `reduceTransparencyChanged`: iOS-only event. Fires when the state of the reduce transparency
319
- * toggle changes. The argument to the event handler is a boolean. The boolean is `true`
320
- * when a reduce transparency is enabled and `false` otherwise.
321
- * - `announcementFinished`: iOS-only event. Fires when the screen reader has
322
- * finished making an announcement. The argument to the event handler is a
323
- * dictionary with these keys:
324
- * - `announcement`: The string announced by the screen reader.
325
- * - `success`: A boolean indicating whether the announcement was
326
- * successfully made.
327
- *
328
- * See https://reactnative.dev/docs/accessibilityinfo#addeventlistener
329
- */
330
- addEventListener<K: $Keys<AccessibilityEventDefinitions>>(
331
- eventName: K,
332
- // $FlowIssue[incompatible-type] - Flow bug with unions and generics (T128099423)
333
- handler: (...$ElementType<AccessibilityEventDefinitions, K>) => void
334
- ): EventSubscription {
335
- const deviceEventName = EventNames.get(eventName);
336
- return deviceEventName == null
337
- ? { remove(): void {} }
338
- : // $FlowFixMe[incompatible-call]
339
- RCTDeviceEventEmitter.addListener(deviceEventName, handler);
340
- },
341
-
342
- /**
343
- * Set accessibility focus to a React component.
344
- *
345
- * See https://reactnative.dev/docs/accessibilityinfo#setaccessibilityfocus
346
- */
347
- setAccessibilityFocus(reactTag: number): void {
348
- legacySendAccessibilityEvent(reactTag, "focus");
349
- },
350
-
351
- /**
352
- * Send a named accessibility event to a HostComponent.
353
- */
354
- sendAccessibilityEvent(
355
- handle: ElementRef<HostComponent<mixed>>,
356
- eventType: AccessibilityEventTypes
357
- ) {
358
- // iOS only supports 'focus' event types
359
- if (Platform.OS === "ios" && eventType === "click") {
360
- return;
361
- }
362
- // route through React renderer to distinguish between Fabric and non-Fabric handles
363
- sendAccessibilityEvent(handle, eventType);
364
- },
365
-
366
- /**
367
- * Post a string to be announced by the screen reader.
368
- *
369
- * See https://reactnative.dev/docs/accessibilityinfo#announceforaccessibility
370
- */
371
- announceForAccessibility(announcement: string): void {
372
- if (Platform.OS === "android") {
373
- NativeAccessibilityInfoAndroid?.announceForAccessibility(announcement);
374
- } else {
375
- NativeAccessibilityManagerIOS?.announceForAccessibility(announcement);
376
- }
377
- },
378
-
379
- /**
380
- * Post a string to be announced by the screen reader.
381
- * - `announcement`: The string announced by the screen reader.
382
- * - `options`: An object that configures the reading options.
383
- * - `queue`: The announcement will be queued behind existing announcements. iOS only.
384
- */
385
- announceForAccessibilityWithOptions(
386
- announcement: string,
387
- options: { queue?: boolean }
388
- ): void {
389
- if (Platform.OS === "android") {
390
- NativeAccessibilityInfoAndroid?.announceForAccessibility(announcement);
391
- } else {
392
- if (NativeAccessibilityManagerIOS?.announceForAccessibilityWithOptions) {
393
- NativeAccessibilityManagerIOS?.announceForAccessibilityWithOptions(
394
- announcement,
395
- options
396
- );
397
- } else {
398
- NativeAccessibilityManagerIOS?.announceForAccessibility(announcement);
399
- }
400
- }
401
- },
402
-
403
- /**
404
- * Get the recommended timeout for changes to the UI needed by this user.
405
- *
406
- * See https://reactnative.dev/docs/accessibilityinfo#getrecommendedtimeoutmillis
407
- */
408
- getRecommendedTimeoutMillis(originalTimeout: number): Promise<number> {
409
- if (Platform.OS === "android") {
410
- return new Promise((resolve, reject) => {
411
- if (NativeAccessibilityInfoAndroid?.getRecommendedTimeoutMillis) {
412
- NativeAccessibilityInfoAndroid.getRecommendedTimeoutMillis(
413
- originalTimeout,
414
- resolve
415
- );
416
- } else {
417
- resolve(originalTimeout);
418
- }
419
- });
420
- } else {
421
- return Promise.resolve(originalTimeout);
422
- }
423
- },
424
- };
425
-
426
- export default AccessibilityInfo;
1
+ /**
2
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ *
7
+ * @flow strict-local
8
+ * @format
9
+ */
10
+
11
+ // RNOH: patch
12
+ // COPIED FROM: https://github.com/facebook/react-native/blob/main/packages/react-native/Libraries/Components/AccessibilityInfo/AccessibilityInfo.js
13
+
14
+ import type { HostComponent } from "react-native/Libraries/Renderer/shims/ReactNativeTypes";
15
+ import type { EventSubscription } from "react-native/Libraries/vendor/emitter/EventEmitter";
16
+ import type { ElementRef } from "react";
17
+
18
+ // RNOH: patch - imports fixed
19
+ import RCTDeviceEventEmitter from "react-native/Libraries/EventEmitter/RCTDeviceEventEmitter";
20
+ import { sendAccessibilityEvent } from "react-native/Libraries/ReactNative/RendererProxy";
21
+ import Platform from "../../Utilities/Platform";
22
+ import legacySendAccessibilityEvent from "./legacySendAccessibilityEvent";
23
+ import NativeAccessibilityInfoAndroid from "react-native/Libraries/Components/AccessibilityInfo/NativeAccessibilityInfo";
24
+ import NativeAccessibilityManagerIOS from "react-native/Libraries/Components/AccessibilityInfo/NativeAccessibilityManager";
25
+ import NativeAccessibilityManagerHarmony from "./NativeAccessibilityManager";
26
+
27
+ // Events that are only supported on Android.
28
+ type AccessibilityEventDefinitionsAndroid = {
29
+ accessibilityServiceChanged: [boolean],
30
+ };
31
+
32
+ // Events that are only supported on iOS.
33
+ type AccessibilityEventDefinitionsIOS = {
34
+ announcementFinished: [{ announcement: string, success: boolean }],
35
+ boldTextChanged: [boolean],
36
+ grayscaleChanged: [boolean],
37
+ invertColorsChanged: [boolean],
38
+ reduceTransparencyChanged: [boolean],
39
+ };
40
+
41
+ type AccessibilityEventDefinitions = {
42
+ ...AccessibilityEventDefinitionsAndroid,
43
+ ...AccessibilityEventDefinitionsIOS,
44
+ change: [boolean], // screenReaderChanged
45
+ reduceMotionChanged: [boolean],
46
+ screenReaderChanged: [boolean],
47
+ };
48
+
49
+ type AccessibilityEventTypes = "click" | "focus" | "viewHoverEnter";
50
+
51
+ // Mapping of public event names to platform-specific event names.
52
+ const EventNames: Map<
53
+ $Keys<AccessibilityEventDefinitions>,
54
+ string
55
+ > = Platform.OS === "android"
56
+ ? new Map([
57
+ ["change", "touchExplorationDidChange"],
58
+ ["reduceMotionChanged", "reduceMotionDidChange"],
59
+ ["screenReaderChanged", "touchExplorationDidChange"],
60
+ ["accessibilityServiceChanged", "accessibilityServiceDidChange"],
61
+ ])
62
+ : (Platform.OS === "harmony" ?
63
+ new Map([
64
+ ["accessibilityServiceChanged", "accessibilityServiceChanged"],
65
+ ])
66
+ : new Map([
67
+ ["announcementFinished", "announcementFinished"],
68
+ ["boldTextChanged", "boldTextChanged"],
69
+ ["change", "screenReaderChanged"],
70
+ ["grayscaleChanged", "grayscaleChanged"],
71
+ ["invertColorsChanged", "invertColorsChanged"],
72
+ ["reduceMotionChanged", "reduceMotionChanged"],
73
+ ["reduceTransparencyChanged", "reduceTransparencyChanged"],
74
+ ["screenReaderChanged", "screenReaderChanged"],
75
+ ]));
76
+
77
+ /**
78
+ * Sometimes it's useful to know whether or not the device has a screen reader
79
+ * that is currently active. The `AccessibilityInfo` API is designed for this
80
+ * purpose. You can use it to query the current state of the screen reader as
81
+ * well as to register to be notified when the state of the screen reader
82
+ * changes.
83
+ *
84
+ * See https://reactnative.dev/docs/accessibilityinfo
85
+ */
86
+ const AccessibilityInfo = {
87
+ /**
88
+ * Query whether bold text is currently enabled.
89
+ *
90
+ * Returns a promise which resolves to a boolean.
91
+ * The result is `true` when bold text is enabled and `false` otherwise.
92
+ *
93
+ * See https://reactnative.dev/docs/accessibilityinfo#isBoldTextEnabled
94
+ */
95
+ isBoldTextEnabled(): Promise<boolean> {
96
+ if (Platform.OS === "android") {
97
+ return Promise.resolve(false);
98
+ } else {
99
+ return new Promise((resolve, reject) => {
100
+ if (NativeAccessibilityManagerIOS != null) {
101
+ NativeAccessibilityManagerIOS.getCurrentBoldTextState(
102
+ resolve,
103
+ reject
104
+ );
105
+ } else {
106
+ reject(null);
107
+ }
108
+ });
109
+ }
110
+ },
111
+
112
+ /**
113
+ * Query whether grayscale is currently enabled.
114
+ *
115
+ * Returns a promise which resolves to a boolean.
116
+ * The result is `true` when grayscale is enabled and `false` otherwise.
117
+ *
118
+ * See https://reactnative.dev/docs/accessibilityinfo#isGrayscaleEnabled
119
+ */
120
+ isGrayscaleEnabled(): Promise<boolean> {
121
+ if (Platform.OS === "android") {
122
+ return Promise.resolve(false);
123
+ } else {
124
+ return new Promise((resolve, reject) => {
125
+ if (NativeAccessibilityManagerIOS != null) {
126
+ NativeAccessibilityManagerIOS.getCurrentGrayscaleState(
127
+ resolve,
128
+ reject
129
+ );
130
+ } else {
131
+ reject(null);
132
+ }
133
+ });
134
+ }
135
+ },
136
+
137
+ /**
138
+ * Query whether inverted colors are currently enabled.
139
+ *
140
+ * Returns a promise which resolves to a boolean.
141
+ * The result is `true` when invert color is enabled and `false` otherwise.
142
+ *
143
+ * See https://reactnative.dev/docs/accessibilityinfo#isInvertColorsEnabled
144
+ */
145
+ isInvertColorsEnabled(): Promise<boolean> {
146
+ if (Platform.OS === "android") {
147
+ return Promise.resolve(false);
148
+ } else {
149
+ return new Promise((resolve, reject) => {
150
+ if (NativeAccessibilityManagerIOS != null) {
151
+ NativeAccessibilityManagerIOS.getCurrentInvertColorsState(
152
+ resolve,
153
+ reject
154
+ );
155
+ } else {
156
+ reject(null);
157
+ }
158
+ });
159
+ }
160
+ },
161
+
162
+ /**
163
+ * Query whether reduced motion is currently enabled.
164
+ *
165
+ * Returns a promise which resolves to a boolean.
166
+ * The result is `true` when a reduce motion is enabled and `false` otherwise.
167
+ *
168
+ * See https://reactnative.dev/docs/accessibilityinfo#isReduceMotionEnabled
169
+ */
170
+ isReduceMotionEnabled(): Promise<boolean> {
171
+ return new Promise((resolve, reject) => {
172
+ if (Platform.OS === "android") {
173
+ if (NativeAccessibilityInfoAndroid != null) {
174
+ NativeAccessibilityInfoAndroid.isReduceMotionEnabled(resolve);
175
+ } else {
176
+ reject(null);
177
+ }
178
+ } else {
179
+ if (NativeAccessibilityManagerIOS != null) {
180
+ NativeAccessibilityManagerIOS.getCurrentReduceMotionState(
181
+ resolve,
182
+ reject
183
+ );
184
+ } else {
185
+ reject(null);
186
+ }
187
+ }
188
+ });
189
+ },
190
+
191
+ /**
192
+ * Query whether reduce motion and prefer cross-fade transitions settings are currently enabled.
193
+ *
194
+ * Returns a promise which resolves to a boolean.
195
+ * The result is `true` when prefer cross-fade transitions is enabled and `false` otherwise.
196
+ *
197
+ * See https://reactnative.dev/docs/accessibilityinfo#prefersCrossFadeTransitions
198
+ */
199
+ prefersCrossFadeTransitions(): Promise<boolean> {
200
+ return new Promise((resolve, reject) => {
201
+ if (Platform.OS === "android") {
202
+ return Promise.resolve(false);
203
+ } else {
204
+ if (
205
+ NativeAccessibilityManagerIOS?.getCurrentPrefersCrossFadeTransitionsState !=
206
+ null
207
+ ) {
208
+ NativeAccessibilityManagerIOS.getCurrentPrefersCrossFadeTransitionsState(
209
+ resolve,
210
+ reject
211
+ );
212
+ } else {
213
+ reject(null);
214
+ }
215
+ }
216
+ });
217
+ },
218
+
219
+ /**
220
+ * Query whether reduced transparency is currently enabled.
221
+ *
222
+ * Returns a promise which resolves to a boolean.
223
+ * The result is `true` when a reduce transparency is enabled and `false` otherwise.
224
+ *
225
+ * See https://reactnative.dev/docs/accessibilityinfo#isReduceTransparencyEnabled
226
+ */
227
+ isReduceTransparencyEnabled(): Promise<boolean> {
228
+ if (Platform.OS === "android") {
229
+ return Promise.resolve(false);
230
+ } else {
231
+ return new Promise((resolve, reject) => {
232
+ if (NativeAccessibilityManagerIOS != null) {
233
+ NativeAccessibilityManagerIOS.getCurrentReduceTransparencyState(
234
+ resolve,
235
+ reject
236
+ );
237
+ } else {
238
+ reject(null);
239
+ }
240
+ });
241
+ }
242
+ },
243
+
244
+ /**
245
+ * Query whether a screen reader is currently enabled.
246
+ *
247
+ * Returns a promise which resolves to a boolean.
248
+ * The result is `true` when a screen reader is enabled and `false` otherwise.
249
+ *
250
+ * See https://reactnative.dev/docs/accessibilityinfo#isScreenReaderEnabled
251
+ */
252
+ isScreenReaderEnabled(): Promise<boolean> {
253
+ return new Promise((resolve, reject) => {
254
+ // RNOH: path to support open harmony
255
+ if (Platform.OS === "harmony"){
256
+ if (NativeAccessibilityManagerHarmony != null) {
257
+ NativeAccessibilityManagerHarmony.isTouchExplorationEnabled(resolve);
258
+ } else {
259
+ reject(null);
260
+ }
261
+ } else if (Platform.OS === "android" ) {
262
+ if (NativeAccessibilityInfoAndroid != null) {
263
+ NativeAccessibilityInfoAndroid.isTouchExplorationEnabled(resolve);
264
+ } else {
265
+ reject(null);
266
+ }
267
+ } else {
268
+ if (NativeAccessibilityManagerIOS != null) {
269
+ NativeAccessibilityManagerIOS.getCurrentVoiceOverState(
270
+ resolve,
271
+ reject
272
+ );
273
+ } else {
274
+ reject(null);
275
+ }
276
+ }
277
+ });
278
+ },
279
+
280
+ /**
281
+ * Query whether Accessibility Service is currently enabled.
282
+ *
283
+ * Returns a promise which resolves to a boolean.
284
+ * The result is `true` when any service is enabled and `false` otherwise.
285
+ *
286
+ * @platform android
287
+ *
288
+ * See https://reactnative.dev/docs/accessibilityinfo/#isaccessibilityserviceenabled-android
289
+ */
290
+ isAccessibilityServiceEnabled(): Promise<boolean> {
291
+ return new Promise((resolve, reject) => {
292
+ if (Platform.OS === "harmony") {
293
+ if (NativeAccessibilityInfoHarmony != null) {
294
+ NativeAccessibilityInfoHarmony.isAccessibilityServiceEnabled(resolve);
295
+ } else {
296
+ reject(null);
297
+ }
298
+ } else if (Platform.OS === "android") {
299
+ if (
300
+ NativeAccessibilityInfoAndroid != null &&
301
+ NativeAccessibilityInfoAndroid.isAccessibilityServiceEnabled != null
302
+ ) {
303
+ NativeAccessibilityInfoAndroid.isAccessibilityServiceEnabled(resolve);
304
+ } else {
305
+ reject(null);
306
+ }
307
+ } else {
308
+ reject(null);
309
+ }
310
+ });
311
+ },
312
+
313
+ /**
314
+ * Add an event handler. Supported events:
315
+ *
316
+ * - `reduceMotionChanged`: Fires when the state of the reduce motion toggle changes.
317
+ * The argument to the event handler is a boolean. The boolean is `true` when a reduce
318
+ * motion is enabled (or when "Transition Animation Scale" in "Developer options" is
319
+ * "Animation off") and `false` otherwise.
320
+ * - `screenReaderChanged`: Fires when the state of the screen reader changes. The argument
321
+ * to the event handler is a boolean. The boolean is `true` when a screen
322
+ * reader is enabled and `false` otherwise.
323
+ *
324
+ * These events are only supported on iOS:
325
+ *
326
+ * - `boldTextChanged`: iOS-only event. Fires when the state of the bold text toggle changes.
327
+ * The argument to the event handler is a boolean. The boolean is `true` when a bold text
328
+ * is enabled and `false` otherwise.
329
+ * - `grayscaleChanged`: iOS-only event. Fires when the state of the gray scale toggle changes.
330
+ * The argument to the event handler is a boolean. The boolean is `true` when a gray scale
331
+ * is enabled and `false` otherwise.
332
+ * - `invertColorsChanged`: iOS-only event. Fires when the state of the invert colors toggle
333
+ * changes. The argument to the event handler is a boolean. The boolean is `true` when a invert
334
+ * colors is enabled and `false` otherwise.
335
+ * - `reduceTransparencyChanged`: iOS-only event. Fires when the state of the reduce transparency
336
+ * toggle changes. The argument to the event handler is a boolean. The boolean is `true`
337
+ * when a reduce transparency is enabled and `false` otherwise.
338
+ * - `announcementFinished`: iOS-only event. Fires when the screen reader has
339
+ * finished making an announcement. The argument to the event handler is a
340
+ * dictionary with these keys:
341
+ * - `announcement`: The string announced by the screen reader.
342
+ * - `success`: A boolean indicating whether the announcement was
343
+ * successfully made.
344
+ *
345
+ * See https://reactnative.dev/docs/accessibilityinfo#addeventlistener
346
+ */
347
+ addEventListener<K: $Keys<AccessibilityEventDefinitions>>(
348
+ eventName: K,
349
+ // $FlowIssue[incompatible-type] - Flow bug with unions and generics (T128099423)
350
+ handler: (...$ElementType<AccessibilityEventDefinitions, K>) => void
351
+ ): EventSubscription {
352
+ const deviceEventName = EventNames.get(eventName);
353
+ return deviceEventName == null
354
+ ? { remove(): void {} }
355
+ : // $FlowFixMe[incompatible-call]
356
+ RCTDeviceEventEmitter.addListener(deviceEventName, handler);
357
+ },
358
+
359
+ /**
360
+ * Set accessibility focus to a React component.
361
+ *
362
+ * See https://reactnative.dev/docs/accessibilityinfo#setaccessibilityfocus
363
+ */
364
+ setAccessibilityFocus(reactTag: number): void {
365
+ legacySendAccessibilityEvent(reactTag, "focus");
366
+ },
367
+
368
+ /**
369
+ * Send a named accessibility event to a HostComponent.
370
+ */
371
+ sendAccessibilityEvent(
372
+ handle: ElementRef<HostComponent<mixed>>,
373
+ eventType: AccessibilityEventTypes
374
+ ) {
375
+ // iOS only supports 'focus' event types
376
+ if (Platform.OS === "ios" && eventType === "click") {
377
+ return;
378
+ }
379
+ // route through React renderer to distinguish between Fabric and non-Fabric handles
380
+ sendAccessibilityEvent(handle, eventType);
381
+ },
382
+
383
+ /**
384
+ * Post a string to be announced by the screen reader.
385
+ *
386
+ * See https://reactnative.dev/docs/accessibilityinfo#announceforaccessibility
387
+ */
388
+ announceForAccessibility(announcement: string): void {
389
+ if(Platform.OS === "harmony") {
390
+ NativeAccessibilityManagerHarmony?.announceForAccessibility(announcement);
391
+ } else if (Platform.OS === "android") {
392
+ NativeAccessibilityInfoAndroid?.announceForAccessibility(announcement);
393
+ } else {
394
+ NativeAccessibilityManagerIOS?.announceForAccessibility(announcement);
395
+ }
396
+ },
397
+
398
+ /**
399
+ * Post a string to be announced by the screen reader.
400
+ * - `announcement`: The string announced by the screen reader.
401
+ * - `options`: An object that configures the reading options.
402
+ * - `queue`: The announcement will be queued behind existing announcements. iOS only.
403
+ */
404
+ announceForAccessibilityWithOptions(
405
+ announcement: string,
406
+ options: { queue?: boolean }
407
+ ): void {
408
+ if (Platform.OS === "android") {
409
+ NativeAccessibilityInfoAndroid?.announceForAccessibility(announcement);
410
+ } else {
411
+ if (NativeAccessibilityManagerIOS?.announceForAccessibilityWithOptions) {
412
+ NativeAccessibilityManagerIOS?.announceForAccessibilityWithOptions(
413
+ announcement,
414
+ options
415
+ );
416
+ } else {
417
+ NativeAccessibilityManagerIOS?.announceForAccessibility(announcement);
418
+ }
419
+ }
420
+ },
421
+
422
+ /**
423
+ * Get the recommended timeout for changes to the UI needed by this user.
424
+ *
425
+ * See https://reactnative.dev/docs/accessibilityinfo#getrecommendedtimeoutmillis
426
+ */
427
+ getRecommendedTimeoutMillis(originalTimeout: number): Promise<number> {
428
+ if (Platform.OS === "android") {
429
+ return new Promise((resolve, reject) => {
430
+ if (NativeAccessibilityInfoAndroid?.getRecommendedTimeoutMillis) {
431
+ NativeAccessibilityInfoAndroid.getRecommendedTimeoutMillis(
432
+ originalTimeout,
433
+ resolve
434
+ );
435
+ } else {
436
+ resolve(originalTimeout);
437
+ }
438
+ });
439
+ } else {
440
+ return Promise.resolve(originalTimeout);
441
+ }
442
+ },
443
+ };
444
+
445
+ export default AccessibilityInfo;