react-native-a11y
Version:
Improvements of a11y for ReactNative, this library improve work with reader and keyboard focus and reader in general.
69 lines • 3.41 kB
JavaScript
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); }
import { findNodeHandle, NativeEventEmitter } from "react-native";
import { KEYBOARD_STATUS_EVENT } from "./A11yModule.conts";
import * as RCA11yModule from "./RCA11yModule";
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 NativeEventEmitter(RCA11yModule.RCA11y);
const eventListener = eventEmitter.addListener(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 = 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 = 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 = findNodeHandle(tag.current);
if (!targetView) return;
const tags = views.map(view => 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;
}
}
export const A11yModule = new A11yModuleIOSImpl();
//# sourceMappingURL=A11yModule.ios.js.map