Permalink
Browse files

Configure requiresMainQueueSetup for core modules

Reviewed By: fkgozali

Differential Revision: D5528305

fbshipit-source-id: f17cad933685be09784b2246f44baf252bfa5a26
  • Loading branch information...
javache authored and facebook-github-bot committed Aug 7, 2017
1 parent d42ccca commit 220034c4d4c8a52f424e05c291a62b63b74447f3
@@ -32,6 +32,11 @@ @implementation RCTBlobManager
@synthesize bridge = _bridge;
+ (BOOL)requiresMainQueueSetup
{
return NO;
}
- (NSDictionary<NSString *, id> *)constantsToExport
{
return @{
@@ -24,38 +24,40 @@ @implementation RCTSettingsManager
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
- (void)dealloc
{
_bridge = bridge;
if (!_defaults) {
_defaults = [NSUserDefaults standardUserDefaults];
}
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(userDefaultsDidChange:)
name:NSUserDefaultsDidChangeNotification
object:_defaults];
[[NSNotificationCenter defaultCenter] removeObserver:self];
}
- (NSDictionary<NSString *, id> *)constantsToExport
{
return @{@"settings": RCTJSONClean([_defaults dictionaryRepresentation])};
}
- (void)dealloc
{
[[NSNotificationCenter defaultCenter] removeObserver:self];
}
- (void)userDefaultsDidChange:(NSNotification *)note
{
if (_ignoringUpdates) {
@@ -71,7 +71,6 @@ - (void)dealloc
@end
@interface RCTModuleInitNotificationRaceTests : XCTestCase <RCTBridgeDelegate>
{
RCTBridge *_bridge;
@@ -98,6 +97,10 @@ - (void)setUp
_notificationObserver = [RCTNotificationObserverModule new];
_bridge = [[RCTBridge alloc] initWithDelegate:self launchOptions:nil];
dispatch_async(dispatch_get_main_queue(), ^{
[[self->_bridge uiManager] constantsToExport];
});
}
- (void)tearDown
View
@@ -13,8 +13,6 @@
#import "RCTUtils.h"
@implementation RCTPlatform
static NSString *interfaceIdiom(UIUserInterfaceIdiom idiom) {
switch(idiom) {
case UIUserInterfaceIdiomPhone:
@@ -30,8 +28,15 @@ @implementation RCTPlatform
}
}
@implementation RCTPlatform
RCT_EXPORT_MODULE(PlatformConstants)
+ (BOOL)requiresMainQueueSetup
{
return YES;
}
- (NSDictionary<NSString *, id> *)constantsToExport
{
UIDevice *device = [UIDevice currentDevice];
@@ -41,11 +41,9 @@ - (void)dealloc
[[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
@@ -99,6 +99,11 @@ + (void)initialize
RCTSwapInstanceMethods([UIWindow class], @selector(motionEnded:withEvent:), @selector(RCT_motionEnded:withEvent:));
}
+ (BOOL)requiresMainQueueSetup
{
return YES;
}
- (instancetype)init
{
if ((self = [super init])) {
@@ -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 @@ @implementation RCTAccessibilityManager
@"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 @@ - (instancetype)init
selector:@selector(didReceiveNewVoiceOverStatus:)
name:UIAccessibilityVoiceOverStatusChanged
object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(accessibilityAnnouncementDidFinish:)
name:UIAccessibilityAnnouncementDidFinishNotification
@@ -112,7 +112,7 @@ - (void)accessibilityAnnouncementDidFinish:(__unused NSNotification *)notificati
// 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 @@ - (void)setMultipliers:(NSDictionary<NSString *, NSNumber *> *)multipliers
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;
@@ -16,8 +16,6 @@
static NSString *RCTCurrentAppBackgroundState()
{
RCTAssertMainQueue();
static NSDictionary *states;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
@@ -41,6 +39,13 @@ @implementation RCTAppState
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();
@@ -132,6 +132,11 @@ @implementation RCTDevSettings
RCT_EXPORT_MODULE()
+ (BOOL)requiresMainQueueSetup
{
return YES; // RCT_DEV-only
}
- (instancetype)init
{
// default behavior is to use NSUserDefaults
@@ -24,6 +24,11 @@ @implementation RCTDeviceInfo {
RCT_EXPORT_MODULE()
+ (BOOL)requiresMainQueueSetup
{
return YES;
}
- (dispatch_queue_t)methodQueue
{
return dispatch_get_main_queue();
@@ -14,6 +14,11 @@ @implementation RCTI18nManager
RCT_EXPORT_MODULE()
+ (BOOL)requiresMainQueueSetup
{
return NO;
}
RCT_EXPORT_METHOD(allowRTL:(BOOL)value)
{
[[RCTI18nUtil sharedInstance] allowRTL:value];
@@ -17,6 +17,11 @@ @implementation RCTSourceCode
@synthesize bridge = _bridge;
+ (BOOL)requiresMainQueueSetup
{
return NO;
}
- (NSDictionary<NSString *, id> *)constantsToExport
{
return @{
@@ -77,6 +77,11 @@ @implementation RCTUIManager
RCT_EXPORT_MODULE()
+ (BOOL)requiresMainQueueSetup
{
return NO;
}
- (void)invalidate
{
/**
@@ -131,11 +131,9 @@ @implementation RCTPerfMonitor {
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

0 comments on commit 220034c

Please sign in to comment.