Skip to content

Fix touch target for views with z-index #13705

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// Copyright 2004-present Facebook. All Rights Reserved.

package com.facebook.react.uimanager;

/**
* ViewGroup that supports z-index.
*/
public interface ReactZIndexedViewGroup {
/**
* Determine the index of a child view at {@param index} considering z-index.
* @param index The child view index
* @return The child view index considering z-index
*/
int getZIndexMappedChildIndex(int index);
}
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,13 @@ private static View findClosestReactAncestor(View view) {
*/
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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,16 @@
import com.facebook.react.uimanager.ReactClippingViewGroup;
import com.facebook.react.uimanager.ReactClippingViewGroupHelper;
import com.facebook.react.uimanager.ReactPointerEventsView;
import com.facebook.react.uimanager.ReactZIndexedViewGroup;
import com.facebook.react.uimanager.ViewGroupDrawingOrderHelper;

/**
* Backing for a React View. Has support for borders, but since borders aren't common, lazy
* initializes most of the storage needed for them.
*/
public class ReactViewGroup extends ViewGroup implements
ReactInterceptingViewGroup, ReactClippingViewGroup, ReactPointerEventsView, ReactHitSlopView {
ReactInterceptingViewGroup, ReactClippingViewGroup, ReactPointerEventsView, ReactHitSlopView,
ReactZIndexedViewGroup {

private static final int ARRAY_CAPACITY_INCREMENT = 12;
private static final int DEFAULT_BACKGROUND_COLOR = Color.TRANSPARENT;
Expand Down Expand Up @@ -408,6 +410,15 @@ protected int getChildDrawingOrder(int childCount, int index) {
return mDrawingOrderHelper.getChildDrawingOrder(childCount, index);
}

@Override
public int getZIndexMappedChildIndex(int index) {
if (mDrawingOrderHelper.shouldEnableCustomDrawingOrder()) {
return mDrawingOrderHelper.getChildDrawingOrder(getChildCount(), index);
} else {
return index;
}
}

@Override
public PointerEvents getPointerEvents() {
return mPointerEvents;
Expand Down