Skip to content

Commit

Permalink
Proper usage CGFLOAT_MAX vs INFINITY inside RCTSurface
Browse files Browse the repository at this point in the history
Summary: See `RCTShadowView+Layout.m` for more info about differences between CGFLOAT_MAX and INFINITY in Yoga and UIKit.

Reviewed By: mmmulani

Differential Revision: D6665635

fbshipit-source-id: 270ba5366c3dfe78e38474de5380d7d5d251e628
  • Loading branch information
shergin authored and facebook-github-bot committed Jan 8, 2018
1 parent f96f9c5 commit b2a2519
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 12 deletions.
2 changes: 1 addition & 1 deletion React/Base/Surface/RCTSurface.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ NS_ASSUME_NONNULL_BEGIN

/**
* Previously set `maximumSize` layout constraint.
* Defaults to `{INFINITY, INFINITY}`.
* Defaults to `{CGFLOAT_MAX, CGFLOAT_MAX}`.
*/
@property (atomic, assign, readonly) CGSize maximumSize;

Expand Down
2 changes: 1 addition & 1 deletion React/Base/Surface/RCTSurface.mm
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ - (instancetype)initWithBridge:(RCTBridge *)bridge
_rootShadowViewDidStartLayingOutSemaphore = dispatch_semaphore_create(0);

_minimumSize = CGSizeZero;
_maximumSize = CGSizeMake(INFINITY, INFINITY);
_maximumSize = CGSizeMake(CGFLOAT_MAX, CGFLOAT_MAX);

[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(handleBridgeWillLoadJavaScriptNotification:)
Expand Down
21 changes: 12 additions & 9 deletions React/Base/Surface/RCTSurfaceRootShadowView.m
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@

#import "RCTSurfaceRootShadowView.h"

#import <React/RCTUIManagerUtils.h>

#import "RCTI18nUtil.h"
#import "RCTShadowView+Layout.h"
#import "RCTUIManagerUtils.h"

@implementation RCTSurfaceRootShadowView {
CGSize _intrinsicSize;
Expand All @@ -25,7 +25,7 @@ - (instancetype)init
self.viewName = @"RCTSurfaceRootView";
_baseDirection = [[RCTI18nUtil sharedInstance] isRTL] ? YGDirectionRTL : YGDirectionLTR;
_minimumSize = CGSizeZero;
_maximumSize = CGSizeMake(INFINITY, INFINITY);
_maximumSize = CGSizeMake(CGFLOAT_MAX, CGFLOAT_MAX);

self.alignSelf = YGAlignStretch;
self.flex = 1;
Expand All @@ -45,14 +45,17 @@ - (void)insertReactSubview:(RCTShadowView *)subview atIndex:(NSInteger)atIndex

- (void)calculateLayoutWithMinimumSize:(CGSize)minimumSize maximumSize:(CGSize)maximimSize
{
// Treating `INFINITY` as `YGUndefined` (which equals `NAN`).
float availableWidth = isinf(maximimSize.width) ? YGUndefined : maximimSize.width;
float availableHeight = isinf(maximimSize.height) ? YGUndefined : maximimSize.height;
YGNodeRef yogaNode = self.yogaNode;

self.minWidth = (YGValue){isinf(minimumSize.width) ? YGUndefined : minimumSize.width, YGUnitPoint};
self.minHeight = (YGValue){isinf(minimumSize.height) ? YGUndefined : minimumSize.height, YGUnitPoint};
YGNodeStyleSetMinWidth(yogaNode, RCTYogaFloatFromCoreGraphicsFloat(maximimSize.width));
YGNodeStyleSetMinHeight(yogaNode, RCTYogaFloatFromCoreGraphicsFloat(maximimSize.height));

YGNodeCalculateLayout(self.yogaNode, availableWidth, availableHeight, _baseDirection);
YGNodeCalculateLayout(
self.yogaNode,
RCTYogaFloatFromCoreGraphicsFloat(maximimSize.width),
RCTYogaFloatFromCoreGraphicsFloat(maximimSize.height),
_baseDirection
);
}

- (NSSet<RCTShadowView *> *)collectViewsWithUpdatedFrames
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ - (CGSize)sizeThatFits:(CGSize)size
}

CGSize minimumSize = CGSizeZero;
CGSize maximumSize = CGSizeMake(INFINITY, INFINITY);
CGSize maximumSize = CGSizeMake(CGFLOAT_MAX, CGFLOAT_MAX);

if (_sizeMeasureMode & RCTSurfaceSizeMeasureModeWidthExact) {
minimumSize.width = size.width;
Expand Down

0 comments on commit b2a2519

Please sign in to comment.