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

Create PaginatingLazyVStack as a generic scrollable list container #1983

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

amy-at-kickstarter
Copy link
Contributor

@amy-at-kickstarter amy-at-kickstarter commented Mar 18, 2024

📲 What

Add PaginatingLazyVStack to our component library.

🤔 Why

As part of SwiftUI work, I'm working on re-writing the old backer dashboard using SwiftUI. (Even if it never ships, I think the work will be educational.)

The main component of this page is going to be a scrolling list of cards. That seems like fairly generic functionality, so I wrote this paginating/refreshable VStack as a generic implementation of it.

👀 See

Here's what the example view looks like - it supports infinite scroll and pull-to-refresh.

paginating vstack example

} else {}

self.data = []
self.addMore()
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I learned some interesting things about Task and .refreshable by doing this. Any modification to data that is bound to the PaginatingLazyVStack causes a re-render, which will cancel any tasks that are currently pending in .refreshable. That's what self.data = [] has to happen after this Task.sleep; otherwise it's instantly re-rendered and canceled.

@amy-at-kickstarter amy-at-kickstarter requested review from a team, ifosli and scottkicks and removed request for a team March 19, 2024 15:33
@amy-at-kickstarter amy-at-kickstarter self-assigned this Mar 19, 2024
@amy-at-kickstarter amy-at-kickstarter marked this pull request as ready for review March 19, 2024 15:33
Comment on lines +7 to +12
@Binding var data: [Data]
@Binding var canShowProgressView: Bool

let onRefresh: () async -> Void
let onDidShowProgressView: () -> Void
let configureCell: (Data) -> Cell

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

these should all be private

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants