Skip to content

Commit

Permalink
Fabric: Fixed incorrect early-return in `UIView+ComponentViewProtocol…
Browse files Browse the repository at this point in the history
…::updateLayoutMetrics`

Summary:
Before the change, an incorrect (NaN or Inf) values in LayoutMetrics might force an early return in the `updateLayoutMetrics:oldMetrics:` method implementation. This was not correct because the rest of the method also didn't run in this case, so it might force some value to stale.
E.g., imagine we have an instruction that contains NaN size and `display: none`. Previously, the function might just return right before applying sizes and progress the stored "already applied" value of LayoutMetrics which will cause the view being visible even if it should not.

Changelog: [Internal] Fabric-specific internal change.

Reviewed By: JoshuaGross

Differential Revision: D21110644

fbshipit-source-id: 501319d7b1dcd5c18f27e0ceca3c8d207485c49b
  • Loading branch information
shergin authored and facebook-github-bot committed Apr 20, 2020
1 parent b000664 commit 6694ce0
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions React/Fabric/Mounting/UIView+ComponentViewProtocol.mm
Original file line number Diff line number Diff line change
Expand Up @@ -79,13 +79,12 @@ - (void)updateLayoutMetrics:(LayoutMetrics const &)layoutMetrics
@"-[UIView(ComponentViewProtocol) updateLayoutMetrics:oldLayoutMetrics:]: Received invalid layout metrics (%@) for a view (%@).",
NSStringFromCGRect(frame),
self);
return;
} else {
// Note: Changing `frame` when `layer.transform` is not the `identity transform` is undefined behavior.
// Therefore, we must use `center` and `bounds`.
self.center = CGPoint{CGRectGetMidX(frame), CGRectGetMidY(frame)};
self.bounds = CGRect{CGPointZero, frame.size};
}

// Note: Changing `frame` when `layer.transform` is not the `identity transform` is undefined behavior.
// Therefore, we must use `center` and `bounds`.
self.center = CGPoint{CGRectGetMidX(frame), CGRectGetMidY(frame)};
self.bounds = CGRect{CGPointZero, frame.size};
}

if (forceUpdate || (layoutMetrics.layoutDirection != oldLayoutMetrics.layoutDirection)) {
Expand Down

0 comments on commit 6694ce0

Please sign in to comment.