mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-11-05 13:26:48 +08:00
feat(core): first class a11y support (#8909)
This commit is contained in:
committed by
Nathan Walker
parent
577b1e9dad
commit
f2e21a50a7
75
packages/core/accessibility/accessibility-service.ios.ts
Normal file
75
packages/core/accessibility/accessibility-service.ios.ts
Normal file
@@ -0,0 +1,75 @@
|
||||
import * as Application from '../application';
|
||||
import { Observable } from '../data/observable';
|
||||
import { Trace } from '../trace';
|
||||
import { AccessibilityServiceEnabledPropName, CommonA11YServiceEnabledObservable, SharedA11YObservable } from './accessibility-service-common';
|
||||
|
||||
export function isAccessibilityServiceEnabled(): boolean {
|
||||
return getSharedA11YObservable().accessibilityServiceEnabled;
|
||||
}
|
||||
|
||||
export function getAndroidAccessibilityManager(): null {
|
||||
return null;
|
||||
}
|
||||
|
||||
let sharedA11YObservable: SharedA11YObservable;
|
||||
let nativeObserver;
|
||||
|
||||
function getSharedA11YObservable(): SharedA11YObservable {
|
||||
if (sharedA11YObservable) {
|
||||
return sharedA11YObservable;
|
||||
}
|
||||
|
||||
sharedA11YObservable = new SharedA11YObservable();
|
||||
|
||||
let isVoiceOverRunning: () => boolean;
|
||||
if (typeof UIAccessibilityIsVoiceOverRunning === 'function') {
|
||||
isVoiceOverRunning = UIAccessibilityIsVoiceOverRunning;
|
||||
} else {
|
||||
if (typeof UIAccessibilityIsVoiceOverRunning !== 'function') {
|
||||
Trace.write(`UIAccessibilityIsVoiceOverRunning() - is not a function`, Trace.categories.Accessibility, Trace.messageType.error);
|
||||
|
||||
isVoiceOverRunning = () => false;
|
||||
}
|
||||
}
|
||||
|
||||
sharedA11YObservable.set(AccessibilityServiceEnabledPropName, isVoiceOverRunning());
|
||||
|
||||
let voiceOverStatusChangedNotificationName: string | null = null;
|
||||
if (typeof UIAccessibilityVoiceOverStatusDidChangeNotification !== 'undefined') {
|
||||
// iOS 11+
|
||||
voiceOverStatusChangedNotificationName = UIAccessibilityVoiceOverStatusDidChangeNotification;
|
||||
} else if (typeof UIAccessibilityVoiceOverStatusChanged !== 'undefined') {
|
||||
// iOS <11
|
||||
voiceOverStatusChangedNotificationName = UIAccessibilityVoiceOverStatusChanged;
|
||||
}
|
||||
|
||||
if (voiceOverStatusChangedNotificationName) {
|
||||
nativeObserver = Application.ios.addNotificationObserver(voiceOverStatusChangedNotificationName, () => {
|
||||
sharedA11YObservable?.set(AccessibilityServiceEnabledPropName, isVoiceOverRunning());
|
||||
});
|
||||
|
||||
Application.on(Application.exitEvent, () => {
|
||||
if (nativeObserver) {
|
||||
Application.ios.removeNotificationObserver(nativeObserver, voiceOverStatusChangedNotificationName);
|
||||
}
|
||||
|
||||
nativeObserver = null;
|
||||
|
||||
if (sharedA11YObservable) {
|
||||
sharedA11YObservable.removeEventListener(Observable.propertyChangeEvent);
|
||||
|
||||
sharedA11YObservable = null;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
Application.on(Application.resumeEvent, () => sharedA11YObservable.set(AccessibilityServiceEnabledPropName, isVoiceOverRunning()));
|
||||
|
||||
return sharedA11YObservable;
|
||||
}
|
||||
|
||||
export class AccessibilityServiceEnabledObservable extends CommonA11YServiceEnabledObservable {
|
||||
constructor() {
|
||||
super(getSharedA11YObservable());
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user