From ac3f345b071fbf762e7224fc6357ab2f7080575c Mon Sep 17 00:00:00 2001 From: Valentin Shergin Date: Tue, 20 Jun 2017 17:12:51 -0700 Subject: [PATCH] Fixed assertion caused by invalid layout of hidden Yoga nodes Summary: That's interesting! If we apply `display: none;` style to some node, Yoga will stop calculation layout for this subtree (which is reasonable). So, from RN perspective we have to stop applying layout for hidden subtree because it is meaningless and causes another errors. Note: We do actually not support `display: none;` yet. It stops computing layout, but it does not hide the views! Reviewed By: javache Differential Revision: D5168651 fbshipit-source-id: 29a9385c76a0f9d637285fc0d268ccc39879ca0a --- React/Views/RCTShadowView.m | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/React/Views/RCTShadowView.m b/React/Views/RCTShadowView.m index 2e7d4794c6..67b954da29 100644 --- a/React/Views/RCTShadowView.m +++ b/React/Views/RCTShadowView.m @@ -165,10 +165,17 @@ static void RCTProcessMetaPropsBorder(const YGValue metaProps[META_PROP_COUNT], if (!YGNodeGetHasNewLayout(node)) { return; } - YGNodeSetHasNewLayout(node, false); RCTAssert(!YGNodeIsDirty(node), @"Attempt to get layout metrics from dirtied Yoga node."); + YGNodeSetHasNewLayout(node, false); + + if (YGNodeStyleGetDisplay(node) == YGDisplayNone) { + // If the node is hidden (has `display: none;`), its (and its descendants) + // layout metrics are invalid and/or dirtied, so we have to stop here. + return; + } + #if RCT_DEBUG // This works around a breaking change in Yoga layout where setting flexBasis needs to be set explicitly, instead of relying on flex to propagate. // We check for it by seeing if a width/height is provided along with a flexBasis of 0 and the width/height is laid out as 0.