Add Voice Over related change to AccessibilityManager.

Reviewed By: @hedgerwang

Differential Revision: D2491520
This commit is contained in:
Chace Liang 2015-10-01 18:07:06 -07:00 коммит произвёл facebook-github-bot-8
Родитель 626b551ff2
Коммит 8221c33650
2 изменённых файлов: 28 добавлений и 0 удалений

Просмотреть файл

@ -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)

Просмотреть файл

@ -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)