mirror of
https://github.com/zhigang1992/react-native.git
synced 2026-04-23 11:57:46 +08:00
Bunch of utility funcs were moved to RCTUIManagerUtils
Summary: Because `RCTUIManager` is already overcomplicated and that stuff deserves separate file and header. Reviewed By: javache Differential Revision: D5856653 fbshipit-source-id: 7001bb8ba611976bf3b82d6a25f5619810a35b34
This commit is contained in:
committed by
Facebook Github Bot
parent
34487c0591
commit
6d67e2dbbc
@@ -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.
|
||||
|
||||
@@ -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"
|
||||
@@ -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
|
||||
@@ -239,32 +239,6 @@ static NSDictionary *deviceOrientationEventBody(UIDeviceOrientation orientation)
|
||||
}
|
||||
#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();
|
||||
|
||||
49
React/Modules/RCTUIManagerUtils.h
Normal file
49
React/Modules/RCTUIManagerUtils.h
Normal file
@@ -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
React/Modules/RCTUIManagerUtils.m
Normal file
62
React/Modules/RCTUIManagerUtils.m
Normal file
@@ -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();
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user