@@ -10,12 +10,14 @@ public struct HStackSnapCore<Content: View>: View {
1010
1111 public init (
1212 leadingOffset: CGFloat ,
13+ spacing: CGFloat ? = nil ,
1314 coordinateSpace: String = " SnapToScroll " ,
1415 @ViewBuilder content: @escaping ( ) -> Content ,
1516 eventHandler: SnapToScrollEventHandler ? = . none) {
1617
1718 self . content = content
1819 self . targetOffset = leadingOffset
20+ self . spacing = spacing
1921 self . scrollOffset = leadingOffset
2022 self . coordinateSpace = coordinateSpace
2123 self . eventHandler = eventHandler
@@ -27,9 +29,8 @@ public struct HStackSnapCore<Content: View>: View {
2729 GeometryReader { geometry in
2830
2931 HStack {
30- HStack ( content: content)
32+ HStack ( spacing : spacing , content: content)
3133 . offset ( x: scrollOffset, y: . zero)
32- . animation ( . easeOut( duration: 0.2 ) )
3334
3435 Spacer ( )
3536 }
@@ -124,7 +125,9 @@ public struct HStackSnapCore<Content: View>: View {
124125 }
125126
126127 // Update state
127- scrollOffset = closestSnapLocation
128+ withAnimation ( . easeOut( duration: 0.2 ) ) {
129+ scrollOffset = closestSnapLocation
130+ }
128131 prevScrollOffset = scrollOffset
129132 }
130133 }
@@ -155,6 +158,9 @@ public struct HStackSnapCore<Content: View>: View {
155158 /// Calculated offset based on `SnapLocation`
156159 @State private var targetOffset : CGFloat
157160
161+ /// Space between content views`
162+ @State private var spacing : CGFloat ?
163+
158164 /// The original offset of each frame, used to calculate `scrollOffset`
159165 @State private var snapLocations : [ Int : CGFloat ] = [ : ]
160166
0 commit comments