From 59378f71dbc059bb6d8eb75cf86148012a20ba09 Mon Sep 17 00:00:00 2001 From: Pieter De Baets Date: Fri, 21 Apr 2017 06:53:28 -0700 Subject: [PATCH] Immediately trigger renderApplication from RCTRootView init Reviewed By: fkgozali Differential Revision: D4849610 fbshipit-source-id: 291a9bcdf0efe47d83130fe2675f3ef04a3f085b --- .../UIExplorerUnitTests/RCTComponentPropsTests.m | 1 + React/Base/RCTRootContentView.h | 6 ++++-- React/Base/RCTRootContentView.m | 1 - React/Base/RCTRootView.m | 12 +++++++----- React/Modules/RCTUIManager.m | 2 +- 5 files changed, 13 insertions(+), 9 deletions(-) diff --git a/Examples/UIExplorer/UIExplorerUnitTests/RCTComponentPropsTests.m b/Examples/UIExplorer/UIExplorerUnitTests/RCTComponentPropsTests.m index 17ed2be2f6..b6ab4b7697 100644 --- a/Examples/UIExplorer/UIExplorerUnitTests/RCTComponentPropsTests.m +++ b/Examples/UIExplorer/UIExplorerUnitTests/RCTComponentPropsTests.m @@ -99,6 +99,7 @@ RCT_CUSTOM_VIEW_PROPERTY(customProp, NSString, RCTPropsTestView) _bridge = [[RCTBridge alloc] initWithBundleURL:[bundle URLForResource:@"UIExplorerUnitTestsBundle" withExtension:@"js"] moduleProvider:nil launchOptions:nil]; + RUN_RUNLOOP_WHILE(_bridge.isLoading); } - (void)testSetProps diff --git a/React/Base/RCTRootContentView.h b/React/Base/RCTRootContentView.h index f405a85506..f667085e7a 100644 --- a/React/Base/RCTRootContentView.h +++ b/React/Base/RCTRootContentView.h @@ -18,11 +18,13 @@ @interface RCTRootContentView : RCTView -@property (nonatomic, readonly) BOOL contentHasAppeared; +@property (nonatomic, readonly, weak) RCTBridge *bridge; +@property (nonatomic, readonly, assign) BOOL contentHasAppeared; @property (nonatomic, readonly, strong) RCTTouchHandler *touchHandler; +@property (nonatomic, readonly, assign) CGSize availableSize; + @property (nonatomic, assign) BOOL passThroughTouches; @property (nonatomic, assign) RCTRootViewSizeFlexibility sizeFlexibility; -@property (nonatomic, readonly) CGSize availableSize; - (instancetype)initWithFrame:(CGRect)frame bridge:(RCTBridge *)bridge diff --git a/React/Base/RCTRootContentView.m b/React/Base/RCTRootContentView.m index f4fb62b532..57ebdd201e 100644 --- a/React/Base/RCTRootContentView.m +++ b/React/Base/RCTRootContentView.m @@ -19,7 +19,6 @@ @implementation RCTRootContentView { - __weak RCTBridge *_bridge; UIColor *_backgroundColor; } diff --git a/React/Base/RCTRootView.m b/React/Base/RCTRootView.m index 9870ebfaee..e077c51417 100644 --- a/React/Base/RCTRootView.m +++ b/React/Base/RCTRootView.m @@ -92,11 +92,10 @@ NSString *const RCTContentDidAppearNotification = @"RCTContentDidAppearNotificat } #endif - if (!_bridge.loading) { - [self bundleFinishedLoading:([_bridge batchedBridge] ?: _bridge)]; - } - [self showLoadingView]; + + // Immediately schedule the application to be started + [self bundleFinishedLoading:[_bridge batchedBridge]]; } RCT_PROFILE_END_EVENT(RCTProfileTagAlways, @""); @@ -259,11 +258,14 @@ RCT_NOT_IMPLEMENTED(- (instancetype)initWithCoder:(NSCoder *)aDecoder) // Use the (batched) bridge that's sent in the notification payload, so the // RCTRootContentView is scoped to the right bridge RCTBridge *bridge = notification.userInfo[@"bridge"]; - [self bundleFinishedLoading:bridge]; + if (bridge != _contentView.bridge) { + [self bundleFinishedLoading:bridge]; + } } - (void)bundleFinishedLoading:(RCTBridge *)bridge { + RCTAssert(bridge != nil, @"Bridge cannot be nil"); if (!bridge.valid) { return; } diff --git a/React/Modules/RCTUIManager.m b/React/Modules/RCTUIManager.m index ea7e59803e..38d0930226 100644 --- a/React/Modules/RCTUIManager.m +++ b/React/Modules/RCTUIManager.m @@ -1207,7 +1207,7 @@ RCT_EXPORT_METHOD(dispatchViewManagerCommand:(nonnull NSNumber *)reactTag { // If there is an active batch layout will happen when batch finished, so we will wait for that. // Otherwise we immidiately trigger layout. - if (![_bridge isBatchActive]) { + if (![_bridge isBatchActive] && ![_bridge isLoading]) { [self _layoutAndMount]; } }