Fix touch inspector when using Nodes

Reviewed By: astreet

Differential Revision: D3433927

fbshipit-source-id: 5b17a16191f167db8f4491da37a1735e725e99b8
This commit is contained in:
Ahmed El-Helw 2016-06-15 12:23:13 -07:00 committed by Facebook Github Bot 5
parent 9803f3b0dc
commit f236667a17
2 changed files with 29 additions and 3 deletions

View File

@ -77,7 +77,8 @@ public class JSTouchDispatcher {
ev.getX(),
ev.getY(),
mRootViewGroup,
mTargetCoordinates);
mTargetCoordinates,
null);
eventDispatcher.dispatchEvent(
TouchEvent.obtain(
mTargetTag,

View File

@ -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]);
}
}