Skip to content

[Android] Handle gestures on transparent views directly under the Detector#3962

Open
j-piasecki wants to merge 1 commit intomainfrom
@jpiasecki/fix-transparent-views-android
Open

[Android] Handle gestures on transparent views directly under the Detector#3962
j-piasecki wants to merge 1 commit intomainfrom
@jpiasecki/fix-transparent-views-android

Conversation

@j-piasecki
Copy link
Member

Description

When using the new API, the direct descendant of the Detector component always passes through shouldHandlerlessViewBecomeTouchTarget. If that view happens to be transparent, it will not be taken into account during hit testing unless it's not a ViewGroup.

This PR adds an explicit check to ensure that views that are direct children of a Detector component are always considered for hit testing, even if they are transparent.

Test plan

import React from 'react';
import { StyleSheet, View } from 'react-native';
import {
  GestureDetector,
  GestureHandlerRootView,
  useTapGesture,
} from 'react-native-gesture-handler';

export default function EmptyExample() {
  const tap = useTapGesture({
    onActivate: () => {
      console.log('tap');
    },
  });

  return (
    <GestureHandlerRootView style={styles.container}>
      <GestureDetector gesture={tap}>
        <View style={{ flex: 1, backgroundColor: 'transparent' }} collapsable={false} />
      </GestureDetector>
    </GestureHandlerRootView>
  );
}

const styles = StyleSheet.create({
  container: {
    flex: 1,
  },
});

Copilot AI review requested due to automatic review settings February 6, 2026 14:26
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adjusts Android hit-testing in GestureHandlerOrchestrator so that transparent views that are direct children of RNGestureHandlerDetectorView are still considered valid touch targets, aligning behavior with the new GestureDetector API expectations.

Changes:

  • Add an explicit RNGestureHandlerDetectorView parent check when deciding whether a handlerless view can become a touch target.
  • Refactor the touch-target predicate into clearer intermediate booleans (isLeaf, isNotTransparent, isDirectDetectorChild, isPointInView).

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant