Sideeffectless measuring of shadow views

Summary:
That's now possible thanks to new Yoga's clonning API.
That will speed up RCTSurface measuring (see the next diff in stack) and should illuminate a class of problems in CK interop layer.
We also will use it in the new text layout engine (in React Native).

Reviewed By: gkassabli

Differential Revision: D6665632

fbshipit-source-id: e94909f0af89e9c7fc5e46b95090ecb3c52546a2
This commit is contained in:
Valentin Shergin 2018-01-07 18:21:41 -08:00 committed by Facebook Github Bot
parent d9e5b313bb
commit f96f9c5fd6
2 changed files with 40 additions and 0 deletions

View File

@ -27,6 +27,13 @@ RCT_EXTERN CGFloat RCTCoreGraphicsFloatFromYogaFloat(float value);
@property (nonatomic, readonly) UIEdgeInsets compoundInsets;
@property (nonatomic, readonly) CGSize availableSize;
#pragma mark - Measuring
/**
* Measures shadow view without side-effects.
*/
- (CGSize)sizeThatFitsMinimumSize:(CGSize)minimumSize maximumSize:(CGSize)maximumSize;
#pragma mark - Dirty Propagation Control
/**

View File

@ -81,6 +81,39 @@ CGFloat RCTCoreGraphicsFloatFromYogaFloat(float value)
return UIEdgeInsetsInsetRect((CGRect){CGPointZero, self.frame.size}, self.compoundInsets).size;
}
#pragma mark - Measuring
- (CGSize)sizeThatFitsMinimumSize:(CGSize)minimumSize maximumSize:(CGSize)maximumSize
{
YGNodeRef clonnedYogaNode = YGNodeClone(self.yogaNode);
YGNodeRef constraintYogaNode = YGNodeNewWithConfig([[self class] yogaConfig]);
YGNodeInsertChild(constraintYogaNode, clonnedYogaNode, 0);
YGNodeStyleSetMinWidth(constraintYogaNode, RCTYogaFloatFromCoreGraphicsFloat(minimumSize.width));
YGNodeStyleSetMinHeight(constraintYogaNode, RCTYogaFloatFromCoreGraphicsFloat(minimumSize.height));
YGNodeStyleSetMaxWidth(constraintYogaNode, RCTYogaFloatFromCoreGraphicsFloat(maximumSize.width));
YGNodeStyleSetMaxHeight(constraintYogaNode, RCTYogaFloatFromCoreGraphicsFloat(maximumSize.height));
YGNodeCalculateLayout(
constraintYogaNode,
YGUndefined,
YGUndefined,
self.layoutDirection
);
CGSize measuredSize = (CGSize){
RCTCoreGraphicsFloatFromYogaFloat(YGNodeLayoutGetWidth(constraintYogaNode)),
RCTCoreGraphicsFloatFromYogaFloat(YGNodeLayoutGetHeight(constraintYogaNode)),
};
YGNodeRemoveChild(constraintYogaNode, clonnedYogaNode);
YGNodeFree(constraintYogaNode);
YGNodeFree(clonnedYogaNode);
return measuredSize;
}
#pragma mark - Dirty Propagation Control
- (void)dirtyLayout