Skip to content

Commit dfe42d6

Browse files
javachefacebook-github-bot
authored andcommitted
Fix incorrect hitState when non-React views are hit
Summary: Changelog: [Android][Changed] Improved logic of findTargetPathAndCoordinatesForTouch Reviewed By: Guad Differential Revision: D31688645 fbshipit-source-id: b9ba91e135b6359e49998a314bf6c91a67fae5ed
1 parent 61755ac commit dfe42d6

File tree

1 file changed

+18
-3
lines changed

1 file changed

+18
-3
lines changed

ReactAndroid/src/main/java/com/facebook/react/uimanager/TouchTargetHelper.java

+18-3
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
package com.facebook.react.uimanager;
99

10+
import android.annotation.SuppressLint;
1011
import android.graphics.Matrix;
1112
import android.graphics.PointF;
1213
import android.graphics.Rect;
@@ -107,6 +108,7 @@ public static int findTargetTagAndCoordinatesForTouch(
107108
* @return If a target was found, returns a path through the view tree of all react tags that are
108109
* a container for the touch target, ordered from target to root (last element)
109110
*/
111+
@SuppressLint("ResourceType")
110112
public static List<Integer> findTargetPathAndCoordinatesForTouch(
111113
float eventX, float eventY, ViewGroup viewGroup, float[] viewCoords) {
112114
UiThreadUtil.assertOnUiThread();
@@ -119,16 +121,29 @@ public static List<Integer> findTargetPathAndCoordinatesForTouch(
119121
View targetView = findTouchTargetViewWithPointerEvents(viewCoords, viewGroup, pathAccumulator);
120122

121123
if (targetView != null) {
122-
View reactTargetView = findClosestReactAncestor(targetView);
123-
int targetTag = getTouchTargetForView(reactTargetView, viewCoords[0], viewCoords[1]);
124-
if (targetTag != pathAccumulator.get(0)) {
124+
View reactTargetView = targetView;
125+
int firstReactAncestor = 0;
126+
// Same logic as findClosestReactAncestor but also track the index
127+
while (reactTargetView != null && reactTargetView.getId() <= 0) {
128+
reactTargetView = (View) reactTargetView.getParent();
129+
firstReactAncestor++;
130+
}
131+
132+
if (firstReactAncestor > 0) {
133+
// Drop non-React views from the path trace
134+
pathAccumulator = pathAccumulator.subList(firstReactAncestor, pathAccumulator.size());
135+
}
136+
137+
int targetTag = getTouchTargetForView(reactTargetView, eventX, eventY);
138+
if (targetTag != reactTargetView.getId()) {
125139
pathAccumulator.add(0, targetTag);
126140
}
127141
}
128142

129143
return pathAccumulator;
130144
}
131145

146+
@SuppressLint("ResourceType")
132147
private static View findClosestReactAncestor(View view) {
133148
while (view != null && view.getId() <= 0) {
134149
view = (View) view.getParent();

0 commit comments

Comments
 (0)