@@ -91,7 +91,7 @@ static UIViewAnimationOptions UIViewAnimationOptionsFromRCTAnimationType(RCTAnim
91
91
92
92
// Use a custom initialization function rather than implementing `+initialize` so that we can control
93
93
// when the initialization code runs. `+initialize` runs immediately before the first message is sent
94
- // to the class which may be too late for us. By this time, we may have missed some
94
+ // to the class which may be too late for us. By this time, we may have missed some
95
95
// `UIKeyboardWillChangeFrameNotification`s.
96
96
+ (void )initializeStatics
97
97
{
@@ -208,8 +208,6 @@ - (instancetype)initWithDictionary:(NSDictionary *)config callback:(RCTResponseS
208
208
209
209
@implementation RCTUIManager
210
210
{
211
- dispatch_queue_t _shadowQueue;
212
-
213
211
// Root views are only mutated on the shadow queue
214
212
NSMutableSet <NSNumber *> *_rootViewTags;
215
213
NSMutableArray <dispatch_block_t > *_pendingUIBlocks;
@@ -235,7 +233,7 @@ @implementation RCTUIManager
235
233
- (void )didReceiveNewContentSizeMultiplier
236
234
{
237
235
__weak RCTUIManager *weakSelf = self;
238
- dispatch_async (self. methodQueue , ^{
236
+ dispatch_async (RCTGetUIManagerQueue () , ^{
239
237
RCTUIManager *strongSelf = weakSelf;
240
238
if (strongSelf) {
241
239
[[NSNotificationCenter defaultCenter ] postNotificationName: RCTUIManagerWillUpdateViewsDueToContentSizeMultiplierChangeNotification
@@ -342,22 +340,29 @@ - (void)setBridge:(RCTBridge *)bridge
342
340
selector: @selector (interfaceOrientationWillChange: )
343
341
name: UIApplicationWillChangeStatusBarOrientationNotification
344
342
object: nil ];
345
-
343
+
346
344
[RCTAnimation initializeStatics ];
347
345
}
348
346
349
- - ( dispatch_queue_t ) methodQueue
347
+ dispatch_queue_t RCTGetUIManagerQueue ( void )
350
348
{
351
- if (!_shadowQueue) {
349
+ static dispatch_queue_t shadowQueue;
350
+ static dispatch_once_t onceToken;
351
+ dispatch_once (&onceToken, ^{
352
352
if ([NSOperation instancesRespondToSelector: @selector (qualityOfService )]) {
353
353
dispatch_queue_attr_t attr = dispatch_queue_attr_make_with_qos_class (DISPATCH_QUEUE_SERIAL, QOS_CLASS_USER_INTERACTIVE, 0 );
354
- _shadowQueue = dispatch_queue_create (RCTUIManagerQueueName, attr);
354
+ shadowQueue = dispatch_queue_create (RCTUIManagerQueueName, attr);
355
355
} else {
356
- _shadowQueue = dispatch_queue_create (RCTUIManagerQueueName, DISPATCH_QUEUE_SERIAL);
357
- dispatch_set_target_queue (_shadowQueue , dispatch_get_global_queue (DISPATCH_QUEUE_PRIORITY_HIGH, 0 ));
356
+ shadowQueue = dispatch_queue_create (RCTUIManagerQueueName, DISPATCH_QUEUE_SERIAL);
357
+ dispatch_set_target_queue (shadowQueue , dispatch_get_global_queue (DISPATCH_QUEUE_PRIORITY_HIGH, 0 ));
358
358
}
359
- }
360
- return _shadowQueue;
359
+ });
360
+ return shadowQueue;
361
+ }
362
+
363
+ - (dispatch_queue_t )methodQueue
364
+ {
365
+ return RCTGetUIManagerQueue ();
361
366
}
362
367
363
368
- (void )registerRootView : (UIView *)rootView withSizeFlexibility : (RCTRootViewSizeFlexibility)sizeFlexibility
@@ -378,7 +383,7 @@ - (void)registerRootView:(UIView *)rootView withSizeFlexibility:(RCTRootViewSize
378
383
379
384
// Register shadow view
380
385
__weak RCTUIManager *weakSelf = self;
381
- dispatch_async (_shadowQueue , ^{
386
+ dispatch_async (RCTGetUIManagerQueue () , ^{
382
387
RCTUIManager *strongSelf = weakSelf;
383
388
if (!_viewRegistry) {
384
389
return ;
@@ -419,7 +424,7 @@ - (void)setFrame:(CGRect)frame forView:(UIView *)view
419
424
}
420
425
421
426
NSNumber *reactTag = view.reactTag ;
422
- dispatch_async (_shadowQueue , ^{
427
+ dispatch_async (RCTGetUIManagerQueue () , ^{
423
428
RCTShadowView *shadowView = _shadowViewRegistry[reactTag];
424
429
RCTAssert (shadowView != nil , @" Could not locate shadow view with tag #%@ " , reactTag);
425
430
@@ -452,7 +457,7 @@ - (void)setIntrinsicContentSize:(CGSize)size forView:(UIView *)view
452
457
RCTAssertMainThread ();
453
458
454
459
NSNumber *reactTag = view.reactTag ;
455
- dispatch_async (_shadowQueue , ^{
460
+ dispatch_async (RCTGetUIManagerQueue () , ^{
456
461
RCTShadowView *shadowView = _shadowViewRegistry[reactTag];
457
462
RCTAssert (shadowView != nil , @" Could not locate root view with tag #%@ " , reactTag);
458
463
@@ -469,7 +474,7 @@ - (void)setBackgroundColor:(UIColor *)color forView:(UIView *)view
469
474
NSNumber *reactTag = view.reactTag ;
470
475
471
476
__weak RCTUIManager *weakSelf = self;
472
- dispatch_async (_shadowQueue , ^{
477
+ dispatch_async (RCTGetUIManagerQueue () , ^{
473
478
RCTUIManager *strongSelf = weakSelf;
474
479
if (!_viewRegistry) {
475
480
return ;
@@ -505,9 +510,9 @@ - (void)_purgeChildren:(NSArray<id<RCTComponent>> *)children
505
510
506
511
- (void )addUIBlock : (RCTViewManagerUIBlock)block
507
512
{
508
- RCTAssertThread (_shadowQueue ,
513
+ RCTAssertThread (RCTGetUIManagerQueue () ,
509
514
@" -[RCTUIManager addUIBlock:] should only be called from the "
510
- " UIManager's _shadowQueue (it may be accessed via `bridge.uiManager.methodQueue `)" );
515
+ " UIManager's queue (get this using `RCTGetUIManagerQueue() `)" );
511
516
512
517
if (!block) {
513
518
return ;
@@ -1103,7 +1108,8 @@ - (void)_layoutAndMount
1103
1108
1104
1109
- (void )flushUIBlocks
1105
1110
{
1106
- RCTAssertThread (_shadowQueue, @" flushUIBlocks can only be called from the shadow queue" );
1111
+ RCTAssertThread (RCTGetUIManagerQueue (),
1112
+ @" flushUIBlocks can only be called from the shadow queue" );
1107
1113
1108
1114
// First copy the previous blocks into a temporary variable, then reset the
1109
1115
// pending blocks to a new array. This guards against mutation while
0 commit comments