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 * @format 8 */ 9 10import type * as React from 'react'; 11import {HostComponent} from '../../../types/public/ReactNativeTypes'; 12import {EmitterSubscription} from '../../vendor/emitter/EventEmitter'; 13 14type AccessibilityChangeEventName = 15 | 'change' // deprecated, maps to screenReaderChanged 16 | 'boldTextChanged' // iOS-only Event 17 | 'grayscaleChanged' // iOS-only Event 18 | 'invertColorsChanged' // iOS-only Event 19 | 'reduceMotionChanged' 20 | 'screenReaderChanged' 21 | 'reduceTransparencyChanged'; // iOS-only Event 22 23type AccessibilityChangeEvent = boolean; 24 25type AccessibilityChangeEventHandler = ( 26 event: AccessibilityChangeEvent, 27) => void; 28 29type AccessibilityAnnouncementEventName = 'announcementFinished'; // iOS-only Event 30 31type AccessibilityAnnouncementFinishedEvent = { 32 announcement: string; 33 success: boolean; 34}; 35 36type AccessibilityAnnouncementFinishedEventHandler = ( 37 event: AccessibilityAnnouncementFinishedEvent, 38) => void; 39 40type AccessibilityEventTypes = 'click' | 'focus'; 41 42/** 43 * @see https://reactnative.dev/docs/accessibilityinfo 44 */ 45export interface AccessibilityInfoStatic { 46 /** 47 * Query whether bold text is currently enabled. 48 * 49 * @platform ios 50 */ 51 isBoldTextEnabled: () => Promise<boolean>; 52 53 /** 54 * Query whether grayscale is currently enabled. 55 * 56 * @platform ios 57 */ 58 isGrayscaleEnabled: () => Promise<boolean>; 59 60 /** 61 * Query whether invert colors is currently enabled. 62 * 63 * @platform ios 64 */ 65 isInvertColorsEnabled: () => Promise<boolean>; 66 67 /** 68 * Query whether reduce motion is currently enabled. 69 */ 70 isReduceMotionEnabled: () => Promise<boolean>; 71 72 /** 73 * Query whether reduce motion and prefer cross-fade transitions settings are currently enabled. 74 * 75 * Returns a promise which resolves to a boolean. 76 * The result is `true` when prefer cross-fade transitions is enabled and `false` otherwise. 77 */ 78 prefersCrossFadeTransitions(): Promise<boolean>; 79 80 /** 81 * Query whether reduce transparency is currently enabled. 82 * 83 * @platform ios 84 */ 85 isReduceTransparencyEnabled: () => Promise<boolean>; 86 87 /** 88 * Query whether a screen reader is currently enabled. 89 */ 90 isScreenReaderEnabled: () => Promise<boolean>; 91 92 /** 93 * Query whether Accessibility Service is currently enabled. 94 * 95 * Returns a promise which resolves to a boolean. 96 * The result is `true` when any service is enabled and `false` otherwise. 97 * 98 * @platform android 99 */ 100 isAccessibilityServiceEnabled(): Promise<boolean>; 101 102 /** 103 * Add an event handler. Supported events: 104 * - announcementFinished: iOS-only event. Fires when the screen reader has finished making an announcement. 105 * The argument to the event handler is a dictionary with these keys: 106 * - announcement: The string announced by the screen reader. 107 * - success: A boolean indicating whether the announcement was successfully made. 108 * - AccessibilityEventName constants other than announcementFinished: Fires on accessibility feature change. 109 * The argument to the event handler is a boolean. 110 * The boolean is true when the related event's feature is enabled and false otherwise. 111 * 112 */ 113 addEventListener( 114 eventName: AccessibilityChangeEventName, 115 handler: AccessibilityChangeEventHandler, 116 ): EmitterSubscription; 117 addEventListener( 118 eventName: AccessibilityAnnouncementEventName, 119 handler: AccessibilityAnnouncementFinishedEventHandler, 120 ): EmitterSubscription; 121 122 /** 123 * Set accessibility focus to a react component. 124 */ 125 setAccessibilityFocus: (reactTag: number) => void; 126 127 /** 128 * Post a string to be announced by the screen reader. 129 */ 130 announceForAccessibility: (announcement: string) => void; 131 132 /** 133 * Post a string to be announced by the screen reader. 134 * - `announcement`: The string announced by the screen reader. 135 * - `options`: An object that configures the reading options. 136 * - `queue`: The announcement will be queued behind existing announcements. iOS only. 137 */ 138 announceForAccessibilityWithOptions( 139 announcement: string, 140 options: {queue?: boolean}, 141 ): void; 142 143 /** 144 * Gets the timeout in millisecond that the user needs. 145 * This value is set in "Time to take action (Accessibility timeout)" of "Accessibility" settings. 146 * 147 * @platform android 148 */ 149 getRecommendedTimeoutMillis: (originalTimeout: number) => Promise<number>; 150 sendAccessibilityEvent: ( 151 handle: React.ElementRef<HostComponent<unknown>>, 152 eventType: AccessibilityEventTypes, 153 ) => void; 154} 155 156export const AccessibilityInfo: AccessibilityInfoStatic; 157export type AccessibilityInfo = AccessibilityInfoStatic; 158