@@ -10,12 +10,14 @@ public struct HStackSnapCore<Content: View>: View {
10
10
11
11
public init (
12
12
leadingOffset: CGFloat ,
13
+ spacing: CGFloat ? = nil ,
13
14
coordinateSpace: String = " SnapToScroll " ,
14
15
@ViewBuilder content: @escaping ( ) -> Content ,
15
16
eventHandler: SnapToScrollEventHandler ? = . none) {
16
17
17
18
self . content = content
18
19
self . targetOffset = leadingOffset
20
+ self . spacing = spacing
19
21
self . scrollOffset = leadingOffset
20
22
self . coordinateSpace = coordinateSpace
21
23
self . eventHandler = eventHandler
@@ -27,9 +29,8 @@ public struct HStackSnapCore<Content: View>: View {
27
29
GeometryReader { geometry in
28
30
29
31
HStack {
30
- HStack ( content: content)
32
+ HStack ( spacing : spacing , content: content)
31
33
. offset ( x: scrollOffset, y: . zero)
32
- . animation ( . easeOut( duration: 0.2 ) )
33
34
34
35
Spacer ( )
35
36
}
@@ -124,7 +125,9 @@ public struct HStackSnapCore<Content: View>: View {
124
125
}
125
126
126
127
// Update state
127
- scrollOffset = closestSnapLocation
128
+ withAnimation ( . easeOut( duration: 0.2 ) ) {
129
+ scrollOffset = closestSnapLocation
130
+ }
128
131
prevScrollOffset = scrollOffset
129
132
}
130
133
}
@@ -155,6 +158,9 @@ public struct HStackSnapCore<Content: View>: View {
155
158
/// Calculated offset based on `SnapLocation`
156
159
@State private var targetOffset : CGFloat
157
160
161
+ /// Space between content views`
162
+ @State private var spacing : CGFloat ?
163
+
158
164
/// The original offset of each frame, used to calculate `scrollOffset`
159
165
@State private var snapLocations : [ Int : CGFloat ] = [ : ]
160
166
0 commit comments