Skip to content

Commit 1ce2284

Browse files
author
Trent Guillory
committed
Added more readme details.
1 parent 1cc8468 commit 1ce2284

File tree

1 file changed

+42
-1
lines changed

1 file changed

+42
-1
lines changed

README.md

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,44 @@
11
# SnapToScroll
22

3-
A description of this package.
3+
Drop-in container view for horizontal snapping.
4+
5+
## Getting Started
6+
7+
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!
42+
43+
## How it Works
44+

0 commit comments

Comments
 (0)