Skip to content

Commit

Permalink
Bunch of utility funcs were moved to RCTUIManagerUtils
Browse files Browse the repository at this point in the history
Summary: Because `RCTUIManager` is already overcomplicated and that stuff deserves separate file and header.

Reviewed By: javache

Differential Revision: D5856653

fbshipit-source-id: 7001bb8ba611976bf3b82d6a25f5619810a35b34
  • Loading branch information
shergin authored and facebook-github-bot committed Sep 26, 2017
1 parent 34487c0 commit 6d67e2d
Show file tree
Hide file tree
Showing 9 changed files with 154 additions and 55 deletions.
1 change: 1 addition & 0 deletions Libraries/NativeAnimation/RCTNativeAnimatedModule.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#import <React/RCTEventEmitter.h>
#import <React/RCTUIManager.h>
#import <React/RCTUIManagerObserverCoordinator.h>
#import <React/RCTUIManagerUtils.h>

#import "RCTValueAnimatedNode.h"

Expand Down
21 changes: 0 additions & 21 deletions React/Modules/RCTUIManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,27 +15,6 @@
#import <React/RCTRootView.h>
#import <React/RCTViewManager.h>

/**
* UIManager queue
*/
RCT_EXTERN dispatch_queue_t RCTGetUIManagerQueue(void);

/**
* Default name for the UIManager queue
*/
RCT_EXTERN char *const RCTUIManagerQueueName;

/**
* Check if we are currently on UIManager queue.
*/
RCT_EXTERN BOOL RCTIsUIManagerQueue(void);

/**
* Convenience macro for asserting that we're running on UIManager queue.
*/
#define RCTAssertUIManagerQueue() RCTAssert(RCTIsUIManagerQueue(), \
@"This function must be called on the UIManager queue")

/**
* Posted right before re-render happens. This is a chance for views to invalidate their state so
* next render cycle will pick up updated views and layout appropriately.
Expand Down
28 changes: 1 addition & 27 deletions React/Modules/RCTUIManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
#import "RCTShadowView+Internal.h"
#import "RCTShadowView.h"
#import "RCTUIManagerObserverCoordinator.h"
#import "RCTUIManagerUtils.h"
#import "RCTUtils.h"
#import "RCTView.h"
#import "RCTViewManager.h"
Expand All @@ -52,7 +53,6 @@ static void RCTTraverseViewNodes(id<RCTComponent> view, void (^block)(id<RCTComp
}
}

char *const RCTUIManagerQueueName = "com.facebook.react.ShadowQueue";
NSString *const RCTUIManagerWillUpdateViewsDueToContentSizeMultiplierChangeNotification = @"RCTUIManagerWillUpdateViewsDueToContentSizeMultiplierChangeNotification";

@implementation RCTUIManager
Expand Down Expand Up @@ -239,32 +239,6 @@ - (void)namedOrientationDidChange
}
#endif

dispatch_queue_t RCTGetUIManagerQueue(void)
{
static dispatch_queue_t shadowQueue;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
if ([NSOperation instancesRespondToSelector:@selector(qualityOfService)]) {
dispatch_queue_attr_t attr = dispatch_queue_attr_make_with_qos_class(DISPATCH_QUEUE_SERIAL, QOS_CLASS_USER_INTERACTIVE, 0);
shadowQueue = dispatch_queue_create(RCTUIManagerQueueName, attr);
} else {
shadowQueue = dispatch_queue_create(RCTUIManagerQueueName, DISPATCH_QUEUE_SERIAL);
dispatch_set_target_queue(shadowQueue, dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0));
}
});
return shadowQueue;
}

BOOL RCTIsUIManagerQueue()
{
static void *queueKey = &queueKey;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
dispatch_queue_set_specific(RCTGetUIManagerQueue(), queueKey, queueKey, NULL);
});
return dispatch_get_specific(queueKey) == queueKey;
}

- (dispatch_queue_t)methodQueue
{
return RCTGetUIManagerQueue();
Expand Down
49 changes: 49 additions & 0 deletions React/Modules/RCTUIManagerUtils.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/**
* Copyright (c) 2015-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*/

#import <UIKit/UIKit.h>

#import <React/RCTAssert.h>
#import <React/RCTDefines.h>

