From 6694ce00bb6a78cc344cd6eac200d2ed8c5e46b9 Mon Sep 17 00:00:00 2001 From: Valentin Shergin Date: Sun, 19 Apr 2020 22:30:40 -0700 Subject: [PATCH] Fabric: Fixed incorrect early-return in `UIView+ComponentViewProtocol::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 --- React/Fabric/Mounting/UIView+ComponentViewProtocol.mm | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/React/Fabric/Mounting/UIView+ComponentViewProtocol.mm b/React/Fabric/Mounting/UIView+ComponentViewProtocol.mm index c9dc5f98d7a..0eda1bda5ea 100644 --- a/React/Fabric/Mounting/UIView+ComponentViewProtocol.mm +++ b/React/Fabric/Mounting/UIView+ComponentViewProtocol.mm @@ -79,13 +79,12 @@ using namespace facebook::react; @"-[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)) {