-
Notifications
You must be signed in to change notification settings - Fork 24.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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
- Loading branch information
1 parent
34487c0
commit 6d67e2d
Showing
9 changed files
with
154 additions
and
55 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.