Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

<VirtualizedList renderScrollComponent> should preserve child elements #40740

Open
gaearon opened this issue Oct 9, 2023 · 3 comments
Open
Labels
Component: VirtualizedList Needs: Repro This issue could be improved with a clear list of steps to reproduce the issue. Needs: Triage 🔍 Never gets stale Prevent those issues and PRs from getting stale

Comments

@gaearon
Copy link
Collaborator

gaearon commented Oct 9, 2023

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

@github-actions github-actions bot added Needs: Repro This issue could be improved with a clear list of steps to reproduce the issue. Component: VirtualizedList labels Oct 9, 2023
@github-actions
Copy link

github-actions bot commented Oct 9, 2023

⚠️ Missing Reproducible Example
ℹ️ We could not detect a reproducible example in your issue report. Please provide either:
  • If your bug is UI related: a Snack
  • If your bug is build/update related: use our Reproducer Template. A reproducer needs to be in a GitHub repository under your username.

@gaearon
Copy link
Collaborator Author

gaearon commented Oct 9, 2023

I guess there's a question of what to do with children you pass to the VirtualizedList itself. It seems like they currently exist in those {...props}. Not sure if it's useful to pass them through or if they should both be available somehow.

Copy link

github-actions bot commented Apr 7, 2024

This issue is stale because it has been open 180 days with no activity. Remove stale label or comment or this will be closed in 7 days.

@github-actions github-actions bot added the Stale There has been a lack of activity on this issue and it may be closed soon. label Apr 7, 2024
@cortinico cortinico added Never gets stale Prevent those issues and PRs from getting stale and removed Stale There has been a lack of activity on this issue and it may be closed soon. labels Apr 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Component: VirtualizedList Needs: Repro This issue could be improved with a clear list of steps to reproduce the issue. Needs: Triage 🔍 Never gets stale Prevent those issues and PRs from getting stale
Projects
None yet
Development

No branches or pull requests

2 participants