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
This commit is contained in:
parent
f96f9c5fd6
commit
b2a251948f
|
@ -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 @@
|
|||
_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 @@
|
|||
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<RCTShadowView *> *)collectViewsWithUpdatedFrames
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Reference in New Issue