Skip to content

Commit

Permalink
Fix touch inspector when using Nodes
Browse files Browse the repository at this point in the history
Reviewed By: astreet

Differential Revision: D3433927

fbshipit-source-id: 5b17a16191f167db8f4491da37a1735e725e99b8
  • Loading branch information
Ahmed El-Helw authored and Facebook Github Bot 5 committed Jun 15, 2016
1 parent 9803f3b commit f236667
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,8 @@ public void handleTouchEvent(MotionEvent ev, EventDispatcher eventDispatcher) {
ev.getX(),
ev.getY(),
mRootViewGroup,
mTargetCoordinates);
mTargetCoordinates,
null);
eventDispatcher.dispatchEvent(
TouchEvent.obtain(
mTargetTag,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,27 @@ public static int findTargetTagForTouch(
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);
}

/**
Expand All @@ -57,13 +77,15 @@ public static int findTargetTagForTouch(
* @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.
Expand All @@ -73,6 +95,9 @@ public static int findTargetTagAndCoordinatesForTouch(
if (nativeTargetView != null) {
View reactTargetView = findClosestReactAncestor(nativeTargetView);
if (reactTargetView != null) {
if (nativeViewTag != null) {
nativeViewTag[0] = reactTargetView.getId();
}
targetTag = getTouchTargetForView(reactTargetView, viewCoords[0], viewCoords[1]);
}
}
Expand Down

0 comments on commit f236667

Please sign in to comment.