diff --git a/React/Modules/RCTUIManager.m b/React/Modules/RCTUIManager.m index 8c0a927a0..560ad9de9 100644 --- a/React/Modules/RCTUIManager.m +++ b/React/Modules/RCTUIManager.m @@ -897,7 +897,14 @@ RCT_EXPORT_METHOD(createView:(nonnull NSNumber *)reactTag // the view, but it's the only way that makes sense given our threading model UIColor *backgroundColor = shadowView.backgroundColor; - [self addUIBlock:^(RCTUIManager *uiManager, NSDictionary *viewRegistry){ + // Dispatch view creation directly to the main thread instead of adding to + // UIBlocks array. This way, it doesn't get deferred until after layout. + __weak RCTUIManager *weakManager = self; + dispatch_async(dispatch_get_main_queue(), ^{ + RCTUIManager *uiManager = weakManager; + if (!uiManager) { + return; + } UIView *view = [componentData createViewWithTag:reactTag]; if (view) { [componentData setProps:props forView:view]; // Must be done before bgColor to prevent wrong default @@ -907,13 +914,13 @@ RCT_EXPORT_METHOD(createView:(nonnull NSNumber *)reactTag if ([view respondsToSelector:@selector(reactBridgeDidFinishTransaction)]) { [uiManager->_bridgeTransactionListeners addObject:view]; } - ((NSMutableDictionary *)viewRegistry)[reactTag] = view; + uiManager->_viewRegistry[reactTag] = view; #if RCT_DEV [view _DEBUG_setReactShadowView:shadowView]; #endif } - }]; + }); } RCT_EXPORT_METHOD(updateView:(nonnull NSNumber *)reactTag