From 8221c33650233b59a0672e1ba1e2c2c01398672b Mon Sep 17 00:00:00 2001 From: Chace Liang Date: Thu, 1 Oct 2015 18:07:06 -0700 Subject: [PATCH] Add Voice Over related change to AccessibilityManager. Reviewed By: @hedgerwang Differential Revision: D2491520 --- React/Modules/RCTAccessibilityManager.h | 2 ++ React/Modules/RCTAccessibilityManager.m | 26 +++++++++++++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/React/Modules/RCTAccessibilityManager.h b/React/Modules/RCTAccessibilityManager.h index a901aa874f..ded98bcbd8 100644 --- a/React/Modules/RCTAccessibilityManager.h +++ b/React/Modules/RCTAccessibilityManager.h @@ -21,6 +21,8 @@ extern NSString *const RCTAccessibilityManagerDidUpdateMultiplierNotification; / /// map from UIKit categories to multipliers @property (nonatomic, copy) NSDictionary *multipliers; +@property (nonatomic, assign) BOOL isVoiceOverEnabled; + @end @interface RCTBridge (RCTAccessibilityManager) diff --git a/React/Modules/RCTAccessibilityManager.m b/React/Modules/RCTAccessibilityManager.m index 12330c8491..153368891f 100644 --- a/React/Modules/RCTAccessibilityManager.m +++ b/React/Modules/RCTAccessibilityManager.m @@ -9,6 +9,8 @@ #import "RCTAccessibilityManager.h" +#import "RCTBridge.h" +#import "RCTEventDispatcher.h" #import "RCTLog.h" NSString *const RCTAccessibilityManagerDidUpdateMultiplierNotification = @"RCTAccessibilityManagerDidUpdateMultiplierNotification"; @@ -24,6 +26,7 @@ NSString *const RCTAccessibilityManagerDidUpdateMultiplierNotification = @"RCTAc @synthesize bridge = _bridge; @synthesize multipliers = _multipliers; +@synthesize isVoiceOverEnabled = _isVoiceOverEnabled; RCT_EXPORT_MODULE() @@ -61,7 +64,14 @@ RCT_EXPORT_MODULE() selector:@selector(didReceiveNewContentSizeCategory:) name:UIContentSizeCategoryDidChangeNotification object:[UIApplication sharedApplication]]; + + [[NSNotificationCenter defaultCenter] addObserver:self + selector:@selector(didReceiveNewVoiceOverStatus:) + name:UIAccessibilityVoiceOverStatusChanged + object:nil]; + self.contentSizeCategory = [UIApplication sharedApplication].preferredContentSizeCategory; + _isVoiceOverEnabled = UIAccessibilityIsVoiceOverRunning(); } return self; } @@ -76,6 +86,16 @@ RCT_EXPORT_MODULE() self.contentSizeCategory = note.userInfo[UIContentSizeCategoryNewValueKey]; } +- (void)didReceiveNewVoiceOverStatus:(NSNotification *)notification +{ + BOOL newIsVoiceOverEnabled = UIAccessibilityIsVoiceOverRunning(); + if (_isVoiceOverEnabled != newIsVoiceOverEnabled) { + _isVoiceOverEnabled = newIsVoiceOverEnabled; + [_bridge.eventDispatcher sendDeviceEventWithName:@"voiceOverDidChange" + body:@(_isVoiceOverEnabled)]; + } +} + - (void)setContentSizeCategory:(NSString *)contentSizeCategory { if (_contentSizeCategory != contentSizeCategory) { @@ -145,6 +165,12 @@ RCT_EXPORT_METHOD(getMultiplier:(RCTResponseSenderBlock)callback) } } +RCT_EXPORT_METHOD(getCurrentVoiceOverState:(RCTResponseSenderBlock)callback + error:(__unused RCTResponseSenderBlock)error) +{ + callback(@[@(_isVoiceOverEnabled)]); +} + @end @implementation RCTBridge (RCTAccessibilityManager)