Add NodeRegion to allow any FlatShadowNode to respond to touch events

Summary: @public When Android dispatches `MotionEvent` to `ReactRootView`, it needs to find a correspoding react node that should receive it. To be able to do it, we need to store boundaries of every `FlatShadowNode` in `FlatViewGroup`. Then we can iterate over node boundaries and find one that contains the touch event coordinates.

Reviewed By: sriramramani

Differential Revision: D2694197
This commit is contained in:
Denis Koroskin
2015-12-13 18:26:10 -08:00
committed by Ahmed El-Helw
parent 8de2acd3a9
commit dad378e394
6 changed files with 118 additions and 8 deletions

View File

@@ -31,6 +31,8 @@ import com.facebook.react.uimanager.CatalystStylesDiffMap;
new ElementsList<>(DrawCommand.EMPTY_ARRAY);
private final ElementsList<AttachDetachListener> mAttachDetachListeners =
new ElementsList<>(AttachDetachListener.EMPTY_ARRAY);
private final ElementsList<NodeRegion> mNodeRegions =
new ElementsList<>(NodeRegion.EMPTY_ARRAY);
private final ElementsList<FlatShadowNode> mNativeChildren =
new ElementsList<>(FlatShadowNode.EMPTY_ARRAY);
@@ -56,7 +58,10 @@ import com.facebook.react.uimanager.CatalystStylesDiffMap;
float left = node.getLayoutX();
float top = node.getLayoutY();
updateViewBounds(node, tag, left, top, left + width, top + height);
float right = left + width;
float bottom = top + height;
updateNodeRegion(node, tag, left, top, right, bottom);
updateViewBounds(node, tag, left, top, right, bottom);
if (mDetachAllChildrenFromViews != null) {
int[] viewsToDetachAllChildrenFrom = collectViewTags(mViewsToDetachAllChildrenFrom);
@@ -90,6 +95,10 @@ import com.facebook.react.uimanager.CatalystStylesDiffMap;
node.signalBackingViewIsCreated();
}
private void addNodeRegion(NodeRegion nodeRegion) {
mNodeRegions.add(nodeRegion);
}
private void addNativeChild(FlatShadowNode nativeChild) {
mNativeChildren.add(nativeChild);
}
@@ -130,6 +139,7 @@ import com.facebook.react.uimanager.CatalystStylesDiffMap;
float height) {
mDrawCommands.start(node.getDrawCommands());
mAttachDetachListeners.start(node.getAttachDetachListeners());
mNodeRegions.start(node.getNodeRegions());
mNativeChildren.start(node.getNativeChildren());
collectStateRecursively(node, 0, 0, width, height);
@@ -147,11 +157,18 @@ import com.facebook.react.uimanager.CatalystStylesDiffMap;
node.setAttachDetachListeners(listeners);
}
final NodeRegion[] nodeRegions = mNodeRegions.finish();
if (nodeRegions != null) {
shouldUpdateMountState = true;
node.setNodeRegions(nodeRegions);
}
if (shouldUpdateMountState) {
mOperationsQueue.enqueueUpdateMountState(
tag,
drawCommands,
listeners);
listeners,
nodeRegions);
}
final FlatShadowNode[] nativeChildren = mNativeChildren.finish();
@@ -254,6 +271,8 @@ import com.facebook.react.uimanager.CatalystStylesDiffMap;
float right = left + width;
float bottom = top + height;
updateNodeRegion(node, tag, left, top, right, bottom);
if (node.mountsToView()) {
ensureBackingViewIsCreated(node, tag, null);
@@ -264,6 +283,21 @@ import com.facebook.react.uimanager.CatalystStylesDiffMap;
updateViewBounds(node, tag, left, top, right, bottom);
} else {
collectStateRecursively(node, left, top, right, bottom);
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));
}
}