Skip to content

Commit 4255f9b

Browse files
huntiemeta-codesync[bot]
authored andcommitted
Fix missing and incorrect AccessibilityInfo types (#56708)
Summary: Pull Request resolved: #56708 **Context** Claude-driven audit of Flow source code vs existing public TypeScript API (manual). **Changes** Alignments to the `AccessibilityInfo` module for both the source Flow types and manual TS types: - **Flow**: Move `grayscaleChanged` and `invertColorsChanged` into shared `AccessibilityEventDefinitions` — both events are registered on both platforms in the `EventNames` map. - **TS**: Add missing event types (`accessibilityServiceChanged`, `announcementFinished`, `darkerSystemColorsChanged`, `highTextContrastChanged`, `windowStateChange`) and platform-specific JSDoc to `AccessibilityChangeEventName` members. Changelog: [General][Fixed] - Fix missing and incorrect types in `AccessibilityInfo` TypeScript definitions Reviewed By: christophpurrer Differential Revision: D104057500 fbshipit-source-id: d14795aee3d1b55b6c7c06268ae57ab95c8c97ae
1 parent 2a0f595 commit 4255f9b

4 files changed

Lines changed: 45 additions & 22 deletions

File tree

packages/react-native/Libraries/Components/AccessibilityInfo/AccessibilityInfo.d.ts

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,22 @@ import {HostInstance} from '../../../types/public/ReactNativeTypes';
1111
import {EmitterSubscription} from '../../vendor/emitter/EventEmitter';
1212

1313
type AccessibilityChangeEventName =
14-
| 'change' // deprecated, maps to screenReaderChanged
15-
| 'boldTextChanged' // iOS-only Event
16-
| 'grayscaleChanged' // iOS-only Event
17-
| 'invertColorsChanged' // iOS-only Event
14+
/** Android only */
15+
| 'accessibilityServiceChanged'
16+
/** iOS only */
17+
| 'boldTextChanged'
18+
/** @deprecated Maps to 'screenReaderChanged' */
19+
| 'change'
20+
/** iOS only */
21+
| 'darkerSystemColorsChanged'
22+
| 'grayscaleChanged'
23+
/** Android only */
24+
| 'highTextContrastChanged'
25+
| 'invertColorsChanged'
1826
| 'reduceMotionChanged'
19-
| 'highTextContrastChanged' // Android-only Event
20-
| 'darkerSystemColorsChanged' // iOS-only Event
21-
| 'screenReaderChanged'
22-
| 'reduceTransparencyChanged'; // iOS-only Event
27+
/** iOS only */
28+
| 'reduceTransparencyChanged'
29+
| 'screenReaderChanged';
2330

2431
type AccessibilityChangeEvent = boolean;
2532

@@ -38,7 +45,11 @@ type AccessibilityAnnouncementFinishedEventHandler = (
3845
event: AccessibilityAnnouncementFinishedEvent,
3946
) => void;
4047

41-
type AccessibilityEventTypes = 'click' | 'focus' | 'viewHoverEnter';
48+
type AccessibilityEventTypes =
49+
| 'click'
50+
| 'focus'
51+
| 'viewHoverEnter'
52+
| 'windowStateChange';
4253

4354
/**
4455
* @see https://reactnative.dev/docs/accessibilityinfo

packages/react-native/Libraries/Components/AccessibilityInfo/AccessibilityInfo.js

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -28,16 +28,16 @@ type AccessibilityEventDefinitionsAndroid = {
2828
type AccessibilityEventDefinitionsIOS = {
2929
announcementFinished: [{announcement: string, success: boolean}],
3030
boldTextChanged: [boolean],
31-
grayscaleChanged: [boolean],
32-
invertColorsChanged: [boolean],
33-
reduceTransparencyChanged: [boolean],
3431
darkerSystemColorsChanged: [boolean],
32+
reduceTransparencyChanged: [boolean],
3533
};
3634

3735
type AccessibilityEventDefinitions = {
3836
...AccessibilityEventDefinitionsAndroid,
3937
...AccessibilityEventDefinitionsIOS,
4038
change: [boolean], // screenReaderChanged
39+
grayscaleChanged: [boolean],
40+
invertColorsChanged: [boolean],
4141
reduceMotionChanged: [boolean],
4242
screenReaderChanged: [boolean],
4343
};
@@ -395,18 +395,18 @@ const AccessibilityInfo = {
395395
* - `screenReaderChanged`: Fires when the state of the screen reader changes. The argument
396396
* to the event handler is a boolean. The boolean is `true` when a screen
397397
* reader is enabled and `false` otherwise.
398+
* - `grayscaleChanged`: Fires when the state of the gray scale toggle changes.
399+
* The argument to the event handler is a boolean. The boolean is `true` when gray scale
400+
* is enabled and `false` otherwise.
401+
* - `invertColorsChanged`: Fires when the state of the invert colors toggle
402+
* changes. The argument to the event handler is a boolean. The boolean is `true` when invert
403+
* colors is enabled and `false` otherwise.
398404
*
399405
* These events are only supported on iOS:
400406
*
401407
* - `boldTextChanged`: iOS-only event. Fires when the state of the bold text toggle changes.
402408
* The argument to the event handler is a boolean. The boolean is `true` when a bold text
403409
* is enabled and `false` otherwise.
404-
* - `grayscaleChanged`: iOS-only event. Fires when the state of the gray scale toggle changes.
405-
* The argument to the event handler is a boolean. The boolean is `true` when a gray scale
406-
* is enabled and `false` otherwise.
407-
* - `invertColorsChanged`: iOS-only event. Fires when the state of the invert colors toggle
408-
* changes. The argument to the event handler is a boolean. The boolean is `true` when a invert
409-
* colors is enabled and `false` otherwise.
410410
* - `reduceTransparencyChanged`: iOS-only event. Fires when the state of the reduce transparency
411411
* toggle changes. The argument to the event handler is a boolean. The boolean is `true`
412412
* when a reduce transparency is enabled and `false` otherwise.

packages/react-native/ReactNativeApi.d.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* This source code is licensed under the MIT license found in the
55
* LICENSE file in the root directory of this source tree.
66
*
7-
* @generated SignedSource<<eeffa8d1c270f98debd70024251b4a1a>>
7+
* @generated SignedSource<<d6790c241d1bd46a735efba34eeb4742>>
88
*
99
* This file was generated by scripts/js-api/build-types/index.js.
1010
*/
@@ -1055,6 +1055,8 @@ declare type AccessibilityEventDefinitions =
10551055
AccessibilityEventDefinitionsAndroid &
10561056
AccessibilityEventDefinitionsIOS & {
10571057
change: [boolean]
1058+
grayscaleChanged: [boolean]
1059+
invertColorsChanged: [boolean]
10581060
reduceMotionChanged: [boolean]
10591061
screenReaderChanged: [boolean]
10601062
}
@@ -1071,8 +1073,6 @@ declare type AccessibilityEventDefinitionsIOS = {
10711073
]
10721074
boldTextChanged: [boolean]
10731075
darkerSystemColorsChanged: [boolean]
1074-
grayscaleChanged: [boolean]
1075-
invertColorsChanged: [boolean]
10761076
reduceTransparencyChanged: [boolean]
10771077
}
10781078
declare type AccessibilityEventTypes =
@@ -6052,7 +6052,7 @@ declare type WrapperComponentProvider = (
60526052
) => React.ComponentType<any>
60536053
export {
60546054
AccessibilityActionEvent, // 5c5928b9
6055-
AccessibilityInfo, // ccbcce2f
6055+
AccessibilityInfo, // 539eb4b3
60566056
AccessibilityProps, // 5a2836fc
60576057
AccessibilityRole, // f2f2e066
60586058
AccessibilityState, // b0c2b3f7

packages/react-native/types/__typetests__/index.tsx

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1493,6 +1493,9 @@ AccessibilityInfo.getRecommendedTimeoutMillis(5000).then(timeoutMiles =>
14931493
),
14941494
);
14951495

