mirror of
https://github.com/zhigang1992/react-native.git
synced 2026-04-05 17:30:38 +08:00
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:
committed by
Ahmed El-Helw
parent
8de2acd3a9
commit
dad378e394
@@ -19,11 +19,13 @@ import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.view.ViewParent;
|
||||
|
||||
import com.facebook.react.uimanager.ReactCompoundView;
|
||||
|
||||
/**
|
||||
* A view that FlatShadowNode hierarchy maps to. Performs drawing by iterating over
|
||||
* array of DrawCommands, executing them one by one.
|
||||
*/
|
||||
/* package */ final class FlatViewGroup extends ViewGroup {
|
||||
/* package */ final class FlatViewGroup extends ViewGroup implements ReactCompoundView {
|
||||
/**
|
||||
* Helper class that allows AttachDetachListener to invalidate the hosting View.
|
||||
*/
|
||||
@@ -47,6 +49,7 @@ import android.view.ViewParent;
|
||||
private @Nullable InvalidateCallback mInvalidateCallback;
|
||||
private DrawCommand[] mDrawCommands = DrawCommand.EMPTY_ARRAY;
|
||||
private AttachDetachListener[] mAttachDetachListeners = AttachDetachListener.EMPTY_ARRAY;
|
||||
private NodeRegion[] mNodeRegions = NodeRegion.EMPTY_ARRAY;
|
||||
private int mDrawChildIndex = 0;
|
||||
private boolean mIsAttached = false;
|
||||
|
||||
@@ -59,6 +62,19 @@ import android.view.ViewParent;
|
||||
super.detachAllViewsFromParent();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int reactTagForTouch(float touchX, float touchY) {
|
||||
for (NodeRegion nodeRegion : mNodeRegions) {
|
||||
if (nodeRegion.mLeft <= touchX && touchX < nodeRegion.mRight &&
|
||||
nodeRegion.mTop <= touchY && touchY < nodeRegion.mBottom) {
|
||||
return nodeRegion.mTag;
|
||||
}
|
||||
}
|
||||
|
||||
// no children found
|
||||
return getId();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void dispatchDraw(Canvas canvas) {
|
||||
super.dispatchDraw(canvas);
|
||||
@@ -143,6 +159,10 @@ import android.view.ViewParent;
|
||||
mAttachDetachListeners = listeners;
|
||||
}
|
||||
|
||||
/* package */ void mountNodeRegions(NodeRegion[] nodeRegions) {
|
||||
mNodeRegions = nodeRegions;
|
||||
}
|
||||
|
||||
/* package */ void mountViews(ViewResolver viewResolver, int[] viewsToAdd, int[] viewsToDetach) {
|
||||
for (int viewToAdd : viewsToAdd) {
|
||||
if (viewToAdd > 0) {
|
||||
|
||||
Reference in New Issue
Block a user