Fix touch target for views with z-index

Summary:
The new implementation of z-index did not handle touches properly. This fixes it by using the mapped child index like we do in `getChildDrawingOrder` in `TouchTargetHelper`.

**Test plan**
Tested that touchables work properly inside sticky headers (it uses z-index) on Android.
Closes https://github.com/facebook/react-native/pull/13705

Reviewed By: AaaChiuuu

Differential Revision: D4987964

Pulled By: sahrens

fbshipit-source-id: 165f98e23d2f304c4dc87f536c22b68a8923d806
This commit is contained in:
Janic Duplessis
2017-05-02 16:03:38 -07:00
committed by Facebook Github Bot
parent 70632615f3
commit 6f092a4264
3 changed files with 33 additions and 2 deletions
@@ -124,8 +124,13 @@ public class TouchTargetHelper {
*/
private static View findTouchTargetView(float[] eventCoords, ViewGroup viewGroup) {
int childrenCount = viewGroup.getChildCount();
// Consider z-index when determining the touch target.
ReactZIndexedViewGroup zIndexedViewGroup = viewGroup instanceof ReactZIndexedViewGroup ?
(ReactZIndexedViewGroup) viewGroup :
null;
for (int i = childrenCount - 1; i >= 0; i--) {
View child = viewGroup.getChildAt(i);
int childIndex = zIndexedViewGroup != null ? zIndexedViewGroup.getZIndexMappedChildIndex(i) : i;
View child = viewGroup.getChildAt(childIndex);
PointF childPoint = mTempPoint;
if (isTransformedTouchPointInView(eventCoords[0], eventCoords[1], viewGroup, child, childPoint)) {
// If it is contained within the child View, the childPoint value will contain the view