Skip to content

Commit f96f9c5

Browse files
sherginfacebook-github-bot
authored andcommitted
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
1 parent d9e5b31 commit f96f9c5

File tree

2 files changed

+40
-0
lines changed

2 files changed

+40
-0
lines changed

React/Views/RCTShadowView+Layout.h

+7
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,13 @@ RCT_EXTERN CGFloat RCTCoreGraphicsFloatFromYogaFloat(float value);
2727
@property (nonatomic, readonly) UIEdgeInsets compoundInsets;
2828
@property (nonatomic, readonly) CGSize availableSize;
2929

30+
#pragma mark - Measuring
31+
32+
/**
33+
* Measures shadow view without side-effects.
34+
*/
35+
- (CGSize)sizeThatFitsMinimumSize:(CGSize)minimumSize maximumSize:(CGSize)maximumSize;
36+
3037
#pragma mark - Dirty Propagation Control
3138

3239
/**

React/Views/RCTShadowView+Layout.m

+33
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,39 @@ - (CGSize)availableSize
8181
return UIEdgeInsetsInsetRect((CGRect){CGPointZero, self.frame.size}, self.compoundInsets).size;
8282
}
8383

84+
#pragma mark - Measuring
85+
86+
- (CGSize)sizeThatFitsMinimumSize:(CGSize)minimumSize maximumSize:(CGSize)maximumSize
87+
{
88+
YGNodeRef clonnedYogaNode = YGNodeClone(self.yogaNode);
89+
YGNodeRef constraintYogaNode = YGNodeNewWithConfig([[self class] yogaConfig]);
90+
91+
YGNodeInsertChild(constraintYogaNode, clonnedYogaNode, 0);
92+
93+
YGNodeStyleSetMinWidth(constraintYogaNode, RCTYogaFloatFromCoreGraphicsFloat(minimumSize.width));
94+
YGNodeStyleSetMinHeight(constraintYogaNode, RCTYogaFloatFromCoreGraphicsFloat(minimumSize.height));
95+
YGNodeStyleSetMaxWidth(constraintYogaNode, RCTYogaFloatFromCoreGraphicsFloat(maximumSize.width));
96+
YGNodeStyleSetMaxHeight(constraintYogaNode, RCTYogaFloatFromCoreGraphicsFloat(maximumSize.height));
97+
98+
YGNodeCalculateLayout(
99+
constraintYogaNode,
100+
YGUndefined,
101+
YGUndefined,
102+
self.layoutDirection
103+
);
104+
105+
CGSize measuredSize = (CGSize){
106+
RCTCoreGraphicsFloatFromYogaFloat(YGNodeLayoutGetWidth(constraintYogaNode)),
107+
RCTCoreGraphicsFloatFromYogaFloat(YGNodeLayoutGetHeight(constraintYogaNode)),
108+
};
109+
110+
YGNodeRemoveChild(constraintYogaNode, clonnedYogaNode);
111+
YGNodeFree(constraintYogaNode);
112+
YGNodeFree(clonnedYogaNode);
113+
114+
return measuredSize;
115+
}
116+
84117
#pragma mark - Dirty Propagation Control
85118

86119
- (void)dirtyLayout

0 commit comments

Comments
 (0)