/**
* Returns UIManager queue.
*/
RCT_EXTERN dispatch_queue_t RCTGetUIManagerQueue(void);

/**
* Default name for the UIManager queue.
*/
RCT_EXTERN char *const RCTUIManagerQueueName;

/**
* Check if we are currently on UIManager queue.
*/
RCT_EXTERN BOOL RCTIsUIManagerQueue(void);

/**
* *Asynchronously* executes the specified block on the UIManager queue.
* Unlike `dispatch_async()` this will execute the block immediately
* if we're already on the UIManager queue.
*/
RCT_EXTERN void RCTExecuteOnUIManagerQueue(dispatch_block_t block);

/**
* *Synchorously* executes the specified block on the UIManager queue.
* Unlike `dispatch_sync()` this will execute the block immediately
* if we're already on the UIManager queue.
* Please do not use this unless you really know what you're doing.
*/
RCT_EXTERN void RCTUnsafeExecuteOnUIManagerQueueSync(dispatch_block_t block);

/**
* Convenience macro for asserting that we're running on UIManager queue.
*/
#define RCTAssertUIManagerQueue() RCTAssert(RCTIsUIManagerQueue(), \
@"This function must be called on the UIManager queue")
62 changes: 62 additions & 0 deletions React/Modules/RCTUIManagerUtils.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
/**
* Copyright (c) 2015-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*/

#import "RCTUIManagerUtils.h"

#import "RCTAssert.h"

char *const RCTUIManagerQueueName = "com.facebook.react.ShadowQueue";

dispatch_queue_t RCTGetUIManagerQueue(void)
{
static dispatch_queue_t shadowQueue;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
if ([NSOperation instancesRespondToSelector:@selector(qualityOfService)]) {
dispatch_queue_attr_t attr = dispatch_queue_attr_make_with_qos_class(DISPATCH_QUEUE_SERIAL, QOS_CLASS_USER_INTERACTIVE, 0);
shadowQueue = dispatch_queue_create(RCTUIManagerQueueName, attr);
} else {
shadowQueue = dispatch_queue_create(RCTUIManagerQueueName, DISPATCH_QUEUE_SERIAL);
dispatch_set_target_queue(shadowQueue, dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0));
}
});
return shadowQueue;
}

BOOL RCTIsUIManagerQueue()
{
static void *queueKey = &queueKey;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
dispatch_queue_set_specific(RCTGetUIManagerQueue(), queueKey, queueKey, NULL);
});
return dispatch_get_specific(queueKey) == queueKey;
}

void RCTExecuteOnUIManagerQueue(dispatch_block_t block)
{
if (RCTIsUIManagerQueue()) {
block();
} else {
dispatch_async(RCTGetUIManagerQueue(), ^{
block();
});
}
}

void RCTUnsafeExecuteOnUIManagerQueueSync(dispatch_block_t block)
{
if (RCTIsUIManagerQueue()) {
block();
} else {
dispatch_sync(RCTGetUIManagerQueue(), ^{
block();
});
}
}
3 changes: 2 additions & 1 deletion React/Profiler/RCTProfile.m
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@
#import "RCTProfile.h"

#import <dlfcn.h>
#import <stdatomic.h>
#import <mach/mach.h>
#import <objc/message.h>
#import <objc/runtime.h>
#import <stdatomic.h>

#import <UIKit/UIKit.h>

Expand All @@ -25,6 +25,7 @@
#import "RCTLog.h"
#import "RCTModuleData.h"
#import "RCTUIManager.h"
#import "RCTUIManagerUtils.h"
#import "RCTUtils.h"

