Skip to content

Commit

Permalink
provide public hook to programatically turn on voiceover
Browse files Browse the repository at this point in the history
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
  • Loading branch information
philIip authored and facebook-github-bot committed Oct 2, 2021
1 parent ea53d3a commit d8931e2
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 3 deletions.
21 changes: 21 additions & 0 deletions React/CoreModules/RCTAccessibilityManager+Internal.h
Original file line number Diff line number Diff line change
@@ -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 <React/RCTDefines.h>

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
21 changes: 18 additions & 3 deletions React/CoreModules/RCTAccessibilityManager.mm
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
*/

#import "RCTAccessibilityManager.h"
#import "RCTAccessibilityManager+Internal.h"

#import <FBReactNativeSpec/FBReactNativeSpec.h>
#import <React/RCTBridge.h>
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -350,6 +356,15 @@ static void setMultipliers(
return std::make_shared<facebook::react::NativeAccessibilityManagerSpecJSI>(params);
}

#pragma mark - Internal

void RCTAccessibilityManagerSetIsVoiceOverEnabled(
RCTAccessibilityManager *accessibilityManager,
BOOL isVoiceOverEnabled)
{
[accessibilityManager _setIsVoiceOverEnabled:isVoiceOverEnabled];
}

@end

@implementation RCTBridge (RCTAccessibilityManager)
Expand Down

0 comments on commit d8931e2

Please sign in to comment.