From f236667a17091569fbe1aed4f666fd7bddca0708 Mon Sep 17 00:00:00 2001 From: Ahmed El-Helw Date: Wed, 15 Jun 2016 12:23:13 -0700 Subject: [PATCH] Fix touch inspector when using Nodes Reviewed By: astreet Differential Revision: D3433927 fbshipit-source-id: 5b17a16191f167db8f4491da37a1735e725e99b8 --- .../react/uimanager/JSTouchDispatcher.java | 3 +- .../react/uimanager/TouchTargetHelper.java | 29 +++++++++++++++++-- 2 files changed, 29 insertions(+), 3 deletions(-) diff --git a/ReactAndroid/src/main/java/com/facebook/react/uimanager/JSTouchDispatcher.java b/ReactAndroid/src/main/java/com/facebook/react/uimanager/JSTouchDispatcher.java index 0fba85655..bbe5fc995 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/uimanager/JSTouchDispatcher.java +++ b/ReactAndroid/src/main/java/com/facebook/react/uimanager/JSTouchDispatcher.java @@ -77,7 +77,8 @@ public class JSTouchDispatcher { ev.getX(), ev.getY(), mRootViewGroup, - mTargetCoordinates); + mTargetCoordinates, + null); eventDispatcher.dispatchEvent( TouchEvent.obtain( mTargetTag, diff --git a/ReactAndroid/src/main/java/com/facebook/react/uimanager/TouchTargetHelper.java b/ReactAndroid/src/main/java/com/facebook/react/uimanager/TouchTargetHelper.java index 8c74639d5..4ef74fafc 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/uimanager/TouchTargetHelper.java +++ b/ReactAndroid/src/main/java/com/facebook/react/uimanager/TouchTargetHelper.java @@ -46,7 +46,27 @@ public class TouchTargetHelper { float eventX, float eventY, ViewGroup viewGroup) { - return findTargetTagAndCoordinatesForTouch(eventX, eventY, viewGroup, mEventCoords); + return findTargetTagAndCoordinatesForTouch( + eventX, eventY, viewGroup, mEventCoords, null); + } + + /** + * Find touch event target view within the provided container given the coordinates provided + * via {@link MotionEvent}. + * + * @param eventX the X screen coordinate of the touch location + * @param eventY the Y screen coordinate of the touch location + * @param viewGroup the container view to traverse + * @param nativeViewId the native react view containing this touch target + * @return the react tag ID of the child view that should handle the event + */ + public static int findTargetTagForTouch( + float eventX, + float eventY, + ViewGroup viewGroup, + @Nullable int[] nativeViewId) { + return findTargetTagAndCoordinatesForTouch( + eventX, eventY, viewGroup, mEventCoords, nativeViewId); } /** @@ -57,13 +77,15 @@ public class TouchTargetHelper { * @param eventY the Y screen coordinate of the touch location * @param viewGroup the container view to traverse * @param viewCoords an out parameter that will return the X,Y value in the target view + * @param nativeViewTag an out parameter that will return the native view id * @return the react tag ID of the child view that should handle the event */ public static int findTargetTagAndCoordinatesForTouch( float eventX, float eventY, ViewGroup viewGroup, - float[] viewCoords) { + float[] viewCoords, + @Nullable int[] nativeViewTag) { UiThreadUtil.assertOnUiThread(); int targetTag = viewGroup.getId(); // Store eventCoords in array so that they are modified to be relative to the targetView found. @@ -73,6 +95,9 @@ public class TouchTargetHelper { if (nativeTargetView != null) { View reactTargetView = findClosestReactAncestor(nativeTargetView); if (reactTargetView != null) { + if (nativeViewTag != null) { + nativeViewTag[0] = reactTargetView.getId(); + } targetTag = getTouchTargetForView(reactTargetView, viewCoords[0], viewCoords[1]); } }