Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[TM] Add spec for AccessibilityManager #24894

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
52 changes: 41 additions & 11 deletions Libraries/Components/AccessibilityInfo/AccessibilityInfo.ios.js
Expand Up @@ -10,12 +10,11 @@

'use strict';

const NativeModules = require('../../BatchedBridge/NativeModules');
import NativeAccessibilityManager from './NativeAccessibilityManager';

const Promise = require('../../Promise');
const RCTDeviceEventEmitter = require('../../EventEmitter/RCTDeviceEventEmitter');

const AccessibilityManager = NativeModules.AccessibilityManager;

const CHANGE_EVENT_NAME = {
announcementFinished: 'announcementFinished',
boldTextChanged: 'boldTextChanged',
Expand Down Expand Up @@ -59,7 +58,11 @@ const AccessibilityInfo = {
*/
isBoldTextEnabled: function(): Promise<boolean> {
return new Promise((resolve, reject) => {
AccessibilityManager.getCurrentBoldTextState(resolve, reject);
if (NativeAccessibilityManager) {
NativeAccessibilityManager.getCurrentBoldTextState(resolve, reject);
} else {
reject(reject);
}
});
},

Expand All @@ -73,7 +76,11 @@ const AccessibilityInfo = {
*/
isGrayscaleEnabled: function(): Promise<boolean> {
return new Promise((resolve, reject) => {
AccessibilityManager.getCurrentGrayscaleState(resolve, reject);
if (NativeAccessibilityManager) {
NativeAccessibilityManager.getCurrentGrayscaleState(resolve, reject);
} else {
reject(reject);
}
});
},

Expand All @@ -87,7 +94,11 @@ const AccessibilityInfo = {
*/
isInvertColorsEnabled: function(): Promise<boolean> {
return new Promise((resolve, reject) => {
AccessibilityManager.getCurrentInvertColorsState(resolve, reject);
if (NativeAccessibilityManager) {
NativeAccessibilityManager.getCurrentInvertColorsState(resolve, reject);
} else {
reject(reject);
}
});
},

Expand All @@ -101,7 +112,11 @@ const AccessibilityInfo = {
*/
isReduceMotionEnabled: function(): Promise<boolean> {
return new Promise((resolve, reject) => {
AccessibilityManager.getCurrentReduceMotionState(resolve, reject);
if (NativeAccessibilityManager) {
NativeAccessibilityManager.getCurrentReduceMotionState(resolve, reject);
} else {
reject(reject);
}
});
},

Expand All @@ -115,7 +130,14 @@ const AccessibilityInfo = {
*/
isReduceTransparencyEnabled: function(): Promise<boolean> {
return new Promise((resolve, reject) => {
AccessibilityManager.getCurrentReduceTransparencyState(resolve, reject);
if (NativeAccessibilityManager) {
NativeAccessibilityManager.getCurrentReduceTransparencyState(
resolve,
reject,
);
} else {
reject(reject);
}
});
},

Expand All @@ -129,7 +151,11 @@ const AccessibilityInfo = {
*/
isScreenReaderEnabled: function(): Promise<boolean> {
return new Promise((resolve, reject) => {
AccessibilityManager.getCurrentVoiceOverState(resolve, reject);
if (NativeAccessibilityManager) {
NativeAccessibilityManager.getCurrentVoiceOverState(resolve, reject);
} else {
reject(reject);
}
});
},

Expand Down Expand Up @@ -204,7 +230,9 @@ const AccessibilityInfo = {
* See http://facebook.github.io/react-native/docs/accessibilityinfo.html#setaccessibilityfocus
*/
setAccessibilityFocus: function(reactTag: number): void {
AccessibilityManager.setAccessibilityFocus(reactTag);
if (NativeAccessibilityManager) {
NativeAccessibilityManager.setAccessibilityFocus(reactTag);
}
},

/**
Expand All @@ -213,7 +241,9 @@ const AccessibilityInfo = {
* See http://facebook.github.io/react-native/docs/accessibilityinfo.html#announceforaccessibility
*/
announceForAccessibility: function(announcement: string): void {
AccessibilityManager.announceForAccessibility(announcement);
if (NativeAccessibilityManager) {
NativeAccessibilityManager.announceForAccessibility(announcement);
}
},

/**
Expand Down
@@ -0,0 +1,48 @@
/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @flow
* @format
*/

'use strict';

import {Platform} from 'react-native';
import type {TurboModule} from 'RCTExport';
import * as TurboModuleRegistry from 'TurboModuleRegistry';

export interface Spec extends TurboModule {
+getCurrentBoldTextState: (
onSuccess: (isBoldTextEnabled: boolean) => void,
onError: (error: Object) => void,
) => void;
+getCurrentGrayscaleState: (
onSuccess: (isGrayscaleEnabled: boolean) => void,
onError: (error: Object) => void,
) => void;
+getCurrentInvertColorsState: (
onSuccess: (isInvertColorsEnabled: boolean) => void,
onError: (error: Object) => void,
) => void;
+getCurrentReduceMotionState: (
onSuccess: (isReduceMotionEnabled: boolean) => void,
onError: (error: Object) => void,
) => void;
+getCurrentReduceTransparencyState: (
onSuccess: (isReduceTransparencyEnabled: boolean) => void,
onError: (error: Object) => void,
) => void;
+getCurrentVoiceOverState: (
onSuccess: (isScreenReaderEnabled: boolean) => void,
onError: (error: Object) => void,
) => void;
+setAccessibilityFocus: (reactTag: number) => void;
+announceForAccessibility: (announcement: string) => void;
}

export default (Platform.OS === 'ios'
? TurboModuleRegistry.getEnforcing<Spec>('AccessibilityManager')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove this conditional, and just use get

: null);