1 | import { Application } from '../application';
|
2 | import { Observable } from '../data/observable';
|
3 | import { Trace } from '../trace';
|
4 | import { AccessibilityServiceEnabledPropName, CommonA11YServiceEnabledObservable, SharedA11YObservable } from './accessibility-service-common';
|
5 | export function isAccessibilityServiceEnabled() {
|
6 | return getSharedA11YObservable().accessibilityServiceEnabled;
|
7 | }
|
8 | export function getAndroidAccessibilityManager() {
|
9 | return null;
|
10 | }
|
11 | let sharedA11YObservable;
|
12 | let nativeObserver;
|
13 | function 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 |
|
32 | voiceOverStatusChangedNotificationName = UIAccessibilityVoiceOverStatusDidChangeNotification;
|
33 | }
|
34 | else if (typeof UIAccessibilityVoiceOverStatusChanged !== 'undefined') {
|
35 |
|
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 | }
|
56 | export class AccessibilityServiceEnabledObservable extends CommonA11YServiceEnabledObservable {
|
57 | constructor() {
|
58 | super(getSharedA11YObservable());
|
59 | }
|
60 | }
|
61 |
|
\ | No newline at end of file |