Skip to content

Commit 3412294

Browse files
committed
Fix linting
1 parent 795490c commit 3412294

File tree

5 files changed

+85
-57
lines changed

5 files changed

+85
-57
lines changed

RELEASE_NOTES.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,23 @@ Until then, deprecated features may be removed in any minor version.
66

77

88

9+
## 0.8
10+
11+
Thanks to [@gabrielribeiro](https://github.com/gabrielribeiro), this version adds a `ScrollManager` that can be used to scroll to certain parts of a scroll view.
12+
13+
This version also fixes a few 0.7 linting errors.
14+
15+
### ✨ Features
16+
17+
* The `ScrollManager` is a new type that can be used to scroll within a scroll view.
18+
* The `ScrollViewWithStickyHeader` can now take a `ScrollManager` in its initializer.
19+
20+
### 🐛 Bug Fixes
21+
22+
* This version fixes linting errors that were accidentally introduced in 0.7, since Xcode 16.3 isn't able to run build scripts.
23+
24+
25+
926
## 0.7.1
1027

1128
This version fixes a few 0.7 bugs and behaviors.

Sources/ScrollKit/Examples/Examples+SpotifyAlbumScreen.swift

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,4 +157,3 @@ private struct Preview: View {
157157
return SheetPreview()
158158
}
159159
#endif
160-

Sources/ScrollKit/Extensions/View+RoundedScollContent.swift

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,13 +84,17 @@ public extension View {
8484

8585
#Preview {
8686

87-
ScrollViewWithStickyHeader(
87+
func previewHeader() -> some View {
88+
Color.red
89+
}
90+
91+
return ScrollViewWithStickyHeader(
8892
.vertical,
89-
header: { Color.red },
93+
header: previewHeader,
9094
headerHeight: 250,
9195
headerMinHeight: 150,
9296
contentCornerRadius: 20,
93-
showsIndicators: false,
97+
showsIndicators: false
9498
) {
9599
LazyVStack {
96100
ForEach(1...100, id: \.self) {

Sources/ScrollKit/ScrollKit.docc/Articles/Getting-Started-Article.md

Lines changed: 44 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -22,48 +22,6 @@ There are however many other scroll utilities in this library. Some have been re
2222

2323

2424

25-
## How to track scroll offset
26-
27-
Althouth there are native alternatives, ScrollKit has a ``ScrollViewWithOffsetTracking`` that triggers an action when it's scrolled:
28-
29-
```swift
30-
struct MyView: View {
31-
32-
@State
33-
private var offset = CGPoint.zero
34-
35-
func handleOffset(_ scrollOffset: CGPoint) {
36-
self.offset = scrollOffset
37-
}
38-
39-
var body: some View {
40-
ScrollViewWithOffsetTracking(onScroll: handleOffset) {
41-
// Add your scroll content here, e.g. a `LazyVStack`
42-
}
43-
}
44-
}
45-
```
46-
47-
You can also use the ``ScrollViewOffsetTracker`` together with the ``SwiftUICore/View/scrollViewOffsetTracking(action:)`` view modifier:
48-
49-
```swift
50-
List {
51-
ScrollViewOffsetTracker {
52-
ForEach(0...100, id: \.self) {
53-
Text("\($0)")
54-
.frame(width: 200, height: 200)
55-
}
56-
}
57-
}
58-
.scrollViewOffsetTracking { offset in
59-
print(offset)
60-
}
61-
```
62-
63-
You use the offset in any way you like, e.g. to fade navigation bar title. This is how ``ScrollViewWithStickyHeader`` is implemented.
64-
65-
66-
6725
## How to set up a scroll view with a sticky header
6826

6927
You can use the ``ScrollViewWithStickyHeader`` view to create a scroll view that has a header view that stretches and transforms when it's pulled down, and sticks to the top as the scroll view content is scrolled:
@@ -109,13 +67,53 @@ The visibleHeaderRatio is how many percent (0-1) that is visible below the navig
10967

11068

11169

112-
## How to set up a scroll view with a header and overlapping content
70+
## How to track scroll offset
71+
72+
Althouth there are native alternatives, ScrollKit has a ``ScrollViewWithOffsetTracking`` that triggers an action when it's scrolled:
73+
74+
```swift
75+
struct MyView: View {
76+
77+
@State
78+
private var offset = CGPoint.zero
79+
80+
func handleOffset(_ scrollOffset: CGPoint) {
81+
self.offset = scrollOffset
82+
}
83+
84+
var body: some View {
85+
ScrollViewWithOffsetTracking(onScroll: handleOffset) {
86+
// Add your scroll content here, e.g. a `LazyVStack`
87+
}
88+
}
89+
}
90+
```
91+
92+
You can also use the ``ScrollViewOffsetTracker`` together with the ``SwiftUICore/View/scrollViewOffsetTracking(action:)`` view modifier:
93+
94+
```swift
95+
List {
96+
ScrollViewOffsetTracker {
97+
ForEach(0...100, id: \.self) {
98+
Text("\($0)")
99+
.frame(width: 200, height: 200)
100+
}
101+
}
102+
}
103+
.scrollViewOffsetTracking { offset in
104+
print(offset)
105+
}
106+
```
107+
108+
You use the offset in any way you like, e.g. to fade navigation bar title. This is how ``ScrollViewWithStickyHeader``, which also provides you with the scroll offset, is implemented.
109+
110+
113111

114-
A common design pattern is to apply rounded corners to the scroll content, and have it overlay the scroll view header. You can use the ``SwiftUICore/View/scrollViewHeaderRoundedOverlap(_:cornerRadius:)`` view extension to achieve this effect:
112+
## How to trigger scrolling with code
115113

116-
![Screenshot](Rounded-Corners)
114+
You can use the ``ScrollManager`` to scroll to certain parts of a scroll view. See the documentation on how to set it up.
117115

118-
ScrollKit also has a ``SwiftUICore/View/scrollViewHeaderOverlap(_:)`` variant that just applies the overlap, withough any other view modifications.
116+
The ``ScrollViewWithStickyHeader`` applies the propert header and content IDs, and lets you inject a manager and use it to scroll within the scroll view.
119117

120118

121119

Sources/ScrollKit/ScrollViewWithStickyHeader.swift

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -199,8 +199,13 @@ private extension ScrollViewWithStickyHeader {
199199
}
200200

201201
#Preview("Demo") {
202-
ScrollViewWithStickyHeader(
203-
header: { Color.red },
202+
203+
func previewHeader() -> some View {
204+
Color.red
205+
}
206+
207+
return ScrollViewWithStickyHeader(
208+
header: previewHeader,
204209
headerHeight: 200,
205210
headerMinHeight: nil
206211
) {
@@ -294,12 +299,9 @@ private struct Preview: View {
294299
headerHeight: 250,
295300
headerMinHeight: 100,
296301
headerStretch: false,
297-
contentCornerRadius: 10, //contentCornerRadius,
302+
contentCornerRadius: 10, // contentCornerRadius,
298303
showsIndicators: false,
299-
onScroll: { offset, visibleHeaderRatio in
300-
self.scrollOffset = offset
301-
self.visibleHeaderRatio = visibleHeaderRatio
302-
}
304+
onScroll: handleScroll
303305
) {
304306
LazyVStack {
305307
ForEach(1...100, id: \.self) {
@@ -315,6 +317,14 @@ private struct Preview: View {
315317
.background(Color.yellow)
316318
}
317319
}
320+
321+
func handleScroll(
322+
offset: CGPoint,
323+
visibleHeaderRatio: CGFloat
324+
) {
325+
self.scrollOffset = offset
326+
self.visibleHeaderRatio = visibleHeaderRatio
327+
}
318328
}
319329

320330
private extension View {

0 commit comments

Comments
 (0)