Skip to content

Commit

Permalink
iOS: set the default measure size correctly for RCTSurfaceHostingView
Browse files Browse the repository at this point in the history
Summary: The RCTRootView default needs to be translated during init of RCTSurfaceHostingView correctly.

Reviewed By: shergin

Differential Revision: D7327918

fbshipit-source-id: 67a2a42b554782b37a032cc0470d794554cc1e5a
  • Loading branch information
fkgozali authored and facebook-github-bot committed Mar 20, 2018
1 parent b808bfd commit e2462e9
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,10 @@ - (instancetype)initWithBridge:(RCTBridge *)bridge
[bridge.performanceLogger markStartForTag:RCTPLTTI];
}

if (self = [super initWithBridge:bridge moduleName:moduleName initialProperties:initialProperties]) {
// `RCTRootViewSizeFlexibilityNone` is the RCTRootView's default.
RCTSurfaceSizeMeasureMode sizeMeasureMode = convertToSurfaceSizeMeasureMode(RCTRootViewSizeFlexibilityNone);

if (self = [super initWithBridge:bridge moduleName:moduleName initialProperties:initialProperties sizeMeasureMode:sizeMeasureMode]) {
self.backgroundColor = [UIColor whiteColor];
}

Expand Down
6 changes: 4 additions & 2 deletions React/Base/Surface/SurfaceHostingView/RCTSurfaceHostingView.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ NS_ASSUME_NONNULL_BEGIN
* Instanciates a view with given Surface object.
* Note: The view retains the surface object.
*/
- (instancetype)initWithSurface:(RCTSurface *)surface NS_DESIGNATED_INITIALIZER;
- (instancetype)initWithSurface:(RCTSurface *)surface
sizeMeasureMode:(RCTSurfaceSizeMeasureMode)sizeMeasureMode NS_DESIGNATED_INITIALIZER;

/**
* Convenience initializer.
Expand All @@ -40,7 +41,8 @@ NS_ASSUME_NONNULL_BEGIN
*/
- (instancetype)initWithBridge:(RCTBridge *)bridge
moduleName:(NSString *)moduleName
initialProperties:(NSDictionary *)initialProperties;
initialProperties:(NSDictionary *)initialProperties
sizeMeasureMode:(RCTSurfaceSizeMeasureMode)sizeMeasureMode;

/**
* Create an instance of RCTSurface to be hosted.
Expand Down
11 changes: 4 additions & 7 deletions React/Base/Surface/SurfaceHostingView/RCTSurfaceHostingView.mm
Original file line number Diff line number Diff line change
Expand Up @@ -33,20 +33,17 @@ @implementation RCTSurfaceHostingView {
- (instancetype)initWithBridge:(RCTBridge *)bridge
moduleName:(NSString *)moduleName
initialProperties:(NSDictionary *)initialProperties
sizeMeasureMode:(RCTSurfaceSizeMeasureMode)sizeMeasureMode
{
RCTSurface *surface = [self createSurfaceWithBridge:bridge moduleName:moduleName initialProperties:initialProperties];
return [self initWithSurface:surface];

return [self initWithSurface:surface sizeMeasureMode:sizeMeasureMode];
}

- (instancetype)initWithSurface:(RCTSurface *)surface
- (instancetype)initWithSurface:(RCTSurface *)surface sizeMeasureMode:(RCTSurfaceSizeMeasureMode)sizeMeasureMode
{
if (self = [super initWithFrame:CGRectZero]) {
_surface = surface;

_sizeMeasureMode =
RCTSurfaceSizeMeasureModeWidthAtMost |
RCTSurfaceSizeMeasureModeHeightAtMost;
_sizeMeasureMode = sizeMeasureMode;

_surface.delegate = self;
_stage = surface.stage;
Expand Down
3 changes: 2 additions & 1 deletion React/Fabric/Surface/RCTFabricSurfaceHostingView.mm
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,12 @@ @implementation RCTFabricSurfaceHostingView
- (instancetype)initWithBridge:(RCTBridge *)bridge
moduleName:(NSString *)moduleName
initialProperties:(NSDictionary *)initialProperties
sizeMeasureMode:(RCTSurfaceSizeMeasureMode)sizeMeasureMode
{
RCTFabricSurface *surface = [[RCTFabricSurface alloc] initWithBridge:bridge
moduleName:moduleName
initialProperties:initialProperties];
return [self initWithSurface:surface];
return [self initWithSurface:surface sizeMeasureMode:sizeMeasureMode];
}

@end
Expand Down

0 comments on commit e2462e9

Please sign in to comment.