title: SwiftUI horizontal ScrollView wanting to auto centre item
body: <p>I’m very new to SwiftUI and trying to figure out the best way to handle this.</p>
  
  <p>I have set up a card view and that I have in a horizontal ScrollView. I am trying to get it to snap or align to the next card so it is always central. Think App Store apps or games tab in the header, I want it to behave like this.</p>
  
  <p>I have searched around a lot for this but cant seem to find a solution, at least in SwiftUI. I implemented a similar thing in a UIKit app but I’m looking for a native SwiftUI solution if at all possible. This is what I implemented previously <a href="https://github.com/BenEmdon/CenteredCollectionView" rel="nofollow noreferrer">https://github.com/BenEmdon/CenteredCollectionView</a> Though I am trying to seek a lighter and native SwiftUI way of doing this if at all possible as I always felt this was a little heavy for what I need.</p>
  
  <p>The code I have so far is as follows:</p>
  
  <pre><code>ScrollView(.horizontal, 
             content: {
                 HStack {
                     CardView(card: cardDetails)
                     CardView(card: cardDetails)
                     CardView(card: cardDetails)
                     CardView(card: cardDetails)
                 }
                 .padding(.leading, 10)
  })
  .frame(height: 250)
  
  struct CardView: View {
      let card: Card
  
      var body: some View {
          ZStack {
              RoundedRectangle(cornerRadius: 25, style: .continuous)
                  .fill(Color.white)
  
              VStack {
                  Text(card.prompt)
                      .font(.largeTitle)
                      .foregroundColor(.black)
  
                  Text(card.answer)
                      .font(.title)
                      .foregroundColor(.gray)
              }
              .padding(20)
              .multilineTextAlignment(.center)
          }
          .frame(width: 450, height: 250)
      }
  }
  </code></pre>
  
  <p>Any input will be greatly appreciated, thank you in advance for your help.</p>
  
  <p>Here is an image from the App Store, the header section is similar to what I want to achieve, when you scroll through these it scrolls on a per item basis and almost snaps to the next item rather than a free scroll:</p>
  
  <p><a href="https://i.stack.imgur.com/jaERH.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/jaERH.jpg" alt="enter image description here"></a></p>