marisLincoln
marisLincoln

Reputation: 39

SwiftUI: Alternatives to using ListView?

I want to have a scrollable list that when each row is tapped, it takes you to a different view. Inside each row, I want to have a heart button that when tapped overrides the navigation behavior and just toggles a heart fill/unfill.
As an alternative to do this, would it make sense to use a ScrollView inside a NavigationView and then have each list item be a VStack?

Pseudocode hierarchy:

NavigationView {
   ScrollView {
      VStack {
         // Button       
      }
  }
}

Is there a better way ( or more preferred way) to accomplish this?

Upvotes: 0

Views: 2327

Answers (1)

Zain Ul Abideen
Zain Ul Abideen

Reputation: 783

Use LazyVStack

let items = ["A","B"]

var body: some View {
    ScrollView {
        LazyVStack(spacing: 10) {
            ForEach(items, id: \.self) { item in
                Text(item)
            }
        }
    }
}

Upvotes: 1

Related Questions