无障碍信息
本页面由 PageTurner AI 翻译(测试版)。未经项目官方认可。 发现错误? 报告问题 →
了解设备当前是否启用了屏幕阅读器有时非常有用。AccessibilityInfo API 正是为此设计。您可以用它查询屏幕阅读器的当前状态,并注册监听屏幕阅读器状态的变化通知。
示例
参考
方法
addEventListener()
static addEventListener(
eventName: AccessibilityChangeEventName | AccessibilityAnnouncementEventName,
handler: (
event: AccessibilityChangeEvent | AccessibilityAnnouncementFinishedEvent,
) => void,
): EmitterSubscription;
添加事件处理器。支持的事件类型:
| Event name | Description |
|---|---|
accessibilityServiceChangedAndroid | Fires when some services such as TalkBack, other Android assistive technologies, and third-party accessibility services are enabled. The argument to the event handler is a boolean. The boolean is true when a some accessibility services is enabled and false otherwise. |
announcementFinishediOS | Fires when the screen reader has finished making an announcement. The argument to the event handler is a dictionary with these keys:
|
boldTextChangediOS | 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. |
grayscaleChangediOS | 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. |
invertColorsChangediOS | 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. |
reduceTransparencyChangediOS | 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. |
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. |
announceForAccessibility()
static announceForAccessibility(announcement: string);
发送字符串供屏幕阅读器播报。
announceForAccessibilityWithOptions()
static announceForAccessibilityWithOptions(
announcement: string,
options: {queue?: boolean},
);
发送带配置选项的字符串供屏幕阅读器播报。默认情况下播报会中断当前语音,但在 iOS 平台可通过在配置对象中设置 queue 为 true 将其加入现有语音队列。
参数:
| Name | Type | Description |
|---|---|---|
| announcement Required | string | The string to be announced |
| options Required | object | queue - queue the announcement behind existing speech iOS |
getRecommendedTimeoutMillis() Android
static getRecommendedTimeoutMillis(originalTimeout: number): Promise<number>;
获取用户需要的操作超时时间(毫秒)。 该值在系统"无障碍设置"的"操作等待时间(无障碍超时)"中设定。
参数:
| Name | Type | Description |
|---|---|---|
| originalTimeout Required | number | The timeout to return if "Accessibility timeout" is not set. Specify in milliseconds. |
isAccessibilityServiceEnabled() Android
static isAccessibilityServiceEnabled(): Promise<boolean>;
检查是否启用了任何无障碍服务。这包括 TalkBack 以及可能安装的第三方无障碍应用。若只需检查 TalkBack 是否启用,请使用 isScreenReaderEnabled。返回一个 Promise,解析结果为布尔值:当有任何无障碍服务启用时为 true,否则为 false。
注意:若只需检查 TalkBack 状态,请使用 isScreenReaderEnabled。
isBoldTextEnabled() iOS
static isBoldTextEnabled(): Promise<boolean>:
查询是否启用了粗体文本。返回一个 Promise,解析结果为布尔值:启用时为 true,否则为 false。
isGrayscaleEnabled() iOS
static isGrayscaleEnabled(): Promise<boolean>;
查询是否启用了灰度显示。返回一个 Promise,解析结果为布尔值:启用时为 true,否则为 false。
isInvertColorsEnabled() iOS
static isInvertColorsEnabled(): Promise<boolean>;
查询是否启用了颜色反转。返回一个 Promise,解析结果为布尔值:启用时为 true,否则为 false。
isReduceMotionEnabled()
static isReduceMotionEnabled(): Promise<boolean>;
查询是否启用了减弱动画效果。返回一个 Promise,解析结果为布尔值:启用时为 true,否则为 false。
isReduceTransparencyEnabled() iOS
static isReduceTransparencyEnabled(): Promise<boolean>;
查询是否启用了降低透明度。返回一个 Promise,解析结果为布尔值:启用时为 true,否则为 false。
isScreenReaderEnabled()
static isScreenReaderEnabled(): Promise<boolean>;
查询是否启用了屏幕阅读器。返回一个 Promise,解析结果为布尔值:启用时为 true,否则为 false。
prefersCrossFadeTransitions() iOS
static prefersCrossFadeTransitions(): Promise<boolean>;
查询是否同时启用了减弱动画效果和偏好淡入淡出过渡效果设置。返回一个 Promise,解析结果为布尔值:当偏好淡入淡出过渡效果启用时为 true,否则为 false。
setAccessibilityFocus()
建议改用指定事件类型为 focus 的 sendAccessibilityEvent 方法。
static setAccessibilityFocus(reactTag: number);
将无障碍焦点设置到 React 组件。
在 Android 平台,该方法会调用 UIManager.sendAccessibilityEvent,并传入 reactTag 和 UIManager.AccessibilityEventTypes.typeViewFocused 参数。
请确保任何希望接收无障碍焦点的 View 都设置了 accessible={true}。
sendAccessibilityEvent()
static sendAccessibilityEvent(host: HostInstance, eventType: AccessibilityEventTypes);
命令式地触发 React 组件上的无障碍事件,例如为屏幕阅读器改变焦点元素。
请确保任何希望接收无障碍焦点的 View 都设置了 accessible={true}。
| Name | Type | Description |
|---|---|---|
| host Required | HostInstance | The component ref to send the event to. |
| eventType Required | AccessibilityEventTypes | One of 'click' (Android only), 'focus', 'viewHoverEnter' (Android only), or 'windowStateChange' (Android only) |