Hi,
I'm working on a app with a List as my main view. Previously I was using a TableViewController to present content. I wanted to know if there is a way to have reusable rows in List to make it more optimized like reusable cells, because this app is loading a lot of rows from an API (list of users and posts) which can be infinite as the user scrolls in the view. I'm currently doing it this way:
import SwiftUI
struct TimelineView : View {
// The custom class containing users and posts
@ObjectBinding var timeline: Timeline
var body: some View {
List {
// Show users
Section(header: Text("timeline_section_users")) {
ForEach(timeline.userObjects) { user in
// The view for a user
UserView(user: user)
}
}
// Show posts
Section(header: Text("timeline_section_posts")) {
ForEach(timeline.postObjects) { post in
// The view for a post
PostView(post: post)
}
}
// Load more
Section {
Text("Loading...").onAppear() {
// When this text appears, we call the API for more content
self.timeline.loadContent()
}
}
}
.listStyle(.grouped)
.navigationBarTitle(Text(timeline.name()))
}
}Is this the correct way to do it? Or is there another optimized way to have reusable rows like cells in TableViews?