1496+
AccessibilityInfo.addEventListener('accessibilityServiceChanged', isEnabled =>
1497+
console.log(`AccessibilityInfo.accessibilityServiceChanged => ${isEnabled}`),
1498+
);
14961499
AccessibilityInfo.addEventListener(
14971500
'announcementFinished',
14981501
({announcement, success}) =>
@@ -1503,9 +1506,18 @@ AccessibilityInfo.addEventListener(
15031506
AccessibilityInfo.addEventListener('boldTextChanged', isEnabled =>
15041507
console.log(`AccessibilityInfo.isBoldTextEnabled => ${isEnabled}`),
15051508
);
1509+
AccessibilityInfo.addEventListener('change', isEnabled =>
1510+
console.log(`AccessibilityInfo.change => ${isEnabled}`),
1511+
);
1512+
AccessibilityInfo.addEventListener('darkerSystemColorsChanged', isEnabled =>
1513+
console.log(`AccessibilityInfo.darkerSystemColorsChanged => ${isEnabled}`),
1514+
);
15061515
AccessibilityInfo.addEventListener('grayscaleChanged', isEnabled =>
15071516
console.log(`AccessibilityInfo.isGrayscaleEnabled => ${isEnabled}`),
15081517
);
1518+
AccessibilityInfo.addEventListener('highTextContrastChanged', isEnabled =>
1519+
console.log(`AccessibilityInfo.highTextContrastChanged => ${isEnabled}`),
1520+
);
15091521
AccessibilityInfo.addEventListener('invertColorsChanged', isEnabled =>
15101522
console.log(`AccessibilityInfo.isInvertColorsEnabled => ${isEnabled}`),
15111523
);

0 commit comments

Comments
 (0)