Summary: X-link: https://github.com/facebook/react-native/pull/41390 Pull Request resolved: https://github.com/facebook/yoga/pull/1460 Yoga passes `MeasureMode`/`YGMeasureMode` to express constraints in how a box should be measured, given definite or indefinite available space. This is modeled after Android [MeasureSpec](https://developer.android.com/reference/android/view/View.MeasureSpec), with a table above `calculateLayoutImpl()` explaining the CSS terms they map to. This can be confusing when flipping between the spec, and code. This switches internal usages to the CSS terms, but leaves around `YGMeasureMode` since it is the public API passed to measure functions. Reviewed By: joevilches Differential Revision: D51068417 fbshipit-source-id: 0a76266a4e7e0cc39996164607229c3c41de2818
54 lines
1.5 KiB
C++
54 lines
1.5 KiB
C++
/*
|
|
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
*
|
|
* This source code is licensed under the MIT license found in the
|
|
* LICENSE file in the root directory of this source tree.
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
#include <cmath>
|
|
|
|
#include <yoga/Yoga.h>
|
|
|
|
#include <yoga/algorithm/SizingMode.h>
|
|
#include <yoga/numeric/Comparison.h>
|
|
|
|
namespace facebook::yoga {
|
|
|
|
struct CachedMeasurement {
|
|
float availableWidth{-1};
|
|
float availableHeight{-1};
|
|
SizingMode widthSizingMode{SizingMode::MaxContent};
|
|
SizingMode heightSizingMode{SizingMode::MaxContent};
|
|
|
|
float computedWidth{-1};
|
|
float computedHeight{-1};
|
|
|
|
bool operator==(CachedMeasurement measurement) const {
|
|
bool isEqual = widthSizingMode == measurement.widthSizingMode &&
|
|
heightSizingMode == measurement.heightSizingMode;
|
|
|
|
if (!yoga::isUndefined(availableWidth) ||
|
|
!yoga::isUndefined(measurement.availableWidth)) {
|
|
isEqual = isEqual && availableWidth == measurement.availableWidth;
|
|
}
|
|
if (!yoga::isUndefined(availableHeight) ||
|
|
!yoga::isUndefined(measurement.availableHeight)) {
|
|
isEqual = isEqual && availableHeight == measurement.availableHeight;
|
|
}
|
|
if (!yoga::isUndefined(computedWidth) ||
|
|
!yoga::isUndefined(measurement.computedWidth)) {
|
|
isEqual = isEqual && computedWidth == measurement.computedWidth;
|
|
}
|
|
if (!yoga::isUndefined(computedHeight) ||
|
|
!yoga::isUndefined(measurement.computedHeight)) {
|
|
isEqual = isEqual && computedHeight == measurement.computedHeight;
|
|
}
|
|
|
|
return isEqual;
|
|
}
|
|
};
|
|
|
|
} // namespace facebook::yoga
|