Skip to content

Commit

Permalink
Configure requiresMainQueueSetup for core modules
Browse files Browse the repository at this point in the history
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 220034c
Show file tree
Hide file tree
Showing 14 changed files with 96 additions and 50 deletions.
5 changes: 5 additions & 0 deletions Libraries/Blob/RCTBlobManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@ @implementation RCTBlobManager

@synthesize bridge = _bridge;

+ (BOOL)requiresMainQueueSetup
{
return NO;
}

- (NSDictionary<NSString *, id> *)constantsToExport
{
return @{
Expand Down
34 changes: 18 additions & 16 deletions Libraries/Settings/RCTSettingsManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@ - (void)dealloc

@end


@interface RCTModuleInitNotificationRaceTests : XCTestCase <RCTBridgeDelegate>
{
RCTBridge *_bridge;
Expand All @@ -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
Expand Down
9 changes: 7 additions & 2 deletions React/Base/RCTPlatform.m
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@

#import "RCTUtils.h"

@implementation RCTPlatform

static NSString *interfaceIdiom(UIUserInterfaceIdiom idiom) {
switch(idiom) {
case UIUserInterfaceIdiomPhone:
Expand All @@ -30,8 +28,15 @@ @implementation RCTPlatform
}
}

@implementation RCTPlatform

RCT_EXPORT_MODULE(PlatformConstants)

+ (BOOL)requiresMainQueueSetup
{
return YES;
}

- (NSDictionary<NSString *, id> *)constantsToExport
{
UIDevice *device = [UIDevice currentDevice];
Expand Down
6 changes: 2 additions & 4 deletions React/DevSupport/RCTDevLoadingView.m
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions React/DevSupport/RCTDevMenu.m
Original file line number Diff line number Diff line change
Expand Up @@ -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])) {
Expand Down
42 changes: 21 additions & 21 deletions React/Modules/RCTAccessibilityManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
Expand All @@ -71,7 +71,7 @@ - (instancetype)init
selector:@selector(didReceiveNewVoiceOverStatus:)
name:UIAccessibilityVoiceOverStatusChanged
object:nil];

[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(accessibilityAnnouncementDidFinish:)
name:UIAccessibilityAnnouncementDidFinishNotification
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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;
Expand Down
9 changes: 7 additions & 2 deletions React/Modules/RCTAppState.m
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@

static NSString *RCTCurrentAppBackgroundState()
{
RCTAssertMainQueue();

static NSDictionary *states;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
Expand All @@ -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();
Expand Down
5 changes: 5 additions & 0 deletions React/Modules/RCTDevSettings.mm
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,11 @@ @implementation RCTDevSettings

RCT_EXPORT_MODULE()

+ (BOOL)requiresMainQueueSetup
{
return YES; // RCT_DEV-only
}

- (instancetype)init
{
// default behavior is to use NSUserDefaults
Expand Down
5 changes: 5 additions & 0 deletions React/Modules/RCTDeviceInfo.m
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@ @implementation RCTDeviceInfo {

RCT_EXPORT_MODULE()

+ (BOOL)requiresMainQueueSetup
{
return YES;
}

- (dispatch_queue_t)methodQueue
{
return dispatch_get_main_queue();
Expand Down
5 changes: 5 additions & 0 deletions React/Modules/RCTI18nManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@ @implementation RCTI18nManager

RCT_EXPORT_MODULE()

+ (BOOL)requiresMainQueueSetup
{
return NO;
}

RCT_EXPORT_METHOD(allowRTL:(BOOL)value)
{
[[RCTI18nUtil sharedInstance] allowRTL:value];
Expand Down
5 changes: 5 additions & 0 deletions React/Modules/RCTSourceCode.m
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ @implementation RCTSourceCode

@synthesize bridge = _bridge;

+ (BOOL)requiresMainQueueSetup
{
return NO;
}

- (NSDictionary<NSString *, id> *)constantsToExport
{
return @{
Expand Down
5 changes: 5 additions & 0 deletions React/Modules/RCTUIManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,11 @@ @implementation RCTUIManager

RCT_EXPORT_MODULE()

+ (BOOL)requiresMainQueueSetup
{
return NO;
}

- (void)invalidate
{
/**
Expand Down
6 changes: 2 additions & 4 deletions React/Profiler/RCTPerfMonitor.m
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 220034c

Please sign in to comment.