react / react/react-native

<VirtualizedList renderScrollComponent> should preserve child elements

Abierto
#40,740 3 comentarios 0 reacciones 0 asignados Ver en GitHub

Nadie ha tomado este issue todavía.

Component: VirtualizedList Needs: Repro Needs: Triage :mag: Never gets stale
Lenguaje dominante
C++
Estrellas
127k
Forks
25.3k
Merge medio
1 d 23 h
PR fusionados (30 d)
4

Descripción

Description

It's extremely confusing that this works:

<VirtualizedList
  renderScrollComponent={props =>
    <ScrollView {...props} />
  }
  // ...
/>

but this doesn't:

<VirtualizedList
  renderScrollComponent={props =>
    <View>
      <ScrollView {...props} />
    </View>
  }
  // ...
/>

The reason appears to be that the third cells argument to cloneElement call here (which in this case would be passed a <View>) overrides the children of that top-level element. So the ScrollView inside gets lost.

What I believe should happen instead is that scrollProps should include children: cells. Then it's up to your renderScrollComponent function to decide what to do with it.

That would be a breaking change but it seems a lot more in line with how React components are supposed to work? It's bad that wrapping a top-level component completely breaks the logic. (I spent an hour debugging this because I couldn't believe a built-in RN component would do this :). It's possible that I badly misunderstood something, so apologies if that's the case.

React Native Version

0.72.5

Output of npx react-native info
info Fetching system and libraries information...
System:
  OS: macOS 13.2.1
  CPU: (10) arm64 Apple M1 Max
  Memory: 12.29 GB / 64.00 GB
  Shell:
    version: 5.8.1
    path: /bin/zsh
Binaries:
  Node:
    version: 18.17.1
    path: /usr/local/bin/node
  Yarn:
    version: 1.22.19
    path: /usr/local/bin/yarn
  npm:
    version: 9.6.7
    path: /usr/local/bin/npm
  Watchman:
    version: 2023.01.30.00
    path: /opt/homebrew/bin/watchman
Managers:
  CocoaPods:
    version: 1.11.3
    path: /opt/homebrew/bin/pod
SDKs:
  iOS SDK:
    Platforms:
      - DriverKit 22.4
      - iOS 16.4
      - macOS 13.3
      - tvOS 16.4
      - watchOS 9.4
  Android SDK: Not Found
IDEs:
  Android Studio: 2022.1 AI-221.6008.13.2211.9514443
  Xcode:
    version: 14.3.1/14E300c
    path: /usr/bin/xcodebuild
Languages:
  Java:
    version: javac 18
    path: /usr/bin/javac
  Ruby:
    version: 2.7.6
    path: /Users/dan/.rbenv/shims/ruby
npmPackages:
  "@react-native-community/cli": Not Found
  react:
    installed: 18.2.0
    wanted: 18.2.0
  react-native:
    installed: 0.72.5
    wanted: 0.72.5
  react-native-macos: Not Found
npmGlobalPackages:
  "*react-native*": Not Found
Android:
  hermesEnabled: true
  newArchEnabled: false
iOS:
  hermesEnabled: true
  newArchEnabled: false
Steps to reproduce

see earlier

Snack, screenshot, or link to a repository

this is about API design

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

Comienza en packages/virtualized-lists/Lists/VirtualizedList.js, alrededor de la construcción de scrollProps y la llamada a cloneElement enlazadas en el issue. Reproduce los ejemplos de renderScrollComponent y determina después si la conservación del elemento hijo envuelto puede cubrirse con una prueba de regresión adecuada y si el comportamiento propuesto de children es aceptable como cambio de API.

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

Evaluación

Stack tecnológico
javascript, react-native
Área
mobile
Tipo de issue
Error
Dificultad
4/5
Tiempo estimado
3-5 días
Estado de actividad
Estancado
Claridad
Bastante claro
Aptitud para principiantes
35/100

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.