react-native-a11y
Version:
Improvements of a11y for ReactNative, this library improve work with reader and keyboard focus and reader in general.
76 lines (75 loc) • 4.24 kB
JavaScript
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); }
function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : i + ""; }
function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
const GC_FRAMEWORK_LINKING_ERROR = `GC_FRAMEWORK_LINKING_ERROR`;
class A11yModuleIOSImpl {
constructor() {
_defineProperty(this, "_currentFocusedTag", null);
_defineProperty(this, "isKeyboardConnected", () => RCA11yModule.isKeyboardConnected().catch(e => {
if (e.code === GC_FRAMEWORK_LINKING_ERROR) {
console.error(e.message);
}
return true;
}));
_defineProperty(this, "keyboardStatusListener", callback => {
const eventEmitter = new _reactNative.NativeEventEmitter(RCA11yModule.RCA11y);
const eventListener = eventEmitter.addListener(_A11yModule.KEYBOARD_STATUS_EVENT, callback);
return () => eventListener.remove();
});
_defineProperty(this, "announceForAccessibility", announcement => {
RCA11yModule.announceForAccessibility(announcement);
});
_defineProperty(this, "announceScreenChange", announcement => {
RCA11yModule.announceScreenChange(announcement);
});
_defineProperty(this, "setA11yFocus", ref => {
const tag = (0, _reactNative.findNodeHandle)(ref.current);
if (tag) {
RCA11yModule.setAccessibilityFocus(tag);
}
});
_defineProperty(this, "setPreferredKeyboardFocus", (tag, targetTag) => {
if (Number.isInteger(tag) && Number.isInteger(targetTag)) {
RCA11yModule.setPreferredKeyboardFocus(tag, targetTag);
}
});
_defineProperty(this, "setKeyboardFocus", ref => {
const tag = (0, _reactNative.findNodeHandle)(ref.current);
if (this._currentFocusedTag && tag && Number.isInteger(this._currentFocusedTag) && Number.isInteger(tag)) {
RCA11yModule.setKeyboardFocus(this._currentFocusedTag, tag);
}
});
_defineProperty(this, "focusFirstInteractiveElement", refToFocus => {
if (refToFocus && refToFocus !== null && refToFocus !== void 0 && refToFocus.current) {
this.setA11yFocus(refToFocus);
} else {
this.announceScreenChange("");
}
});
_defineProperty(this, "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);
});
}
set currentFocusedTag(value) {
this._currentFocusedTag = value;
}
}
const A11yModule = exports.A11yModule = new A11yModuleIOSImpl();
//# sourceMappingURL=A11yModule.ios.js.map
;