mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
791d0973cc
Summary:
This diff changes the value of `EmptyLayoutMetrics` to make it as unusual and useless as possible. This helps when we need to compare sub-values of `LayoutMetrics` to apply only changed ones.
For example, let say we need to make a transition between two `LayoutMetrics` values. Let's say the first (the source) one equals `EmptyLayoutMetrics`. In order to apply only changed part, we need to compare individual sub-values, like `frame` or `displayType`. Before this change, the default value of `borderWidth` was `{0, 0, 0, 0}`. So in case if the second (the destination) value is also `{0, 0, 0, 0}`, the operation will be skipped.
This is undesirable because all new values have to be applied anyway because `EmptyLayoutMetrics` designates that the actual previous values are unknowns.
This fixes some visual issues on iOS caused by this issue because recycled views sometimes have non-default layout values where the transition from `EmptyLayoutMetrics` to some arbitrary value skips some sub-values.
Reviewed By: JoshuaGross
Differential Revision: D17312176
fbshipit-source-id: 7f311baea202ec2662ca87be0ae0ae6c6dd42712
86 lines
2.6 KiB
C++
86 lines
2.6 KiB
C++
/**
|
|
* Copyright (c) Facebook, Inc. and its 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 <react/core/LayoutPrimitives.h>
|
|
#include <react/graphics/Geometry.h>
|
|
|
|
namespace facebook {
|
|
namespace react {
|
|
|
|
/*
|
|
* Describes results of layout process for particular shadow node.
|
|
*/
|
|
struct LayoutMetrics {
|
|
Rect frame;
|
|
EdgeInsets contentInsets{0};
|
|
EdgeInsets borderWidth{0};
|
|
DisplayType displayType{DisplayType::Flex};
|
|
LayoutDirection layoutDirection{LayoutDirection::Undefined};
|
|
Float pointScaleFactor{1.0};
|
|
|
|
Rect getContentFrame() const {
|
|
return Rect{
|
|
Point{contentInsets.left, contentInsets.top},
|
|
Size{frame.size.width - contentInsets.left - contentInsets.right,
|
|
frame.size.height - contentInsets.top - contentInsets.bottom}};
|
|
}
|
|
|
|
bool operator==(const LayoutMetrics &rhs) const {
|
|
return std::tie(
|
|
this->frame,
|
|
this->contentInsets,
|
|
this->borderWidth,
|
|
this->displayType,
|
|
this->layoutDirection,
|
|
this->pointScaleFactor) ==
|
|
std::tie(
|
|
rhs.frame,
|
|
rhs.contentInsets,
|
|
rhs.borderWidth,
|
|
rhs.displayType,
|
|
rhs.layoutDirection,
|
|
rhs.pointScaleFactor);
|
|
}
|
|
|
|
bool operator!=(const LayoutMetrics &rhs) const {
|
|
return !(*this == rhs);
|
|
}
|
|
};
|
|
|
|
/*
|
|
* 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()};
|
|
|
|
} // namespace react
|
|
} // namespace facebook
|