You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Using `SnapToScroll` is straightforward. There's only two requirements:
8
+
9
+
1. Replace `HStack` with `HStackSnap`
10
+
2. Add `GeometryReaderOverlay` to your view.
11
+
12
+
An example:
13
+
14
+
```swift
15
+
16
+
HStackSnap(leadingOffset: 16) {
17
+
18
+
ForEach(modelArray) { viewModel in
19
+
20
+
myView(viewModel: viewModel)
21
+
.frame(maxWidth: 250)
22
+
.overlay(GeometryReaderOverlay(id: viewModel.id))
23
+
}
24
+
}
25
+
}
26
+
27
+
```
28
+
For more examples, see `SnapToScrollDemo/ContentView.swift`.
29
+
30
+
## Options
31
+
32
+
`HStackSnap` comes with two customizable properties:
33
+
34
+
-`leadingOffset`: The leading padding you'd like each element to snap to.
35
+
-`coordinateSpace`: Option to set custom name for the coordinate space, in the case you're using multiple `HStackSnap`s of various sizes.
36
+
37
+
## Limitations
38
+
39
+
1. If your child views are designed to take up all available horizontal space, they'll expand beyond the visible view. Prevent this with `.frame(maxWidth: x)`
40
+
2.`HStackSnap` is currently designed to work with static content.
41
+
3. At the moment, `HStackSnap` offers snapping to the leading edge only. If you'd like to offer a PR that adds support for `.center` and / or `.trailing`, I'd love to look it over!
0 commit comments