7
7
8
8
package com .facebook .react .uimanager ;
9
9
10
+ import android .annotation .SuppressLint ;
10
11
import android .graphics .Matrix ;
11
12
import android .graphics .PointF ;
12
13
import android .graphics .Rect ;
@@ -107,6 +108,7 @@ public static int findTargetTagAndCoordinatesForTouch(
107
108
* @return If a target was found, returns a path through the view tree of all react tags that are
108
109
* a container for the touch target, ordered from target to root (last element)
109
110
*/
111
+ @ SuppressLint ("ResourceType" )
110
112
public static List <Integer > findTargetPathAndCoordinatesForTouch (
111
113
float eventX , float eventY , ViewGroup viewGroup , float [] viewCoords ) {
112
114
UiThreadUtil .assertOnUiThread ();
@@ -119,16 +121,29 @@ public static List<Integer> findTargetPathAndCoordinatesForTouch(
119
121
View targetView = findTouchTargetViewWithPointerEvents (viewCoords , viewGroup , pathAccumulator );
120
122
121
123
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 ()) {
125
139
pathAccumulator .add (0 , targetTag );
126
140
}
127
141
}
128
142
129
143
return pathAccumulator ;
130
144
}
131
145
146
+ @ SuppressLint ("ResourceType" )
132
147
private static View findClosestReactAncestor (View view ) {
133
148
while (view != null && view .getId () <= 0 ) {
134
149
view = (View ) view .getParent ();
0 commit comments