Files
discord-decomp/modules/a11y/native/useAnnounceAsyncCompletion.native.tsx
T
2026-11-01 12:12:55 +02:00

56 lines
1.6 KiB
TypeScript

// Metro module 10186 (f10187).
import { useRef, useEffect, useCallback } from "react";
import { AccessibilityInfo } from "react-native";
import { AccessibilityAnnouncer } from "../../../design/shared";
import { isIOS } from "../../../utils/PlatformUtils";
import { getIsScreenReaderEnabled } from "./useIsScreenReaderEnabled.native";
export default function useAnnounceAsyncCompletion() {
const ref = useRef(null);
useEffect(() => () => {
const current = ref.current;
if (current != null) {
current.call(ref);
}
ref.current = null;
}, []);
return useCallback(function(a0) {
let r26;
let c26630_0 = a0;
let r6 = arguments[1];
if (r6 === void 0) {
r6 = "assertive";
}
AccessibilityAnnouncer.announce(a0, r6);
if (isIOS() && getIsScreenReaderEnabled()) {
const current = ref.current;
if (current != null) {
current.call(ref);
}
r26 = new Promise((c30202_0) => {
let c30202_2;
let c30202_1 = setTimeout(() => {
const current = ref.current;
return current == null ? void 0 : current.call(ref);
}, 1800);
c30202_2 = AccessibilityInfo.addEventListener("announcementFinished", (a0) => {
if (a0.announcement === c26630_0 && a0.success) {
const current = ref.current;
if (current != null) {
current.call(ref);
}
}
});
ref.current = () => {
clearTimeout(c30202_1);
c30202_2.remove();
ref.current = null;
c30202_0();
};
});
} else {
r26 = Promise.resolve();
}
return r26;
}, []);
};