Configure requiresMainQueueSetup for core modules

Reviewed By: fkgozali

Differential Revision: D5528305

fbshipit-source-id: f17cad933685be09784b2246f44baf252bfa5a26
This commit is contained in:
Pieter De Baets 2017-08-07 06:45:24 -07:00 committed by Facebook Github Bot
parent d42ccca2e1
commit 220034c4d4
14 changed files with 99 additions and 53 deletions

View File

@ -32,6 +32,11 @@ RCT_EXPORT_MODULE(BlobModule)
@synthesize bridge = _bridge;
+ (BOOL)requiresMainQueueSetup
{
return NO;
}
- (NSDictionary<NSString *, id> *)constantsToExport
{
return @{

View File

@ -24,38 +24,40 @@
RCT_EXPORT_MODULE()
+ (BOOL)requiresMainQueueSetup
{
return NO;
}
- (instancetype)init
{
return [self initWithUserDefaults:[NSUserDefaults standardUserDefaults]];
}
- (instancetype)initWithUserDefaults:(NSUserDefaults *)defaults
{
if ((self = [self init])) {
_defaults = defaults;
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(userDefaultsDidChange:)
name:NSUserDefaultsDidChangeNotification
object:_defaults];
}
return self;
}
- (void)setBridge:(RCTBridge *)bridge
{
_bridge = bridge;
if (!_defaults) {
_defaults = [NSUserDefaults standardUserDefaults];
}
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(userDefaultsDidChange:)
name:NSUserDefaultsDidChangeNotification
object:_defaults];
}
- (NSDictionary<NSString *, id> *)constantsToExport
{
return @{@"settings": RCTJSONClean([_defaults dictionaryRepresentation])};
}
- (void)dealloc
{
[[NSNotificationCenter defaultCenter] removeObserver:self];
}
- (NSDictionary<NSString *, id> *)constantsToExport
{
return @{@"settings": RCTJSONClean([_defaults dictionaryRepresentation])};
}
- (void)userDefaultsDidChange:(NSNotification *)note
{
if (_ignoringUpdates) {

View File

@ -71,7 +71,6 @@ RCT_EXPORT_MODULE()
@end
@interface RCTModuleInitNotificationRaceTests : XCTestCase <RCTBridgeDelegate>
{
RCTBridge *_bridge;
@ -98,6 +97,10 @@ RCT_EXPORT_MODULE()
_notificationObserver = [RCTNotificationObserverModule new];
_bridge = [[RCTBridge alloc] initWithDelegate:self launchOptions:nil];
dispatch_async(dispatch_get_main_queue(), ^{
[[self->_bridge uiManager] constantsToExport];
});
}
- (void)tearDown

View File

@ -13,8 +13,6 @@
#import "RCTUtils.h"
@implementation RCTPlatform
static NSString *interfaceIdiom(UIUserInterfaceIdiom idiom) {
switch(idiom) {
case UIUserInterfaceIdiomPhone:
@ -30,8 +28,15 @@ static NSString *interfaceIdiom(UIUserInterfaceIdiom idiom) {
}
}
@implementation RCTPlatform
RCT_EXPORT_MODULE(PlatformConstants)
+ (BOOL)requiresMainQueueSetup
{
return YES;
}
- (NSDictionary<NSString *, id> *)constantsToExport
{
UIDevice *device = [UIDevice currentDevice];

View File

@ -41,11 +41,9 @@ RCT_EXPORT_MODULE()
[[NSNotificationCenter defaultCenter] removeObserver:self];
}
- (instancetype)init
+ (BOOL)requiresMainQueueSetup
{
// We're only overriding this to ensure the module gets created at startup
// TODO (t11106126): Remove once we have more declarative control over module setup.
return [super init];
return YES;
}
- (void)setBridge:(RCTBridge *)bridge

View File

@ -99,6 +99,11 @@ RCT_EXPORT_MODULE()
RCTSwapInstanceMethods([UIWindow class], @selector(motionEnded:withEvent:), @selector(RCT_motionEnded:withEvent:));
}
+ (BOOL)requiresMainQueueSetup
{
return YES;
}
- (instancetype)init
{
if ((self = [super init])) {

View File

@ -17,21 +17,7 @@
NSString *const RCTAccessibilityManagerDidUpdateMultiplierNotification = @"RCTAccessibilityManagerDidUpdateMultiplierNotification";
@interface RCTAccessibilityManager ()
@property (nonatomic, copy) NSString *contentSizeCategory;
@property (nonatomic, assign) CGFloat multiplier;
@end
@implementation RCTAccessibilityManager
@synthesize bridge = _bridge;
@synthesize multipliers = _multipliers;
RCT_EXPORT_MODULE()
+ (NSDictionary<NSString *, NSString *> *)JSToUIKitMap
static NSString *UIKitCategoryFromJSCategory(NSString *JSCategory)
{
static NSDictionary *map = nil;
static dispatch_once_t onceToken;
@ -49,12 +35,26 @@ RCT_EXPORT_MODULE()
@"accessibilityExtraExtraLarge": UIContentSizeCategoryAccessibilityExtraExtraLarge,
@"accessibilityExtraExtraExtraLarge": UIContentSizeCategoryAccessibilityExtraExtraExtraLarge};
});
return map;
return map[JSCategory];
}
+ (NSString *)UIKitCategoryFromJSCategory:(NSString *)JSCategory
@interface RCTAccessibilityManager ()
@property (nonatomic, copy) NSString *contentSizeCategory;
@property (nonatomic, assign) CGFloat multiplier;
@end
@implementation RCTAccessibilityManager
@synthesize bridge = _bridge;
@synthesize multipliers = _multipliers;
RCT_EXPORT_MODULE()
+ (BOOL)requiresMainQueueSetup
{
return [self JSToUIKitMap][JSCategory];
return YES;
}
- (instancetype)init
@ -71,7 +71,7 @@ RCT_EXPORT_MODULE()
selector:@selector(didReceiveNewVoiceOverStatus:)
name:UIAccessibilityVoiceOverStatusChanged
object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(accessibilityAnnouncementDidFinish:)
name:UIAccessibilityAnnouncementDidFinishNotification
@ -112,7 +112,7 @@ RCT_EXPORT_MODULE()
// Response dictionary to populate the event with.
NSDictionary *response = @{@"announcement": userInfo[UIAccessibilityAnnouncementKeyStringValue],
@"success": userInfo[UIAccessibilityAnnouncementKeyWasSuccessful]};
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
[_bridge.eventDispatcher sendDeviceEventWithName:@"announcementDidFinish"
@ -176,7 +176,7 @@ RCT_EXPORT_METHOD(setAccessibilityContentSizeMultipliers:(NSDictionary *)JSMulti
NSMutableDictionary<NSString *, NSNumber *> *multipliers = [NSMutableDictionary new];
for (NSString *__nonnull JSCategory in JSMultipliers) {
NSNumber *m = [RCTConvert NSNumber:JSMultipliers[JSCategory]];
NSString *UIKitCategory = [[self class] UIKitCategoryFromJSCategory:JSCategory];
NSString *UIKitCategory = UIKitCategoryFromJSCategory(JSCategory);
multipliers[UIKitCategory] = m;
}
self.multipliers = multipliers;

View File

@ -16,8 +16,6 @@
static NSString *RCTCurrentAppBackgroundState()
{
RCTAssertMainQueue();
static NSDictionary *states;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
@ -41,6 +39,13 @@ static NSString *RCTCurrentAppBackgroundState()
RCT_EXPORT_MODULE()
+ (BOOL)requiresMainQueueSetup
{
// UIApplication.applicationState seems reasonably safe to access from
// a background thread.
return NO;
}
- (dispatch_queue_t)methodQueue
{
return dispatch_get_main_queue();

View File

@ -132,6 +132,11 @@ static NSString *const kRCTDevSettingsUserDefaultsKey = @"RCTDevMenu";
RCT_EXPORT_MODULE()
+ (BOOL)requiresMainQueueSetup
{
return YES; // RCT_DEV-only
}
- (instancetype)init
{
// default behavior is to use NSUserDefaults

View File

@ -24,6 +24,11 @@
RCT_EXPORT_MODULE()
+ (BOOL)requiresMainQueueSetup
{
return YES;
}
- (dispatch_queue_t)methodQueue
{
return dispatch_get_main_queue();

View File

@ -14,6 +14,11 @@
RCT_EXPORT_MODULE()
+ (BOOL)requiresMainQueueSetup
{
return NO;
}
RCT_EXPORT_METHOD(allowRTL:(BOOL)value)
{
[[RCTI18nUtil sharedInstance] allowRTL:value];

View File

@ -17,6 +17,11 @@ RCT_EXPORT_MODULE()
@synthesize bridge = _bridge;
+ (BOOL)requiresMainQueueSetup
{
return NO;
}
- (NSDictionary<NSString *, id> *)constantsToExport
{
return @{

View File

@ -77,6 +77,11 @@ NSString *const RCTUIManagerWillUpdateViewsDueToContentSizeMultiplierChangeNotif
RCT_EXPORT_MODULE()
+ (BOOL)requiresMainQueueSetup
{
return NO;
}
- (void)invalidate
{
/**

View File

@ -131,11 +131,9 @@ static vm_size_t RCTGetResidentMemorySize(void)
RCT_EXPORT_MODULE()
- (instancetype)init
+ (BOOL)requiresMainQueueSetup
{
// We're only overriding this to ensure the module gets created at startup
// TODO (t11106126): Remove once we have more declarative control over module setup.
return [super init];
return YES;
}
- (dispatch_queue_t)methodQueue