From b2a251948f3309d2b1d0d533fb2fa74d2f8a10b8 Mon Sep 17 00:00:00 2001 From: Valentin Shergin Date: Sun, 7 Jan 2018 18:21:43 -0800 Subject: [PATCH] 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 --- React/Base/Surface/RCTSurface.h | 2 +- React/Base/Surface/RCTSurface.mm | 2 +- React/Base/Surface/RCTSurfaceRootShadowView.m | 21 +++++++++++-------- .../RCTSurfaceHostingView.mm | 2 +- 4 files changed, 15 insertions(+), 12 deletions(-) diff --git a/React/Base/Surface/RCTSurface.h b/React/Base/Surface/RCTSurface.h index 1f6ec2b63..603f0e851 100644 --- a/React/Base/Surface/RCTSurface.h +++ b/React/Base/Surface/RCTSurface.h @@ -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; diff --git a/React/Base/Surface/RCTSurface.mm b/React/Base/Surface/RCTSurface.mm index ebe11690b..9624663af 100644 --- a/React/Base/Surface/RCTSurface.mm +++ b/React/Base/Surface/RCTSurface.mm @@ -67,7 +67,7 @@ _rootShadowViewDidStartLayingOutSemaphore = dispatch_semaphore_create(0); _minimumSize = CGSizeZero; - _maximumSize = CGSizeMake(INFINITY, INFINITY); + _maximumSize = CGSizeMake(CGFLOAT_MAX, CGFLOAT_MAX); [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(handleBridgeWillLoadJavaScriptNotification:) diff --git a/React/Base/Surface/RCTSurfaceRootShadowView.m b/React/Base/Surface/RCTSurfaceRootShadowView.m index 9ffe7364c..3b98c6d79 100644 --- a/React/Base/Surface/RCTSurfaceRootShadowView.m +++ b/React/Base/Surface/RCTSurfaceRootShadowView.m @@ -9,9 +9,9 @@ #import "RCTSurfaceRootShadowView.h" -#import - #import "RCTI18nUtil.h" +#import "RCTShadowView+Layout.h" +#import "RCTUIManagerUtils.h" @implementation RCTSurfaceRootShadowView { CGSize _intrinsicSize; @@ -25,7 +25,7 @@ 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)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 *)collectViewsWithUpdatedFrames diff --git a/React/Base/Surface/SurfaceHostingView/RCTSurfaceHostingView.mm b/React/Base/Surface/SurfaceHostingView/RCTSurfaceHostingView.mm index 5d55f62a4..4759b6f54 100644 --- a/React/Base/Surface/SurfaceHostingView/RCTSurfaceHostingView.mm +++ b/React/Base/Surface/SurfaceHostingView/RCTSurfaceHostingView.mm @@ -85,7 +85,7 @@ RCT_NOT_IMPLEMENTED(- (nullable instancetype)initWithCoder:(NSCoder *)coder) } CGSize minimumSize = CGSizeZero; - CGSize maximumSize = CGSizeMake(INFINITY, INFINITY); + CGSize maximumSize = CGSizeMake(CGFLOAT_MAX, CGFLOAT_MAX); if (_sizeMeasureMode & RCTSurfaceSizeMeasureModeWidthExact) { minimumSize.width = size.width;