UNPKG

react-native-a11y

Version:

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

67 lines (66 loc) 3.06 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.A11yModule = void 0; var _reactNative = require("react-native"); var _A11yModule = require("./A11yModule.conts"); var RCA11yModule = _interopRequireWildcard(require("./RCA11yModule")); function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function (e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (const t in e) "default" !== t && {}.hasOwnProperty.call(e, t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, t)) && (i.get || i.set) ? o(f, t, i) : f[t] = e[t]); return f; })(e, t); } const GC_FRAMEWORK_LINKING_ERROR = `GC_FRAMEWORK_LINKING_ERROR`; class A11yModuleIOSImpl { isKeyboardConnected = () => RCA11yModule.isKeyboardConnected().catch(e => { if (e.code === GC_FRAMEWORK_LINKING_ERROR) { console.error(e.message); } return true; }); keyboardStatusListener = callback => { const eventEmitter = new _reactNative.NativeEventEmitter(RCA11yModule.RCA11y); const eventListener = eventEmitter.addListener(_A11yModule.KEYBOARD_STATUS_EVENT, callback); return () => eventListener.remove(); }; announceForAccessibility = announcement => { RCA11yModule.announceForAccessibility(announcement); }; announceScreenChange = announcement => { RCA11yModule.announceScreenChange(announcement); }; setA11yFocus = ref => { const tag = (0, _reactNative.findNodeHandle)(ref.current); if (tag) { RCA11yModule.setAccessibilityFocus(tag); } }; setPreferredKeyboardFocus = (tag, targetTag) => { if (Number.isInteger(tag) && Number.isInteger(targetTag)) { RCA11yModule.setPreferredKeyboardFocus(tag, targetTag); } }; setKeyboardFocus = ref => { const tag = (0, _reactNative.findNodeHandle)(ref.current); if (tag && Number.isInteger(tag)) { RCA11yModule.setKeyboardFocus(tag); } }; focusFirstInteractiveElement = refToFocus => { if (refToFocus && refToFocus !== null && refToFocus !== void 0 && refToFocus.current) { this.setA11yFocus(refToFocus); } else { this.announceScreenChange(''); } }; setA11yElementsOrder = ({ tag, views }) => { var _RCA11yModule$setA11y; if (!tag) return; const targetView = (0, _reactNative.findNodeHandle)(tag.current); if (!targetView) return; const tags = views.map(view => (0, _reactNative.findNodeHandle)(view)).filter(view => Boolean(view)); RCA11yModule === null || RCA11yModule === void 0 || (_RCA11yModule$setA11y = RCA11yModule.setA11yOrder) === null || _RCA11yModule$setA11y === void 0 || _RCA11yModule$setA11y.call(RCA11yModule, tags, targetView); }; } const A11yModule = exports.A11yModule = new A11yModuleIOSImpl(); //# sourceMappingURL=A11yModule.ios.js.map