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
Expand Up @@ -80,7 +80,7 @@ NS_ASSUME_NONNULL_BEGIN


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


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


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


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


#import "RCTSurfaceRootShadowView.h" #import "RCTSurfaceRootShadowView.h"


#import <React/RCTUIManagerUtils.h>

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


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


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


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


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


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


- (NSSet<RCTShadowView *> *)collectViewsWithUpdatedFrames - (NSSet<RCTShadowView *> *)collectViewsWithUpdatedFrames
Expand Down
Expand Up @@ -85,7 +85,7 @@ - (CGSize)sizeThatFits:(CGSize)size
} }


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


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

0 comments on commit b2a2519

Please sign in to comment.