AccessibilityInfo
有时候我们希望知道用户的设备是否正在运行读屏应用。AccessibilityInfo
正是用于此目的。你可以用它来查询读屏应用的当前状态,并且可以监听其状态变化。
示例
- 函数式组件
- Class 组件
文档
方法
isBoldTextEnabled()
static isBoldTextEnabled()
iOS-Only. Query whether a bold text is currently enabled. Returns a promise which resolves to a boolean. The result is true
when bold text is enabled and false
otherwise.
isGrayscaleEnabled()
static isGrayscaleEnabled()
iOS-Only. Query whether grayscale is currently enabled. Returns a promise which resolves to a boolean. The result is true
when grayscale is enabled and false
otherwise.
isInvertColorsEnabled()
static isInvertColorsEnabled()
iOS-Only. Query whether invert colors is currently enabled. Returns a promise which resolves to a boolean. The result is true
when invert colors is enabled and false
otherwise.
isReduceMotionEnabled()
static isReduceMotionEnabled()
Query whether reduce motion is currently enabled. Returns a promise which resolves to a boolean. The result is true
when reduce motion is enabled and false
otherwise.
isReduceTransparencyEnabled()
static isReduceTransparencyEnabled()
iOS-Only. Query whether reduce transparency is currently enabled. Returns a promise which resolves to a boolean. The result is true
when a reduce transparency is enabled and false
otherwise.
isScreenReaderEnabled()
static isScreenReaderEnabled()
查询读屏应用当前是否开启。返回值为一个 promise,最终解析值为一个布尔值。true
表示开启状态,false
反之。
addEventListener()
static addEventListener(eventName, handler)
添加一个监听函数,支持的事件类型如下:
boldTextChanged
: iOS-only event. Fires when the state of the bold text toggle changes. The argument to the event handler is a boolean. The boolean istrue
when bold text is enabled andfalse
otherwise.grayscaleChanged
: iOS-only event. Fires when the state of the gray scale toggle changes. The argument to the event handler is a boolean. The boolean istrue
when a gray scale is enabled andfalse
otherwise.invertColorsChanged
: iOS-only event. Fires when the state of the invert colors toggle changes. The argument to the event handler is a boolean. The boolean istrue
when invert colors is enabled andfalse
otherwise.reduceMotionChanged
: Fires when the state of the reduce motion toggle changes. The argument to the event handler is a boolean. The boolean istrue
when a reduce motion is enabled (or when "Transition Animation Scale" in "Developer options" is "Animation off") andfalse
otherwise.screenReaderChanged
: 读屏应用状态改变时触发。传递给监听函数的参数为布尔值,true
表示开启状态,false
反之。reduceTransparencyChanged
: iOS-only event. Fires when the state of the reduce transparency toggle changes. The argument to the event handler is a boolean. The boolean istrue
when reduce transparency is enabled andfalse
otherwise.announcementFinished
: 仅 iOS 可用。在读屏软件完成一次朗读后触发。传递给监听函数的参数 为一个字典,包含以下两个字段:announcement
: 读屏软件所读的字符串。success
: 此次朗读是否成功完成。
setAccessibilityFocus()
static setAccessibilityFocus(reactTag)
将读屏软件的焦点设置到某个 react 组件上。在 Android 等同于调用 UIManager.sendAccessibilityEvent(reactTag, UIManager.AccessibilityEventTypes.typeViewFocused);
.
Note: Make sure that any
View
you want to receive the accessibility focus hasaccessible={true}
.
announceForAccessibility()
static announceForAccessibility(announcement)
发送一个字符串给读屏应用朗读。
removeEventListener()
static removeEventListener(eventName, handler)
移除一个监听函数。