UNPKG

2.79 kBJavaScriptView Raw
1import { Application } from '../application';
2import { Observable } from '../data/observable';
3import { Trace } from '../trace';
4import { AccessibilityServiceEnabledPropName, CommonA11YServiceEnabledObservable, SharedA11YObservable } from './accessibility-service-common';
5export function isAccessibilityServiceEnabled() {
6 return getSharedA11YObservable().accessibilityServiceEnabled;
7}
8export function getAndroidAccessibilityManager() {
9 return null;
10}
11let sharedA11YObservable;
12let nativeObserver;
13function getSharedA11YObservable() {
14 if (sharedA11YObservable) {
15 return sharedA11YObservable;
16 }
17 sharedA11YObservable = new SharedA11YObservable();
18 let isVoiceOverRunning;
19 if (typeof UIAccessibilityIsVoiceOverRunning === 'function') {
20 isVoiceOverRunning = UIAccessibilityIsVoiceOverRunning;
21 }
22 else {
23 if (typeof UIAccessibilityIsVoiceOverRunning !== 'function') {
24 Trace.write(`UIAccessibilityIsVoiceOverRunning() - is not a function`, Trace.categories.Accessibility, Trace.messageType.error);
25 isVoiceOverRunning = () => false;
26 }
27 }
28 sharedA11YObservable.set(AccessibilityServiceEnabledPropName, isVoiceOverRunning());
29 let voiceOverStatusChangedNotificationName = null;
30 if (typeof UIAccessibilityVoiceOverStatusDidChangeNotification !== 'undefined') {
31 // iOS 11+
32 voiceOverStatusChangedNotificationName = UIAccessibilityVoiceOverStatusDidChangeNotification;
33 }
34 else if (typeof UIAccessibilityVoiceOverStatusChanged !== 'undefined') {
35 // iOS <11
36 voiceOverStatusChangedNotificationName = UIAccessibilityVoiceOverStatusChanged;
37 }
38 if (voiceOverStatusChangedNotificationName) {
39 nativeObserver = Application.ios.addNotificationObserver(voiceOverStatusChangedNotificationName, () => {
40 sharedA11YObservable?.set(AccessibilityServiceEnabledPropName, isVoiceOverRunning());
41 });
42 Application.on(Application.exitEvent, () => {
43 if (nativeObserver) {
44 Application.ios.removeNotificationObserver(nativeObserver, voiceOverStatusChangedNotificationName);
45 }
46 nativeObserver = null;
47 if (sharedA11YObservable) {
48 sharedA11YObservable.removeEventListener(Observable.propertyChangeEvent);
49 sharedA11YObservable = null;
50 }
51 });
52 }
53 Application.on(Application.resumeEvent, () => sharedA11YObservable.set(AccessibilityServiceEnabledPropName, isVoiceOverRunning()));
54 return sharedA11YObservable;
55}
56export class AccessibilityServiceEnabledObservable extends CommonA11YServiceEnabledObservable {
57 constructor() {
58 super(getSharedA11YObservable());
59 }
60}
61//# sourceMappingURL=accessibility-service.ios.js.map
\No newline at end of file