Skip to content

Commit 00bc09c

Browse files
appdenfacebook-github-bot
authored andcommitted
Allow RCTRootView to be initialized with a frame
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
1 parent cbc3d90 commit 00bc09c

File tree

2 files changed

+22
-5
lines changed

2 files changed

+22
-5
lines changed

React/Base/RCTRootView.h

+10-1
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,18 @@ extern
5050
/**
5151
* - Designated initializer -
5252
*/
53+
- (instancetype)initWithFrame:(CGRect)frame
54+
bridge:(RCTBridge *)bridge
55+
moduleName:(NSString *)moduleName
56+
initialProperties:(nullable NSDictionary *)initialProperties NS_DESIGNATED_INITIALIZER;
57+
58+
/**
59+
* - Convenience initializer -
60+
* The frame will default to CGRectZero.
61+
*/
5362
- (instancetype)initWithBridge:(RCTBridge *)bridge
5463
moduleName:(NSString *)moduleName
55-
initialProperties:(nullable NSDictionary *)initialProperties NS_DESIGNATED_INITIALIZER;
64+
initialProperties:(nullable NSDictionary *)initialProperties;
5665

5766
/**
5867
* - Convenience initializer -

React/Base/RCTRootView.m

+12-4
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,10 @@ @implementation RCTRootView {
4444
CGSize _intrinsicContentSize;
4545
}
4646

47-
- (instancetype)initWithBridge:(RCTBridge *)bridge
48-
moduleName:(NSString *)moduleName
49-
initialProperties:(NSDictionary *)initialProperties
47+
- (instancetype)initWithFrame:(CGRect)frame
48+
bridge:(RCTBridge *)bridge
49+
moduleName:(NSString *)moduleName
50+
initialProperties:(NSDictionary *)initialProperties
5051
{
5152
RCTAssertMainQueue();
5253
RCTAssert(bridge, @"A bridge instance is required to create an RCTRootView");
@@ -57,7 +58,7 @@ - (instancetype)initWithBridge:(RCTBridge *)bridge
5758
[bridge.performanceLogger markStartForTag:RCTPLTTI];
5859
}
5960

60-
if (self = [super initWithFrame:CGRectZero]) {
61+
if (self = [super initWithFrame:frame]) {
6162
self.backgroundColor = [UIColor whiteColor];
6263

6364
_bridge = bridge;
@@ -95,6 +96,13 @@ - (instancetype)initWithBridge:(RCTBridge *)bridge
9596
return self;
9697
}
9798

99+
- (instancetype)initWithBridge:(RCTBridge *)bridge
100+
moduleName:(NSString *)moduleName
101+
initialProperties:(NSDictionary *)initialProperties
102+
{
103+
return [self initWithFrame:CGRectZero bridge:bridge moduleName:moduleName initialProperties:initialProperties];
104+
}
105+
98106
- (instancetype)initWithBundleURL:(NSURL *)bundleURL
99107
moduleName:(NSString *)moduleName
100108
initialProperties:(NSDictionary *)initialProperties

0 commit comments

Comments
 (0)