react / react/react-native

Pressable onPress fires when scrolling FlatList

Abierto
#48,488 3 comentarios 3 reacciones 0 asignados Ver en GitHub

Nadie ha tomado este issue todavía.

Component: FlatList Issue: Author Provided Repro Needs: Author Feedback
Lenguaje dominante
C++
Estrellas
127k
Forks
25.3k
Merge medio
1 d 23 h
PR fusionados (30 d)
4

Descripción

Description

When you have a list of <Pressable> inside a <FlatList>, and the list is short enough to fully fit on the screen (so that no scrolling is actually needed), then if you do scroll the list a whole bunch of onPress events will fire on the Pressable list items.

The expected behavior is that onPress should only be triggered when actually pressing an item.

I initially filed this report on the FlashList repo, but after further testing I actually believe this is a React Native issue.
Here's the FlashList issue: https://github.com/Shopify/flash-list/issues/1461
Here's an older very similar React Native issue that's been closed without a fix: https://github.com/facebook/react-native/issues/27355

Steps to reproduce

See the linked FlashList issue for the code and steps needed to reproduce

React Native Version

0.76.5

Affected Platforms

Runtime - Android

Output of npx react-native info
System:
  OS: macOS 15.1.1
  CPU: (12) arm64 Apple M3 Pro
  Memory: 560.73 MB / 36.00 GB
  Shell:
    version: "5.9"
    path: /bin/zsh
Binaries:
  Node:
    version: 20.18.1
    path: /usr/local/bin/node
  Yarn:
    version: 4.5.1
    path: /usr/local/bin/yarn
  npm:
    version: 10.8.2
    path: /usr/local/bin/npm
  Watchman:
    version: 2024.12.02.00
    path: /opt/homebrew/bin/watchman
Managers:
  CocoaPods: Not Found
SDKs:
  iOS SDK:
    Platforms:
      - DriverKit 24.1
      - iOS 18.1
      - macOS 15.1
      - tvOS 18.1
      - visionOS 2.1
      - watchOS 11.1
  Android SDK:
    API Levels:
      - "34"
      - "35"
    Build Tools:
      - 34.0.0
      - 35.0.0
    System Images:
      - android-34 | Google Play ARM 64 v8a
      - android-35 | Google APIs ARM 64 v8a
      - android-35 | Google Play ARM 64 v8a
    Android NDK: Not Found
IDEs:
  Android Studio: 2024.2 AI-242.23339.11.2421.12700392
  Xcode:
    version: 16.1/16B40
    path: /usr/bin/xcodebuild
Languages:
  Java:
    version: 17.0.13
    path: /usr/bin/javac
  Ruby:
    version: 2.6.10
    path: /Users/tobbe/.rbenv/shims/ruby
npmPackages:
  "@react-native-community/cli":
    installed: 15.1.3
    wanted: ^15.1.3
  react:
    installed: 18.3.1
    wanted: 18.3.1
  react-native:
    installed: 0.76.5
    wanted: 0.76.5
  react-native-macos: Not Found
npmGlobalPackages:
  "*react-native*": Not Found
Android:
  hermesEnabled: Not found
  newArchEnabled: Not found
iOS:
  hermesEnabled: Not found
  newArchEnabled: Not found
Stacktrace or Logs
(NOBRIDGE) LOG  {"item": {"id": "3ac68afc-c605-48d3-a4f8-fbd91aa97f63", "title": "Second Item"}}
 (NOBRIDGE) LOG  {"item": {"id": "58694a0f-3da1-471f-bd96-145571e29d72", "title": "Third Item"}}
 (NOBRIDGE) LOG  {"item": {"id": "58694a0f-3da1-471f-bd96-145571e29d72", "title": "Third Item"}}
 (NOBRIDGE) LOG  {"item": {"id": "58694a0f-3da1-471f-bd96-145571e29d72", "title": "Third Item"}}
 (NOBRIDGE) LOG  {"item": {"id": "58694a0f-3da1-471f-bd96-145571e29d72", "title": "Third Item"}}
 (NOBRIDGE) LOG  {"item": {"id": "58694a0f-3da1-471f-bd96-145571e29d72", "title": "Third Item"}}
 (NOBRIDGE) LOG  {"item": {"id": "bd7acbea-c1b1-46c2-aed5-3ad53abb28ba", "title": "First Item"}}
 (NOBRIDGE) LOG  {"item": {"id": "3ac68afc-c605-48d3-a4f8-fbd91aa97f63", "title": "Second Item"}}
 (NOBRIDGE) LOG  {"item": {"id": "3ac68afc-c605-48d3-a4f8-fbd91aa97f63", "title": "Second Item"}}
 (NOBRIDGE) LOG  {"item": {"id": "3ac68afc-c605-48d3-a4f8-fbd91aa97f63", "title": "Second Item"}}
 (NOBRIDGE) LOG  {"item": {"id": "58694a0f-3da1-471f-bd96-145571e29d72", "title": "Third Item"}}
 (NOBRIDGE) LOG  {"item": {"id": "58694a0f-3da1-471f-bd96-145571e29d72", "title": "Third Item"}}
 (NOBRIDGE) LOG  {"item": {"id": "58694a0f-3da1-471f-bd96-145571e29d72", "title": "Third Item"}}
 (NOBRIDGE) LOG  {"item": {"id": "58694a0f-3da1-471f-bd96-145571e29d72", "title": "Third Item"}}
 (NOBRIDGE) LOG  {"item": {"id": "3ac68afc-c605-48d3-a4f8-fbd91aa97f63", "title": "Second Item"}}
 (NOBRIDGE) LOG  {"item": {"id": "bd7acbea-c1b1-46c2-aed5-3ad53abb28ba", "title": "First Item"}}
 (NOBRIDGE) LOG  {"item": {"id": "bd7acbea-c1b1-46c2-aed5-3ad53abb28ba", "title": "First Item"}}
 (NOBRIDGE) LOG  {"item": {"id": "bd7acbea-c1b1-46c2-aed5-3ad53abb28ba", "title": "First Item"}}
 (NOBRIDGE) LOG  {"item": {"id": "58694a0f-3da1-471f-bd96-145571e29d72", "title": "Third Item"}}
 (NOBRIDGE) LOG  {"item": {"id": "58694a0f-3da1-471f-bd96-145571e29d72", "title": "Third Item"}}
Reproducer

https://github.com/Tobbe/expo-bun-flash-list-issue

Screenshots and Videos

https://github.com/user-attachments/assets/6626450b-a771-46f5-80f1-f0d620394816

Guía de contribución

Abrir la guía de contribución

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Línea de trabajo

Empieza ejecutando el reproductor enlazado de Expo/Bun FlashList en Android con React Native 0.76.5 y confirma el comportamiento de Pressable/FlatList descrito aquí. Rastrea el comportamiento relevante de React Native a partir de esa reproducción; se considera terminado cuando desplazarse por una FlatList corta ya no dispara onPress, mientras que una pulsación real sí lo hace.

Escrito por el modelo de indexación a partir del texto del issue.

Evaluación

Stack tecnológico
android, react-native
Área
mobile-dev
Tipo de issue
Error
Dificultad
4/5
Tiempo estimado
3-5 días
Estado de actividad
Estancado
Claridad
Necesita aclaración
Aptitud para principiantes
32/100

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.