85 lines
3.1 KiB
TypeScript
85 lines
3.1 KiB
TypeScript
// Metro module 4585 (f4586).
|
|
import { NativeModules } from "react-native";
|
|
import Logger from "../../debug/Logger";
|
|
import LifecycleManager from "../../../lib/LifecycleManager";
|
|
import { getIsScreenReaderEnabled, addScreenReaderEnabledListener } from "./useIsScreenReaderEnabled.native";
|
|
import { isAndroid } from "../../../utils/PlatformUtils";
|
|
import Module4587 from "../../../_bundle/Module4587";
|
|
let c2792_4 = new Logger("AccessibilityFocusLockManager");
|
|
class AccessibilityFocusLockManager extends LifecycleManager {
|
|
_screenReaderEnabled = getIsScreenReaderEnabled();
|
|
_focusLockedNativeIDGroups = new Map();
|
|
_focusLockEnabled = false;
|
|
_focusLockEnabledDelayTimeoutId = -1;
|
|
_focusLockEnabledDelayTimeout = 250;
|
|
_updateAccessibilityFocusLock(r3 = false) {
|
|
let c14333_1;
|
|
let c14333_0 = r3;
|
|
let r4 = void 0;
|
|
c14333_1 = void 0;
|
|
clearTimeout(this._focusLockEnabledDelayTimeoutId);
|
|
c14333_1 = void 0;
|
|
for (const item of this._focusLockedNativeIDGroups.values()) {
|
|
r4 = item;
|
|
c14333_1 = item;
|
|
}
|
|
if (r4 != null && this._screenReaderEnabled) {
|
|
this._focusLockEnabledDelayTimeoutId = setTimeout(() => {
|
|
if (isAndroid()) {
|
|
Module4587.enableFocusLock(c14333_1, c14333_0);
|
|
} else {
|
|
NativeModules.DCDAccessibilityManager.enableFocusLock(c14333_1, c14333_0);
|
|
}
|
|
}, this._focusLockEnabledDelayTimeout);
|
|
this._focusLockEnabled = true;
|
|
} else if (this._focusLockEnabled) {
|
|
if (isAndroid()) {
|
|
Module4587.disableFocusLock();
|
|
} else {
|
|
NativeModules.DCDAccessibilityManager.disableFocusLock();
|
|
}
|
|
this._focusLockEnabled = false;
|
|
}
|
|
}
|
|
_initialize() {
|
|
this._screenReaderEnabledListener = addScreenReaderEnabledListener((a0) => {
|
|
this._screenReaderEnabled = a0;
|
|
this._updateAccessibilityFocusLock();
|
|
});
|
|
}
|
|
_terminate() {
|
|
const _screenReaderEnabledListener = this._screenReaderEnabledListener;
|
|
if (_screenReaderEnabledListener != null) {
|
|
_screenReaderEnabledListener.call(this);
|
|
}
|
|
this._focusLockedNativeIDGroups.clear();
|
|
this._updateAccessibilityFocusLock();
|
|
}
|
|
enableAccessibilityFocusLock(a0) {
|
|
if (a0.length === 0) {
|
|
c2792_4.error("No target view nativeIDs to add.");
|
|
}
|
|
for (const item of this._focusLockedNativeIDGroups.values()) {
|
|
for (const item2 of item) {
|
|
if (a0.includes(item2)) {
|
|
c2792_4.error(`Duplicate target view nativeID ${item2} already accessibility focus locked.`);
|
|
}
|
|
}
|
|
}
|
|
this._focusLockedNativeIDGroups.set(a0[0], a0);
|
|
this._updateAccessibilityFocusLock(true);
|
|
}
|
|
disableAccessibilityFocusLock(a0) {
|
|
if (a0.length === 0) {
|
|
c2792_4.error("No target view nativeIDs to remove.");
|
|
}
|
|
if (!this._focusLockedNativeIDGroups.has(a0[0])) {
|
|
c2792_4.error(`No target view nativeID ${a0[0]} accessibility focus locked.`);
|
|
}
|
|
this._focusLockedNativeIDGroups.delete(a0[0]);
|
|
this._updateAccessibilityFocusLock();
|
|
}
|
|
}
|
|
const accessibilityFocusLockManager = new AccessibilityFocusLockManager();
|
|
export default accessibilityFocusLockManager;
|