From d8931e2f940de0ce7bce9d8b8cf559ccec49f46f Mon Sep 17 00:00:00 2001 From: Phillip Pan Date: Fri, 1 Oct 2021 21:15:37 -0700 Subject: [PATCH] provide public hook to programatically turn on voiceover Summary: Changelog: [Internal] https://fb.workplace.com/groups/rn.support/posts/6677051292343429 ax team is building a tool to extract information about the views for design reviewers, and RN has some AX information that is not working atm because of dependency on whether voiceover is on or not. so, this will give them the ability to programmatically set that field and hopefully be able to get accurate ax info Reviewed By: ikenwoo Differential Revision: D31010566 fbshipit-source-id: 4c8a33fce40266b270dd5994442c8472ca88f5dd --- .../RCTAccessibilityManager+Internal.h | 21 +++++++++++++++++++ React/CoreModules/RCTAccessibilityManager.mm | 21 ++++++++++++++++--- 2 files changed, 39 insertions(+), 3 deletions(-) create mode 100644 React/CoreModules/RCTAccessibilityManager+Internal.h diff --git a/React/CoreModules/RCTAccessibilityManager+Internal.h b/React/CoreModules/RCTAccessibilityManager+Internal.h new file mode 100644 index 00000000000000..b3a17b5f3c50d3 --- /dev/null +++ b/React/CoreModules/RCTAccessibilityManager+Internal.h @@ -0,0 +1,21 @@ +/* + * 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. + */ + +#import "RCTAccessibilityManager.h" + +#import + +NS_ASSUME_NONNULL_BEGIN + +RCT_EXTERN_C_BEGIN + +// Only to be used for testing and internal tooling. Do not use this in production. +void RCTAccessibilityManagerSetIsVoiceOverEnabled(RCTAccessibilityManager *accessibiltyManager, BOOL isVoiceOverEnabled); + +RCT_EXTERN_C_END + +NS_ASSUME_NONNULL_END diff --git a/React/CoreModules/RCTAccessibilityManager.mm b/React/CoreModules/RCTAccessibilityManager.mm index 1ea4436cf33c98..3d0c7765d059ca 100644 --- a/React/CoreModules/RCTAccessibilityManager.mm +++ b/React/CoreModules/RCTAccessibilityManager.mm @@ -6,6 +6,7 @@ */ #import "RCTAccessibilityManager.h" +#import "RCTAccessibilityManager+Internal.h" #import #import @@ -183,9 +184,14 @@ - (void)reduceTransparencyStatusDidChange:(__unused NSNotification *)notificatio - (void)voiceVoiceOverStatusDidChange:(__unused NSNotification *)notification { - BOOL newIsVoiceOverEnabled = UIAccessibilityIsVoiceOverRunning(); - if (_isVoiceOverEnabled != newIsVoiceOverEnabled) { - _isVoiceOverEnabled = newIsVoiceOverEnabled; + BOOL isVoiceOverEnabled = UIAccessibilityIsVoiceOverRunning(); + [self _setIsVoiceOverEnabled:isVoiceOverEnabled]; +} + +- (void)_setIsVoiceOverEnabled:(BOOL)isVoiceOverEnabled +{ + if (_isVoiceOverEnabled != isVoiceOverEnabled) { + _isVoiceOverEnabled = isVoiceOverEnabled; #pragma clang diagnostic push #pragma clang diagnostic ignored "-Wdeprecated-declarations" [[_moduleRegistry moduleForName:"EventDispatcher"] sendDeviceEventWithName:@"screenReaderChanged" @@ -350,6 +356,15 @@ static void setMultipliers( return std::make_shared(params); } +#pragma mark - Internal + +void RCTAccessibilityManagerSetIsVoiceOverEnabled( + RCTAccessibilityManager *accessibilityManager, + BOOL isVoiceOverEnabled) +{ + [accessibilityManager _setIsVoiceOverEnabled:isVoiceOverEnabled]; +} + @end @implementation RCTBridge (RCTAccessibilityManager)