Skip to content

Commit

Permalink
Allow RCTRootView to be initialized with a frame
Browse files Browse the repository at this point in the history
Summary:
If a root view is initialized with a bridge that is already loaded, then it immediately will initialize its content view with a zero size, which results in that content view's size being calculated according to its content instead of the size set on the root view after initialization. This would lead to a race condition where sometimes the content view has a smaller size than the root view.

Changelog:
[iOS][Added] - Allow RCTRootView to be initialized with a frame

Reviewed By: PeteTheHeat

Differential Revision: D27052637

fbshipit-source-id: 384ab3be27c92c0d84d34d49afb697882335d890
  • Loading branch information
appden authored and facebook-github-bot committed Mar 16, 2021
1 parent cbc3d90 commit 00bc09c
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 5 deletions.
11 changes: 10 additions & 1 deletion React/Base/RCTRootView.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,18 @@ extern
/**
* - Designated initializer -
*/
- (instancetype)initWithFrame:(CGRect)frame
bridge:(RCTBridge *)bridge
moduleName:(NSString *)moduleName
initialProperties:(nullable NSDictionary *)initialProperties NS_DESIGNATED_INITIALIZER;

/**
* - Convenience initializer -
* The frame will default to CGRectZero.
*/
- (instancetype)initWithBridge:(RCTBridge *)bridge
moduleName:(NSString *)moduleName
initialProperties:(nullable NSDictionary *)initialProperties NS_DESIGNATED_INITIALIZER;
initialProperties:(nullable NSDictionary *)initialProperties;

/**
* - Convenience initializer -
Expand Down
16 changes: 12 additions & 4 deletions React/Base/RCTRootView.m
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,10 @@ @implementation RCTRootView {
CGSize _intrinsicContentSize;
}

- (instancetype)initWithBridge:(RCTBridge *)bridge
moduleName:(NSString *)moduleName
initialProperties:(NSDictionary *)initialProperties
- (instancetype)initWithFrame:(CGRect)frame
bridge:(RCTBridge *)bridge
moduleName:(NSString *)moduleName
initialProperties:(NSDictionary *)initialProperties
{
RCTAssertMainQueue();
RCTAssert(bridge, @"A bridge instance is required to create an RCTRootView");
Expand All @@ -57,7 +58,7 @@ - (instancetype)initWithBridge:(RCTBridge *)bridge
[bridge.performanceLogger markStartForTag:RCTPLTTI];
}

if (self = [super initWithFrame:CGRectZero]) {
if (self = [super initWithFrame:frame]) {
self.backgroundColor = [UIColor whiteColor];

_bridge = bridge;
Expand Down Expand Up @@ -95,6 +96,13 @@ - (instancetype)initWithBridge:(RCTBridge *)bridge
return self;
}

- (instancetype)initWithBridge:(RCTBridge *)bridge
moduleName:(NSString *)moduleName
initialProperties:(NSDictionary *)initialProperties
{
return [self initWithFrame:CGRectZero bridge:bridge moduleName:moduleName initialProperties:initialProperties];
}

- (instancetype)initWithBundleURL:(NSURL *)bundleURL
moduleName:(NSString *)moduleName
initialProperties:(NSDictionary *)initialProperties
Expand Down

0 comments on commit 00bc09c

Please sign in to comment.