跳至主内容

无障碍信息

非官方测试版翻译

本页面由 PageTurner AI 翻译(测试版)。未经项目官方认可。 发现错误? 报告问题 →

了解设备当前是否启用了屏幕阅读器有时非常有用。AccessibilityInfo API 正是为此设计。您可以用它查询屏幕阅读器的当前状态,并注册监听屏幕阅读器状态的变化通知。

示例


参考

方法

addEventListener()

tsx
static addEventListener(
eventName: AccessibilityChangeEventName | AccessibilityAnnouncementEventName,
handler: (
event: AccessibilityChangeEvent | AccessibilityAnnouncementFinishedEvent,
) => void,
): EmitterSubscription;

添加事件处理器。支持的事件类型:

Event nameDescription
accessibilityServiceChanged
Android
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.
announcementFinished
iOS
Fires when the screen reader has finished making an announcement. The argument to the event handler is a dictionary with these keys:
  • announcement: The string announced by the screen reader.
  • success: A boolean indicating whether the announcement was successfully made.
boldTextChanged
iOS
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.
grayscaleChanged
iOS
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.
invertColorsChanged
iOS
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.
reduceMotionChangedFires 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.
reduceTransparencyChanged
iOS
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.
screenReaderChangedFires 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()

tsx
static announceForAccessibility(announcement: string);

发送字符串供屏幕阅读器播报。


announceForAccessibilityWithOptions()

tsx
static announceForAccessibilityWithOptions(
announcement: string,
options: {queue?: boolean},
);

发送带配置选项的字符串供屏幕阅读器播报。默认情况下播报会中断当前语音,但在 iOS 平台可通过在配置对象中设置 queuetrue 将其加入现有语音队列。

参数:

NameTypeDescription
announcement
Required
stringThe string to be announced
options
Required
objectqueue - queue the announcement behind existing speech
iOS

getRecommendedTimeoutMillis()
Android

tsx
static getRecommendedTimeoutMillis(originalTimeout: number): Promise<number>;

获取用户需要的操作超时时间(毫秒)。 该值在系统"无障碍设置"的"操作等待时间(无障碍超时)"中设定。

参数:

NameTypeDescription
originalTimeout
Required
numberThe timeout to return if "Accessibility timeout" is not set. Specify in milliseconds.

isAccessibilityServiceEnabled()
Android

tsx
static isAccessibilityServiceEnabled(): Promise<boolean>;

检查是否启用了任何无障碍服务。这包括 TalkBack 以及可能安装的第三方无障碍应用。若只需检查 TalkBack 是否启用,请使用 isScreenReaderEnabled。返回一个 Promise,解析结果为布尔值:当有任何无障碍服务启用时为 true,否则为 false

备注

如果您只需要检查 TalkBack 的状态,请使用 isScreenReaderEnabled


isBoldTextEnabled()
iOS

tsx
static isBoldTextEnabled(): Promise<boolean>:

查询是否启用了粗体文本。返回一个 Promise,解析结果为布尔值:启用时为 true,否则为 false


isGrayscaleEnabled()
iOS

tsx
static isGrayscaleEnabled(): Promise<boolean>;

查询是否启用了灰度显示。返回一个 Promise,解析结果为布尔值:启用时为 true,否则为 false


isInvertColorsEnabled()
iOS

tsx
static isInvertColorsEnabled(): Promise<boolean>;

查询是否启用了颜色反转。返回一个 Promise,解析结果为布尔值:启用时为 true,否则为 false


isReduceMotionEnabled()

tsx
static isReduceMotionEnabled(): Promise<boolean>;

查询是否启用了减弱动画效果。返回一个 Promise,解析结果为布尔值:启用时为 true,否则为 false


isReduceTransparencyEnabled()
iOS

tsx
static isReduceTransparencyEnabled(): Promise<boolean>;

查询是否启用了降低透明度。返回一个 Promise,解析结果为布尔值:启用时为 true,否则为 false


isScreenReaderEnabled()

tsx
static isScreenReaderEnabled(): Promise<boolean>;

查询是否启用了屏幕阅读器。返回一个 Promise,解析结果为布尔值:启用时为 true,否则为 false


prefersCrossFadeTransitions()
iOS

tsx
static prefersCrossFadeTransitions(): Promise<boolean>;

查询是否同时启用了减弱动画效果和偏好淡入淡出过渡效果设置。返回一个 Promise,解析结果为布尔值:当偏好淡入淡出过渡效果启用时为 true,否则为 false


🗑️ setAccessibilityFocus()

已弃用

建议改用指定事件类型为 focussendAccessibilityEvent 方法。

tsx
static setAccessibilityFocus(reactTag: number);

将无障碍焦点设置到 React 组件。

在 Android 平台,该方法会调用 UIManager.sendAccessibilityEvent,并传入 reactTagUIManager.AccessibilityEventTypes.typeViewFocused 参数。

备注

请确保任何希望接收无障碍焦点的 View 都设置了 accessible={true}


sendAccessibilityEvent()

tsx
static sendAccessibilityEvent(host: HostInstance, eventType: AccessibilityEventTypes);

命令式地触发 React 组件上的无障碍事件,例如为屏幕阅读器改变焦点元素。

备注

请确保任何希望接收无障碍焦点的 View 都设置了 accessible={true}

NameTypeDescription
host
Required
HostInstanceThe component ref to send the event to.
eventType
Required
AccessibilityEventTypesOne of 'click' (Android only), 'focus', 'viewHoverEnter' (Android only), or 'windowStateChange' (Android only)