From 584cbd3b99f1aaa375665dc5117cc28da4f4df92 Mon Sep 17 00:00:00 2001 From: Denis Koroskin Date: Mon, 11 Jan 2016 20:03:20 -0800 Subject: [PATCH] Update/Add NodeRegion after collectState() Summary: RCTText may modify its DrawCommand on collectState(), which updateNodeRegion() relies on. This means that order of the two is important: call collectState() first, followed by updateNodeRegion(). This fixes the bug where am RCTText may sometimes not respond to clicks (because its NodeRegion would be empty). Reviewed By: ahmedre Differential Revision: D2816295 --- .../com/facebook/react/flat/StateBuilder.java | 46 ++++++++----------- 1 file changed, 18 insertions(+), 28 deletions(-) diff --git a/ReactAndroid/src/main/java/com/facebook/react/flat/StateBuilder.java b/ReactAndroid/src/main/java/com/facebook/react/flat/StateBuilder.java index e973dc257..1a9f1b605 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/flat/StateBuilder.java +++ b/ReactAndroid/src/main/java/com/facebook/react/flat/StateBuilder.java @@ -83,8 +83,6 @@ import com.facebook.react.uimanager.events.EventDispatcher; Float.POSITIVE_INFINITY, Float.POSITIVE_INFINITY); - node.updateNodeRegion(left, top, right, bottom); - updateViewBounds(node, left, top, right, bottom); if (mDetachAllChildrenFromViews != null) { @@ -146,8 +144,14 @@ import com.facebook.react.uimanager.events.EventDispatcher; mViewsToDrop.add(node); } - private void addNodeRegion(NodeRegion nodeRegion) { - mNodeRegions.add(nodeRegion); + private void addNodeRegion( + FlatShadowNode node, + float left, + float top, + float right, + float bottom) { + node.updateNodeRegion(left, top, right, bottom); + mNodeRegions.add(node.getNodeRegion()); } private void addNativeChild(FlatShadowNode nativeChild) { @@ -216,13 +220,6 @@ import com.facebook.react.uimanager.events.EventDispatcher; clipTop = Float.NEGATIVE_INFINITY; clipRight = Float.POSITIVE_INFINITY; clipBottom = Float.POSITIVE_INFINITY; - } else if (node.isVirtualAnchor()) { - // If RCTText is mounted to View, virtual children will not receive any touch events - // because they don't get added to nodeRegions, so nodeRegions will be empty and - // FlatViewGroup.reactTagForTouch() will always return RCTText's id. To fix the issue, - // manually add nodeRegion so it will have exactly one NodeRegion, and virtual nodes will - // be able to receive touch events. - addNodeRegion(node.getNodeRegion()); } collectStateRecursively( @@ -238,6 +235,15 @@ import com.facebook.react.uimanager.events.EventDispatcher; isAndroidView, needsCustomLayoutForChildren); + if (node.isVirtualAnchor()) { + // If RCTText is mounted to View, virtual children will not receive any touch events + // because they don't get added to nodeRegions, so nodeRegions will be empty and + // FlatViewGroup.reactTagForTouch() will always return RCTText's id. To fix the issue, + // manually add nodeRegion so it will have exactly one NodeRegion, and virtual nodes will + // be able to receive touch events. + addNodeRegion(node, left, top, right, bottom); + } + boolean shouldUpdateMountState = false; final DrawCommand[] drawCommands = mDrawCommands.finish(); if (drawCommands != null) { @@ -424,8 +430,6 @@ import com.facebook.react.uimanager.events.EventDispatcher; float right = left + width; float bottom = top + height; - node.updateNodeRegion(left, top, right, bottom); - if (node.mountsToView()) { ensureBackingViewIsCreated(node, tag, null); @@ -466,21 +470,7 @@ import com.facebook.react.uimanager.events.EventDispatcher; parentClipBottom, false, false); - addNodeRegion(node.getNodeRegion()); - } - } - - private static void updateNodeRegion( - FlatShadowNode node, - int tag, - float left, - float top, - float right, - float bottom) { - final NodeRegion nodeRegion = node.getNodeRegion(); - if (nodeRegion.mLeft != left || nodeRegion.mTop != top || - nodeRegion.mRight != right || nodeRegion.mBottom != bottom) { - node.setNodeRegion(new NodeRegion(left, top, right, bottom, tag)); + addNodeRegion(node, left, top, right, bottom); } }