in ComponentKit/LayoutComponents/CKFlexboxComponent.mm [288:321]
static YGSize measureYGComponent(YGNodeRef node,
float width,
YGMeasureMode widthMode,
float height,
YGMeasureMode heightMode)
{
CKFlexboxChildCachedLayout *cachedLayout = (__bridge CKFlexboxChildCachedLayout *)YGNodeGetContext(node);
const CGSize minSize = {
.width = (widthMode == YGMeasureModeExactly) ? width : 0,
.height = (heightMode == YGMeasureModeExactly) ? height : 0
};
const CGSize maxSize = {
.width = (widthMode == YGMeasureModeExactly || widthMode == YGMeasureModeAtMost) ? width : INFINITY,
.height = (heightMode == YGMeasureModeExactly || heightMode == YGMeasureModeAtMost) ? height : INFINITY
};
// We cache measurements for the duration of single layout calculation of FlexboxComponent
// ComponentKit and Yoga handle caching between calculations
// We don't have any guarantees about when and how this will be called,
// so we just cache the results to try to reuse them during final layout
if (!CKYogaNodeCanUseCachedMeasurement(widthMode, width, heightMode, height, cachedLayout.widthMode, cachedLayout.width, cachedLayout.heightMode, cachedLayout.height, static_cast<float>(cachedLayout.componentLayout.size.width), static_cast<float>(cachedLayout.componentLayout.size.height), 0, 0, ckYogaDefaultConfig())) {
CKComponent *component = cachedLayout.component;
cachedLayout.componentLayout = CKComputeComponentLayout(component, convertCKSizeRangeToCKRepresentation(CKSizeRange(minSize, maxSize)), convertCGSizeToCKRepresentation(cachedLayout.parentSize));
cachedLayout.width = width;
cachedLayout.height = height;
cachedLayout.widthMode = widthMode;
cachedLayout.heightMode = heightMode;
}
const float componentLayoutWidth = static_cast<float>(cachedLayout.componentLayout.size.width);
const float componentLayoutHeight = static_cast<float>(cachedLayout.componentLayout.size.height);
const float measuredWidth = convertFloatToYogaRepresentation(componentLayoutWidth);
const float measuredHeight = convertFloatToYogaRepresentation(componentLayoutHeight);
return {measuredWidth, measuredHeight};
}