0

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?

1
  • Yep, use a ForEach inside a container VStack. Then inside the ForEach, add your VStack that contains a button. Commented Jun 1, 2021 at 15:04

1 Answer 1

1

Use LazyVStack

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

var body: some View {
    ScrollView {
        LazyVStack(spacing: 10) {
            ForEach(items, id: \.self) { item in
                Text(item)
            }
        }
    }
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.