[Android] `Touchable` doesn't call onPress when you tap on a` TextInput editable={false}` child

Ouverte
#4,622 4 commentaires 0 réactions 0 personnes assignées Voir sur GitHub

Les mainteneurs répondent en général sous 2 jours

Personne n'a encore pris cette issue.

Évaluation

Difficulté
3/5
Temps estimé
1-2 jours
Accessibilité débutants
55/100
Type d'issue
Bug
Clarté
Plutôt claire
Activité
Active
Stack technique
react-native, typescript
Domaine
frontend, mobile

Piste de recherche

Start by comparing RNGH Touchable and Pressable behavior with React Native's Pressable using the reproduction in the issue: a disabled TextInput inside each component on Android. Check the relevant gesture and touch handling entry points and existing tests for disabled TextInput children. Done when RNGH invokes onPress consistently with the intended Android behavior and the regression is covered by a test.

Rédigé par le modèle d'indexation à partir du texte de l'issue.

Description

Missing info Missing repro Platform: Android
Description

Tapping a disabled TextInput doesn't trigger the onPress handler of its wrapping Touchable on Android.

The behaviour of RNGH's Touchable (and therefore Pressable) differs from the default React Native implementation. However, RN itself is inconsistent across iOS and Android, so the behaviour there also varies. Therefore, I'm not sure what is supposed to be the reference behaviour anymore, but what I can say is that it worked in RNGH v2.

Android iOS Web
RN onPress is called onPress is not called onPress is called
RNGH onPress is not called onPress is called 🤯 onPress is called

AI explanation for the default behaviour on Android:

editable={false} becomes setEnabled(false) on the native EditText.
RN's Android hit-testing treats any disabled view as box-none: "Views that are disabled should never be the target of pointer events."
So the TextInput can't be the touch target, the parent Pressable becomes the target, and onPress fires.

AI explanation for the default behaviour on iOS:

editable={false} only turns off editing. The view can still be hit.
The touch lands on the TextInput. TextInput.js attaches its own usePressability handlers whatever editable is (it just skips focus() when non-editable, around line 599).
The TextInput therefore claims the responder, and the parent Pressable never gets it, so it logs nothing.
Steps to reproduce
import { Pressable, TextInput } from 'react-native'
import { Pressable as RNGHPressable, Touchable } from 'react-native-gesture-handler'

<View>
  <Pressable onPress={() => Alert.alert('RN')}>
    <TextInput editable={false} placeholder="tap here" />
  </Pressable>

  <RNGHPressable onPress={() => Alert.alert('RNGH Pressable')}>
    <TextInput editable={false} placeholder="tap here" />
  </RNGHPressable>

  <Touchable onPress={() => Alert.alert('RNGH Touchable')}>
    <TextInput editable={false} placeholder="tap here" />
  </Touchable>
</View>
  1. Tap on the first Pressable - observe "RN" alert
  2. Tap on the secondPressable - observe no alert being shown
A link to a Gist, an Expo Snack or a link to a repository based on this template that reproduces the bug.
Gesture Handler version

3.4.0

React Native version

0.86.3

Platforms

Android

JavaScript runtime

None

Workflow

None

Build type

None

Device

None

Device model

No response

Acknowledgements

Yes

Langage dominant
TypeScript
Étoiles
6.8k
Forks
1.1k
Merge moyen
1 j 23 h
PR mergées (30 j)
46

Préparer son environnement

  • Aucun Dockerfile ni fichier Docker Compose
  • Propose un modèle de pull request
  • Aucun guide de contribution

Par où commencer

  1. Lisez l'issue en entier, puis le guide de contribution du projet.
  2. Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
  3. Forkez le dépôt et travaillez sur une branche.
  4. Ouvrez une pull request qui référence le numéro de l'issue.

Autres issues de software-mansion/react-native-gesture-handler

Toutes les issues de software-mansion/react-native-gesture-handler

Issues similaires

Plus d'issues TypeScript

Recevez les nouvelles issues par e-mail

Un résumé court des issues GitHub adaptées aux débutants.