react / react/react-native

<VirtualizedList renderScrollComponent> should preserve child elements

Aperta
#40,740 3 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Component: VirtualizedList Needs: Repro Needs: Triage :mag: Never gets stale
Lingua principale
C++
Stelle
127k
Fork
25.3k
Merge medio
1g 23h
PR unite (30g)
4

Descrizione

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

Guida per i contributori

Apri la guida per i contributori

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Direzione di ricerca

Inizia in packages/virtualized-lists/Lists/VirtualizedList.js, intorno alla costruzione di scrollProps e alla chiamata a cloneElement collegate nell'issue. Riproduci gli esempi di renderScrollComponent, quindi determina se la conservazione dell'elemento figlio avvolto può essere verificata con un test di regressione appropriato e se il comportamento proposto di children è accettabile come modifica dell'API.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
javascript, react-native
Ambito
mobile
Tipo di issue
Bug
Difficoltà
4/5
Tempo stimato
3-5 giorni
Stato di attività
Ferma
Chiarezza
Abbastanza chiara
Idoneità per principianti
35/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.