Permalink
Browse files

Proper usage CGFLOAT_MAX vs INFINITY inside RCTSurface

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 b2a251948f3309d2b1d0d533fb2fa74d2f8a10b8
@@ -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;
@@ -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:)
@@ -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;
@@ -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;
@@ -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
@@ -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;

0 comments on commit b2a2519

Please sign in to comment.