From b7518b0301fca24a984f1d035c3326e593d79669 Mon Sep 17 00:00:00 2001 From: michalchudziak Date: Thu, 16 May 2019 10:46:03 +0200 Subject: [PATCH 1/3] [TM] Add spec for AccessibilityManager --- .../AccessibilityInfo.ios.js | 23 ++++----- .../NativeAccessibilityManager.js | 49 +++++++++++++++++++ 2 files changed, 61 insertions(+), 11 deletions(-) create mode 100644 Libraries/Components/AccessibilityInfo/NativeAccessibilityManager.js diff --git a/Libraries/Components/AccessibilityInfo/AccessibilityInfo.ios.js b/Libraries/Components/AccessibilityInfo/AccessibilityInfo.ios.js index e1c73379bb9662..7db1060edd0d37 100644 --- a/Libraries/Components/AccessibilityInfo/AccessibilityInfo.ios.js +++ b/Libraries/Components/AccessibilityInfo/AccessibilityInfo.ios.js @@ -10,11 +10,9 @@ 'use strict'; -const NativeModules = require('../../BatchedBridge/NativeModules'); const Promise = require('../../Promise'); const RCTDeviceEventEmitter = require('../../EventEmitter/RCTDeviceEventEmitter'); - -const AccessibilityManager = NativeModules.AccessibilityManager; +const NativeAccessibilityManager = require('./NativeAccessibilityManager'); const CHANGE_EVENT_NAME = { announcementFinished: 'announcementFinished', @@ -59,7 +57,7 @@ const AccessibilityInfo = { */ isBoldTextEnabled: function(): Promise { return new Promise((resolve, reject) => { - AccessibilityManager.getCurrentBoldTextState(resolve, reject); + NativeAccessibilityManager.getCurrentBoldTextState(resolve, reject); }); }, @@ -73,7 +71,7 @@ const AccessibilityInfo = { */ isGrayscaleEnabled: function(): Promise { return new Promise((resolve, reject) => { - AccessibilityManager.getCurrentGrayscaleState(resolve, reject); + NativeAccessibilityManager.getCurrentGrayscaleState(resolve, reject); }); }, @@ -87,7 +85,7 @@ const AccessibilityInfo = { */ isInvertColorsEnabled: function(): Promise { return new Promise((resolve, reject) => { - AccessibilityManager.getCurrentInvertColorsState(resolve, reject); + NativeAccessibilityManager.getCurrentInvertColorsState(resolve, reject); }); }, @@ -101,7 +99,7 @@ const AccessibilityInfo = { */ isReduceMotionEnabled: function(): Promise { return new Promise((resolve, reject) => { - AccessibilityManager.getCurrentReduceMotionState(resolve, reject); + NativeAccessibilityManager.getCurrentReduceMotionState(resolve, reject); }); }, @@ -115,7 +113,10 @@ const AccessibilityInfo = { */ isReduceTransparencyEnabled: function(): Promise { return new Promise((resolve, reject) => { - AccessibilityManager.getCurrentReduceTransparencyState(resolve, reject); + NativeAccessibilityManager.getCurrentReduceTransparencyState( + resolve, + reject, + ); }); }, @@ -129,7 +130,7 @@ const AccessibilityInfo = { */ isScreenReaderEnabled: function(): Promise { return new Promise((resolve, reject) => { - AccessibilityManager.getCurrentVoiceOverState(resolve, reject); + NativeAccessibilityManager.getCurrentVoiceOverState(resolve, reject); }); }, @@ -204,7 +205,7 @@ const AccessibilityInfo = { * See http://facebook.github.io/react-native/docs/accessibilityinfo.html#setaccessibilityfocus */ setAccessibilityFocus: function(reactTag: number): void { - AccessibilityManager.setAccessibilityFocus(reactTag); + NativeAccessibilityManager.setAccessibilityFocus(reactTag); }, /** @@ -213,7 +214,7 @@ const AccessibilityInfo = { * See http://facebook.github.io/react-native/docs/accessibilityinfo.html#announceforaccessibility */ announceForAccessibility: function(announcement: string): void { - AccessibilityManager.announceForAccessibility(announcement); + NativeAccessibilityManager.announceForAccessibility(announcement); }, /** diff --git a/Libraries/Components/AccessibilityInfo/NativeAccessibilityManager.js b/Libraries/Components/AccessibilityInfo/NativeAccessibilityManager.js new file mode 100644 index 00000000000000..f0bb48d09ffce8 --- /dev/null +++ b/Libraries/Components/AccessibilityInfo/NativeAccessibilityManager.js @@ -0,0 +1,49 @@ +/** + * 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 type {TurboModule} from 'RCTExport'; +import * as TurboModuleRegistry from 'TurboModuleRegistry'; + +export interface Spec extends TurboModule { + +getCurrentBoldTextState: ( + resolve: (isBoldTextEnabled: boolean) => void, + reject: (error: Object) => void, + ) => void; + +getCurrentGrayscaleState: ( + resolve: (isGrayscaleEnabled: boolean) => void, + reject: (error: Object) => void, + ) => void; + +getCurrentInvertColorsState: ( + resolve: (isInvertColorsEnabled: boolean) => void, + reject: (error: Object) => void, + ) => void; + +getCurrentReduceMotionState: ( + resolve: (isReduceMotionEnabled: boolean) => void, + reject: (error: Object) => void, + ) => void; + +getCurrentReduceTransparencyState: ( + resolve: (isReduceTransparencyEnabled: boolean) => void, + reject: (error: Object) => void, + ) => void; + +getCurrentVoiceOverState: ( + resolve: (isScreenReaderEnabled: boolean) => void, + reject: (error: Object) => void, + ) => void; + +setAccessibilityFocus: (reactTag: number) => void; + +announceForAccessibility: (announcement: string) => void; + + // RCTDeviceEventEmitter + +addListener: (eventName: string, handler: Function) => Object; + +removeListeners: (eventName: string, handler: Function) => void; +} + +export default TurboModuleRegistry.getEnforcing('AccessibilityManager'); From 8d3f6df0d3a19df5963cec2db3daad77de9e9cdb Mon Sep 17 00:00:00 2001 From: michalchudziak Date: Thu, 16 May 2019 11:19:33 +0200 Subject: [PATCH 2/3] Add default to require --- Libraries/Components/AccessibilityInfo/AccessibilityInfo.ios.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Libraries/Components/AccessibilityInfo/AccessibilityInfo.ios.js b/Libraries/Components/AccessibilityInfo/AccessibilityInfo.ios.js index 7db1060edd0d37..64a7772098e52a 100644 --- a/Libraries/Components/AccessibilityInfo/AccessibilityInfo.ios.js +++ b/Libraries/Components/AccessibilityInfo/AccessibilityInfo.ios.js @@ -12,7 +12,7 @@ const Promise = require('../../Promise'); const RCTDeviceEventEmitter = require('../../EventEmitter/RCTDeviceEventEmitter'); -const NativeAccessibilityManager = require('./NativeAccessibilityManager'); +const NativeAccessibilityManager = require('./NativeAccessibilityManager').default; const CHANGE_EVENT_NAME = { announcementFinished: 'announcementFinished', From 933c2cf41423e94773498e3b0850c56a89b91893 Mon Sep 17 00:00:00 2001 From: michalchudziak Date: Thu, 16 May 2019 14:00:15 +0200 Subject: [PATCH 3/3] Format file correctly --- .../Components/AccessibilityInfo/AccessibilityInfo.ios.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Libraries/Components/AccessibilityInfo/AccessibilityInfo.ios.js b/Libraries/Components/AccessibilityInfo/AccessibilityInfo.ios.js index 64a7772098e52a..eb174807bad651 100644 --- a/Libraries/Components/AccessibilityInfo/AccessibilityInfo.ios.js +++ b/Libraries/Components/AccessibilityInfo/AccessibilityInfo.ios.js @@ -12,7 +12,8 @@ const Promise = require('../../Promise'); const RCTDeviceEventEmitter = require('../../EventEmitter/RCTDeviceEventEmitter'); -const NativeAccessibilityManager = require('./NativeAccessibilityManager').default; +const NativeAccessibilityManager = require('./NativeAccessibilityManager') + .default; const CHANGE_EVENT_NAME = { announcementFinished: 'announcementFinished',