From 51fe19084f8b70f789d650e0ee22fc32f8ec02cd Mon Sep 17 00:00:00 2001 From: Xin Chen Date: Thu, 16 Dec 2021 17:13:51 -0800 Subject: [PATCH] Do not register touch target for out of bounds events with clipChildren set to true Summary: Similar to the previous diff, we should not allow view group that has clipChildren set to true to respond events that are out of bounds. Changelog: [Internal][Android] Reviewed By: ShikaSD Differential Revision: D33102331 fbshipit-source-id: de3a5ffdd5293ada1d2c211659e79edc697b5d15 --- .../react/uimanager/TouchTargetHelper.java | 21 ++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/ReactAndroid/src/main/java/com/facebook/react/uimanager/TouchTargetHelper.java b/ReactAndroid/src/main/java/com/facebook/react/uimanager/TouchTargetHelper.java index 2fdbe18d643..e96077eddec 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/uimanager/TouchTargetHelper.java +++ b/ReactAndroid/src/main/java/com/facebook/react/uimanager/TouchTargetHelper.java @@ -178,17 +178,24 @@ public class TouchTargetHelper { // We prefer returning a child, so we check for a child that can handle the touch first if (allowReturnTouchTargetTypes.contains(TouchTargetReturnType.CHILD) && view instanceof ViewGroup) { - // We don't allow touches on views that are outside the bounds of an `overflow: hidden` and - // `overflow: scroll` View. - if (view instanceof ReactOverflowView) { - @Nullable String overflow = ((ReactOverflowView) view).getOverflow(); - if ((ViewProps.HIDDEN.equals(overflow) || ViewProps.SCROLL.equals(overflow)) - && !isTouchPointInView(eventCoords[0], eventCoords[1], view)) { + ViewGroup viewGroup = (ViewGroup) view; + if (!isTouchPointInView(eventCoords[0], eventCoords[1], view)) { + // We don't allow touches on views that are outside the bounds of an `overflow: hidden` and + // `overflow: scroll` View. + if (view instanceof ReactOverflowView) { + @Nullable String overflow = ((ReactOverflowView) view).getOverflow(); + if (ViewProps.HIDDEN.equals(overflow) || ViewProps.SCROLL.equals(overflow)) { + return null; + } + } + + // We don't allow touches on views that are outside the bounds and has clipChildren set to + // true. + if (viewGroup.getClipChildren()) { return null; } } - ViewGroup viewGroup = (ViewGroup) view; int childrenCount = viewGroup.getChildCount(); // Consider z-index when determining the touch target. ReactZIndexedViewGroup zIndexedViewGroup =