Skip to content

Commit a2e0430

Browse files
committed
Align the alpha traversal gate with iOS
1 parent 162c21d commit a2e0430

2 files changed

Lines changed: 10 additions & 3 deletions

File tree

‎packages/react-native-gesture-handler/android/src/main/java/com/swmansion/gesturehandler/core/GestureHandlerOrchestrator.kt‎

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -871,9 +871,11 @@ class GestureHandlerOrchestrator(
871871
// A child view is handling touch, also extract handlers attached to this view
872872
if (found) {
873873
recordViewHandlersForPointer(view, coords, pointerId, event)
874-
} else if (view is RNGestureHandlerDetectorView) {
874+
} else if (view is RNGestureHandlerDetectorView && !allChildrenHidden(view)) {
875875
// No child consumed the touch, but we still record the detector's own handlers so
876-
// that `hitSlop` expansion keeps working. The detector's frame ignores
876+
// that `hitSlop` expansion keeps working. Skipped when every child is hidden or
877+
// below the alpha gate, otherwise the detector would stay tappable while its
878+
// content is invisible. The detector's frame ignores
877879
// child transforms, so for a single-child detector we check bounds in the child's
878880
// transform-aware coordinate space - otherwise the detector would steal presses over
879881
// areas its content has been moved away from.
@@ -911,6 +913,10 @@ class GestureHandlerOrchestrator(
911913

912914
private fun canReceiveEvents(view: View) = view.visibility == View.VISIBLE && view.alpha >= minimumAlphaForTraversal
913915

916+
// True when the group has children and none of them can receive events (hidden or below the alpha gate).
917+
private fun allChildrenHidden(viewGroup: ViewGroup) =
918+
viewGroup.childCount > 0 && (0 until viewGroup.childCount).none { canReceiveEvents(viewGroup.getChildAt(it)) }
919+
914920
// if view is not a view group it is clipping, otherwise we check for `getClipChildren` flag to
915921
// be turned on and also confirm with the ViewConfigHelper implementation
916922
private fun isClipping(view: View) = view !is ViewGroup || viewConfigHelper.isViewClippingChildren(view)

‎packages/react-native-gesture-handler/android/src/main/java/com/swmansion/gesturehandler/react/RNGestureHandlerRootHelper.kt‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,8 @@ class RNGestureHandlerRootHelper(private val context: ReactContext, wrappedView:
185185
}
186186

187187
companion object {
188-
private const val MIN_ALPHA_FOR_TOUCH = 0.1f
188+
// Same threshold as UIKit / RCTViewComponentView hit testing on iOS.
189+
private const val MIN_ALPHA_FOR_TOUCH = 0.01f
189190
private fun findRootViewTag(viewGroup: ViewGroup): ViewGroup {
190191
UiThreadUtil.assertOnUiThread()
191192
var parent: ViewParent? = viewGroup

0 commit comments

Comments
 (0)