From dafa97535208d1fe2d452059ead418f828466583 Mon Sep 17 00:00:00 2001 From: Valentin Shergin Date: Mon, 18 May 2020 14:04:10 -0700 Subject: [PATCH] Fabric: Simplification of `UIManager::getRelativeLayoutMetrics` Summary: Using of the new API makes clear that we don't need to calculate the newest descendant node. Changelog: [Internal] Fabric-specific internal change. Reviewed By: mdvacca Differential Revision: D21480202 fbshipit-source-id: c54998573baffe4a05726e3402da027f052b049a --- ReactCommon/fabric/uimanager/UIManager.cpp | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/ReactCommon/fabric/uimanager/UIManager.cpp b/ReactCommon/fabric/uimanager/UIManager.cpp index 3de1d006fde..761a87c3efe 100644 --- a/ReactCommon/fabric/uimanager/UIManager.cpp +++ b/ReactCommon/fabric/uimanager/UIManager.cpp @@ -213,27 +213,22 @@ LayoutMetrics UIManager::getRelativeLayoutMetrics( true); }); } else { + // It is possible for JavaScript (or other callers) to have a reference + // to a previous version of ShadowNodes, but we enforce that + // metrics are only calculated on most recently committed versions. owningAncestorShadowNode = getNewestCloneOfShadowNode(*ancestorShadowNode); ancestorShadowNode = owningAncestorShadowNode.get(); } - // Get latest version of both the ShadowNode and its ancestor. - // It is possible for JS (or other callers) to have a reference - // to a previous version of ShadowNodes, but we enforce that - // metrics are only calculated on most recently committed versions. - auto newestShadowNode = getNewestCloneOfShadowNode(shadowNode); - - auto layoutableShadowNode = - traitCast(newestShadowNode.get()); auto layoutableAncestorShadowNode = traitCast(ancestorShadowNode); - if (!layoutableShadowNode || !layoutableAncestorShadowNode) { + if (!layoutableAncestorShadowNode) { return EmptyLayoutMetrics; } - return layoutableShadowNode->getRelativeLayoutMetrics( - *layoutableAncestorShadowNode, policy); + return LayoutableShadowNode::computeRelativeLayoutMetrics( + shadowNode.getFamily(), *layoutableAncestorShadowNode, policy); } void UIManager::updateState(StateUpdate const &stateUpdate) const {