From 008ad0200fd55b8351c108ecfbdd1890a7ae8ab9 Mon Sep 17 00:00:00 2001 From: Ahmed El-Helw Date: Wed, 21 Dec 2016 17:49:43 -0800 Subject: [PATCH] Fix measurement of virtual nodes Summary: Virtual nodes do not have backing Yoga nodes, so measure their first non-virtual parent instead of measuring them. Reviewed By: sriramramani Differential Revision: D4360540 fbshipit-source-id: 505d35fec74dddf67b002d29268acc29d2651b13 --- .../react/flat/FlatUIImplementation.java | 30 +++++++++++++------ 1 file changed, 21 insertions(+), 9 deletions(-) diff --git a/ReactAndroid/src/main/java/com/facebook/react/flat/FlatUIImplementation.java b/ReactAndroid/src/main/java/com/facebook/react/flat/FlatUIImplementation.java index c734e5b2af9..4afb6c4e6aa 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/flat/FlatUIImplementation.java +++ b/ReactAndroid/src/main/java/com/facebook/react/flat/FlatUIImplementation.java @@ -217,21 +217,33 @@ public class FlatUIImplementation extends UIImplementation { return; } + // virtual nodes do not have values for width and height, so get these values + // from the first non-virtual parent node + while (node != null && node.isVirtual()) { + node = (FlatShadowNode) node.getParent(); + } + + if (node == null) { + // everything is virtual, this shouldn't happen so just silently return + return; + } + float width = node.getLayoutWidth(); float height = node.getLayoutHeight(); - float xInParent = node.getLayoutX(); - float yInParent = node.getLayoutY(); + boolean nodeMountsToView = node.mountsToView(); + // this is to avoid double-counting xInParent and yInParent when we visit + // the while loop, below. + float xInParent = nodeMountsToView ? node.getLayoutX() : 0; + float yInParent = nodeMountsToView ? node.getLayoutY() : 0; - while (true) { - node = Assertions.assumeNotNull((FlatShadowNode) node.getParent()); - if (node.mountsToView()) { - mStateBuilder.ensureBackingViewIsCreated(node); - break; + while (!node.mountsToView()) { + if (!node.isVirtual()) { + xInParent += node.getLayoutX(); + yInParent += node.getLayoutY(); } - xInParent += node.getLayoutX(); - yInParent += node.getLayoutY(); + node = Assertions.assumeNotNull((FlatShadowNode) node.getParent()); } float parentWidth = node.getLayoutWidth();