Skip to content

Commit

Permalink
Fabric: EmptyLayoutMetrics does not contain invalid values anymore
Browse files Browse the repository at this point in the history
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
  • Loading branch information
shergin authored and facebook-github-bot committed Mar 11, 2020
1 parent 85a4b0f commit 0d6d586
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 25 deletions.
8 changes: 5 additions & 3 deletions React/Fabric/Mounting/UIView+ComponentViewProtocol.mm
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,9 @@ - (void)handleCommand:(NSString *)commandName args:(NSArray *)args
- (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) ||
Expand All @@ -86,13 +88,13 @@ - (void)updateLayoutMetrics:(LayoutMetrics const &)layoutMetrics
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;
}
}
Expand Down
25 changes: 3 additions & 22 deletions ReactCommon/fabric/core/layout/LayoutMetrics.h
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 0d6d586

Please sign in to comment.