fix: keep toasts working where the accessibility bridge is missing

This commit is contained in:
Linus Rath
2026-10-31 04:52:44 +01:00
parent b943246373
commit 01dd7461f5
2 changed files with 11 additions and 2 deletions
+10 -1
View File
@@ -18,8 +18,17 @@ export interface AnnounceOptions {
assertive?: boolean;
}
function isIos(): boolean {
try {
return Platform.OS === 'ios';
} catch {
// A react-native stand-in without Platform (tests).
return false;
}
}
export function announce(message: string, options: AnnounceOptions = {}): void {
if (Platform.OS !== 'ios') return;
if (!isIos()) return;
const text = message.replace(/\s+/g, ' ').trim();
if (!text) return;
const now = Date.now();
+1 -1
View File
@@ -10,8 +10,8 @@ let watching = false;
function watch(): void {
if (watching) return;
watching = true;
const info = AccessibilityInfo as typeof AccessibilityInfo | undefined;
try {
const info = AccessibilityInfo as typeof AccessibilityInfo | undefined;
void info?.isScreenReaderEnabled?.().then((on) => { screenReaderOn = on; }).catch(() => undefined);
info?.addEventListener?.('screenReaderChanged', (on: boolean) => { screenReaderOn = on; });
} catch {