NSString *const RCTProfileDidStartProfiling = @"RCTProfileDidStartProfiling";
Expand Down
16 changes: 16 additions & 0 deletions React/React.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -999,6 +999,12 @@
590D7BFE1EBD458B00D8A370 /* RCTShadowView+Layout.h in Headers */ = {isa = PBXBuildFile; fileRef = 590D7BFB1EBD458B00D8A370 /* RCTShadowView+Layout.h */; };
590D7BFF1EBD458B00D8A370 /* RCTShadowView+Layout.m in Sources */ = {isa = PBXBuildFile; fileRef = 590D7BFC1EBD458B00D8A370 /* RCTShadowView+Layout.m */; };
590D7C001EBD458B00D8A370 /* RCTShadowView+Layout.m in Sources */ = {isa = PBXBuildFile; fileRef = 590D7BFC1EBD458B00D8A370 /* RCTShadowView+Layout.m */; };
59500D431F71C63F00B122B7 /* RCTUIManagerUtils.h in Headers */ = {isa = PBXBuildFile; fileRef = 59500D411F71C63700B122B7 /* RCTUIManagerUtils.h */; };
59500D441F71C63F00B122B7 /* RCTUIManagerUtils.h in Headers */ = {isa = PBXBuildFile; fileRef = 59500D411F71C63700B122B7 /* RCTUIManagerUtils.h */; };
59500D451F71C63F00B122B7 /* RCTUIManagerUtils.m in Sources */ = {isa = PBXBuildFile; fileRef = 59500D421F71C63F00B122B7 /* RCTUIManagerUtils.m */; };
59500D461F71C63F00B122B7 /* RCTUIManagerUtils.m in Sources */ = {isa = PBXBuildFile; fileRef = 59500D421F71C63F00B122B7 /* RCTUIManagerUtils.m */; };
59500D471F71C66700B122B7 /* RCTUIManagerUtils.h in Copy Headers */ = {isa = PBXBuildFile; fileRef = 59500D411F71C63700B122B7 /* RCTUIManagerUtils.h */; };
59500D481F71C67600B122B7 /* RCTUIManagerUtils.h in Copy Headers */ = {isa = PBXBuildFile; fileRef = 59500D411F71C63700B122B7 /* RCTUIManagerUtils.h */; };
5960C1B51F0804A00066FD5B /* RCTLayoutAnimation.h in Headers */ = {isa = PBXBuildFile; fileRef = 5960C1B11F0804A00066FD5B /* RCTLayoutAnimation.h */; };
5960C1B61F0804A00066FD5B /* RCTLayoutAnimation.h in Headers */ = {isa = PBXBuildFile; fileRef = 5960C1B11F0804A00066FD5B /* RCTLayoutAnimation.h */; };
5960C1B71F0804A00066FD5B /* RCTLayoutAnimation.m in Sources */ = {isa = PBXBuildFile; fileRef = 5960C1B21F0804A00066FD5B /* RCTLayoutAnimation.m */; };
Expand Down Expand Up @@ -1250,6 +1256,7 @@
dstPath = include/React;
dstSubfolderSpec = 16;
files = (
59500D481F71C67600B122B7 /* RCTUIManagerUtils.h in Copy Headers */,
3D0E37901F1CC5E100DCAC9F /* RCTWebSocketModule.h in Copy Headers */,
5960C1BF1F0804F50066FD5B /* RCTLayoutAnimation.h in Copy Headers */,
5960C1C01F0804F50066FD5B /* RCTLayoutAnimationGroup.h in Copy Headers */,
Expand Down Expand Up @@ -1471,6 +1478,7 @@
dstPath = include/React;
dstSubfolderSpec = 16;
files = (
59500D471F71C66700B122B7 /* RCTUIManagerUtils.h in Copy Headers */,
3D0E378F1F1CC5CF00DCAC9F /* RCTWebSocketModule.h in Copy Headers */,
5960C1BD1F0804DF0066FD5B /* RCTLayoutAnimation.h in Copy Headers */,
5960C1BE1F0804DF0066FD5B /* RCTLayoutAnimationGroup.h in Copy Headers */,
Expand Down Expand Up @@ -2029,6 +2037,8 @@
58C571C01AA56C1900CDF9C8 /* RCTDatePickerManager.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; lineEnding = 0; path = RCTDatePickerManager.h; sourceTree = "<group>"; xcLanguageSpecificationIdentifier = xcode.lang.objcpp; };
590D7BFB1EBD458B00D8A370 /* RCTShadowView+Layout.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "RCTShadowView+Layout.h"; sourceTree = "<group>"; };
590D7BFC1EBD458B00D8A370 /* RCTShadowView+Layout.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "RCTShadowView+Layout.m"; sourceTree = "<group>"; };
59500D411F71C63700B122B7 /* RCTUIManagerUtils.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RCTUIManagerUtils.h; sourceTree = "<group>"; };
59500D421F71C63F00B122B7 /* RCTUIManagerUtils.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RCTUIManagerUtils.m; sourceTree = "<group>"; };
5960C1B11F0804A00066FD5B /* RCTLayoutAnimation.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RCTLayoutAnimation.h; sourceTree = "<group>"; };
5960C1B21F0804A00066FD5B /* RCTLayoutAnimation.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RCTLayoutAnimation.m; sourceTree = "<group>"; };
5960C1B31F0804A00066FD5B /* RCTLayoutAnimationGroup.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RCTLayoutAnimationGroup.h; sourceTree = "<group>"; };
Expand Down Expand Up @@ -2337,6 +2347,8 @@
13E067491A70F434002CDEE1 /* RCTUIManager.m */,
59EB6DB91EBD6FC90072A5E7 /* RCTUIManagerObserverCoordinator.h */,
59EB6DBA1EBD6FC90072A5E7 /* RCTUIManagerObserverCoordinator.mm */,
59500D411F71C63700B122B7 /* RCTUIManagerUtils.h */,
59500D421F71C63F00B122B7 /* RCTUIManagerUtils.m */,
);
path = Modules;
sourceTree = "<group>";
Expand Down Expand Up @@ -2902,6 +2914,7 @@
3D7BFD221EA8E351008DFB7A /* RCTReloadPackagerMethod.h in Headers */,
3D302F4D1DF828F800D6DDAE /* RCTURLRequestDelegate.h in Headers */,
3D302F4E1DF828F800D6DDAE /* RCTURLRequestHandler.h in Headers */,
59500D441F71C63F00B122B7 /* RCTUIManagerUtils.h in Headers */,
3D302F4F1DF828F800D6DDAE /* RCTUtils.h in Headers */,
3D302F541DF828F800D6DDAE /* RCTJSCSamplingProfiler.h in Headers */,
3D302F551DF828F800D6DDAE /* RCTAccessibilityManager.h in Headers */,
Expand Down Expand Up @@ -3221,6 +3234,7 @@
3D80DA5E1DF820620028D040 /* RCTProfile.h in Headers */,
3D80DA5F1DF820620028D040 /* RCTActivityIndicatorView.h in Headers */,
3D80DA601DF820620028D040 /* RCTActivityIndicatorViewManager.h in Headers */,
59500D431F71C63F00B122B7 /* RCTUIManagerUtils.h in Headers */,
5960C1B91F0804A00066FD5B /* RCTLayoutAnimationGroup.h in Headers */,
C6194AB01EF156280034D062 /* RCTPackagerConnectionConfig.h in Headers */,
CF2731C01E7B8DE40044CA4F /* RCTDeviceInfo.h in Headers */,
Expand Down Expand Up @@ -3778,6 +3792,7 @@
2D3B5EAE1D9B08F800451313 /* RCTEventEmitter.m in Sources */,
2D3B5ECA1D9B095F00451313 /* RCTComponentData.m in Sources */,
2D3B5EA31D9B08BE00451313 /* RCTParserUtils.m in Sources */,
59500D461F71C63F00B122B7 /* RCTUIManagerUtils.m in Sources */,
2D3B5EA01D9B08B200451313 /* RCTLog.mm in Sources */,
2D3B5EE21D9B09B400451313 /* RCTScrollViewManager.m in Sources */,
5960C1BC1F0804A00066FD5B /* RCTLayoutAnimationGroup.m in Sources */,
Expand Down Expand Up @@ -4023,6 +4038,7 @@
buildActionMask = 2147483647;
files = (
13134C9A1E296B2A00B9F3CB /* RCTCxxMethod.mm in Sources */,
59500D451F71C63F00B122B7 /* RCTUIManagerUtils.m in Sources */,
597633361F4E021D005BE8A4 /* RCTShadowView+Internal.m in Sources */,
59FBEFB61E46D91C0095D885 /* RCTScrollContentViewManager.m in Sources */,
13723B501A82FD3C00F88898 /* RCTStatusBarManager.m in Sources */,
Expand Down
Loading

0 comments on commit 6d67e2d

Please sign in to comment.