diff --git a/ReactAndroid/src/main/java/com/facebook/react/flat/FlatViewGroup.java b/ReactAndroid/src/main/java/com/facebook/react/flat/FlatViewGroup.java index 040cec66d2..5e2a2385fe 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/flat/FlatViewGroup.java +++ b/ReactAndroid/src/main/java/com/facebook/react/flat/FlatViewGroup.java @@ -412,7 +412,8 @@ import com.facebook.react.views.image.ImageLoadEvent; } private NodeRegion nodeRegionWithinBounds(float touchX, float touchY) { - for (NodeRegion nodeRegion : mNodeRegions) { + for (int i = mNodeRegions.length - 1; i >= 0; --i) { + NodeRegion nodeRegion = mNodeRegions[i]; if (nodeRegion.withinBounds(touchX, touchY)) { return nodeRegion; } 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 7df5db8b4f..e5be9c10b1 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/flat/StateBuilder.java +++ b/ReactAndroid/src/main/java/com/facebook/react/flat/StateBuilder.java @@ -285,6 +285,15 @@ import com.facebook.react.uimanager.events.EventDispatcher; clipBottom = Float.POSITIVE_INFINITY; } + if (!isAndroidView && 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 descendantUpdated = collectStateRecursively( node, left, @@ -298,15 +307,6 @@ import com.facebook.react.uimanager.events.EventDispatcher; isAndroidView, needsCustomLayoutForChildren); - if (!isAndroidView && 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) { @@ -549,6 +549,8 @@ import com.facebook.react.uimanager.events.EventDispatcher; updateViewBounds(node, left, top, right, bottom); } } else { + addNodeRegion(node, left, top, right, bottom); + updated = collectStateRecursively( node, left, @@ -561,7 +563,6 @@ import com.facebook.react.uimanager.events.EventDispatcher; parentClipBottom, false, false); - addNodeRegion(node, left, top, right, bottom); } return updated;