Fabric: EmptyLayoutMetrics does not contain invalid values anymore

Summary:
Before this change, fields of EmptyLayoutMetrics have some "invalid" values to allow us to compare equal them individually and get `false`. Turned out that having invalid values there might break some serialization layers, which is no good.
This change fixes that and adds explicit check for EmptyLayoutMetrics before running a comparison of individual fields.

Changelog: [Internal] Fabric-specific internal change.

Reviewed By: mdvacca

Differential Revision: D20324881

fbshipit-source-id: ab8e2a402f6bdfb393fc9b6789decb526fa94dfa
This commit is contained in:
Valentin Shergin 2020-03-10 16:57:20 -07:00 коммит произвёл Facebook Github Bot
Родитель 85a4b0f5bd
Коммит 0d6d58656a
2 изменённых файлов: 8 добавлений и 25 удалений

Просмотреть файл

@ -63,7 +63,9 @@ using namespace facebook::react;
- (void)updateLayoutMetrics:(LayoutMetrics const &)layoutMetrics
oldLayoutMetrics:(LayoutMetrics const &)oldLayoutMetrics
{
if (layoutMetrics.frame != oldLayoutMetrics.frame) {
bool forceUpdate = oldLayoutMetrics == EmptyLayoutMetrics;
if (forceUpdate || (layoutMetrics.frame != oldLayoutMetrics.frame)) {
CGRect frame = RCTCGRectFromRect(layoutMetrics.frame);
if (!std::isfinite(frame.origin.x) || !std::isfinite(frame.origin.y) || !std::isfinite(frame.size.width) ||
@ -86,13 +88,13 @@ using namespace facebook::react;
self.bounds = CGRect{CGPointZero, frame.size};
}
if (layoutMetrics.layoutDirection != oldLayoutMetrics.layoutDirection) {
if (forceUpdate || (layoutMetrics.layoutDirection != oldLayoutMetrics.layoutDirection)) {
self.semanticContentAttribute = layoutMetrics.layoutDirection == LayoutDirection::RightToLeft
? UISemanticContentAttributeForceRightToLeft
: UISemanticContentAttributeForceLeftToRight;
}
if (layoutMetrics.displayType != oldLayoutMetrics.displayType) {
if (forceUpdate || (layoutMetrics.displayType != oldLayoutMetrics.displayType)) {
self.hidden = layoutMetrics.displayType == DisplayType::None;
}
}

Просмотреть файл

@ -57,29 +57,10 @@ struct LayoutMetrics {
* Represents some undefined, not-yet-computed or meaningless value of
* `LayoutMetrics` type.
* The value is comparable by equality with any other `LayoutMetrics` value.
* All individual sub-properties of `EmptyLayoutMetrics` have the most possible
* "invalid" values; this is useful when we compare them with some valid values.
*/
static const LayoutMetrics EmptyLayoutMetrics = {
/* .frame = */ {
/* .origin = */ {std::numeric_limits<Float>::min(),
std::numeric_limits<Float>::min()},
/* .size = */
{std::numeric_limits<Float>::min(), std::numeric_limits<Float>::min()},
},
/* .contentInsets = */
{std::numeric_limits<Float>::min(),
std::numeric_limits<Float>::min(),
std::numeric_limits<Float>::min(),
std::numeric_limits<Float>::min()},
/* .borderWidth = */
{std::numeric_limits<Float>::min(),
std::numeric_limits<Float>::min(),
std::numeric_limits<Float>::min(),
std::numeric_limits<Float>::min()},
/* .displayType = */ (DisplayType)-1,
/* .layoutDirection = */ (LayoutDirection)-1,
/* .pointScaleFactor = */ std::numeric_limits<Float>::min()};
static LayoutMetrics const EmptyLayoutMetrics = {
/* .frame = */ {{0, 0}, {-1.0, -1.0}}
};
} // namespace react
} // namespace facebook