UNPKG

react-native-a11y

Version:

Improvements of a11y for ReactNative, this library improve work with reader and keyboard focus and reader in general.

49 lines 2.56 kB
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; } function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); } function _toPrimitive(input, hint) { if (typeof input !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (typeof res !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); } import { AccessibilityInfo, findNodeHandle, InteractionManager, NativeEventEmitter } from "react-native"; import { noop } from "../../utils"; import { KEYBOARD_STATUS_EVENT } from "./A11yModule.conts"; import * as RCA11yModule from "./RCA11yModule"; class A11yAndroidImpl { constructor() { _defineProperty(this, "isKeyboardConnected", RCA11yModule.isKeyboardConnected); _defineProperty(this, "keyboardStatusListener", callback => { const eventEmitter = new NativeEventEmitter(); const eventListener = eventEmitter.addListener(KEYBOARD_STATUS_EVENT, callback); return () => eventListener.remove(); }); _defineProperty(this, "focusFirstInteractiveElement", this.setA11yFocus); _defineProperty(this, "setPreferredKeyboardFocus", noop); _defineProperty(this, "setA11yElementsOrder", _ref => { var _RCA11yModule$setA11y; let { views } = _ref; const tags = views.map(view => findNodeHandle(view)).filter(view => Boolean(view)); (_RCA11yModule$setA11y = RCA11yModule.setA11yOrder) === null || _RCA11yModule$setA11y === void 0 ? void 0 : _RCA11yModule$setA11y.call(RCA11yModule, tags, 0); }); } announceForAccessibility(announcement) { AccessibilityInfo.announceForAccessibility(announcement); } setKeyboardFocus(ref) { const tag = findNodeHandle(ref.current); if (tag) { InteractionManager.runAfterInteractions(() => { RCA11yModule.setKeyboardFocus(tag); }); } } announceScreenChange(announcement) { RCA11yModule.announceScreenChange(announcement); } setA11yFocus(ref) { const tag = findNodeHandle(ref.current); if (tag) { AccessibilityInfo.setAccessibilityFocus(tag); } } } export const A11yModule = new A11yAndroidImpl(); //# sourceMappingURL=A11yModule.android.js.map