Skip to content

Commit a952166

Browse files
committed
Move examples into a new namespace and rename some view modifiers
1 parent 2aa1b15 commit a952166

23 files changed

+314
-166
lines changed

Demo/Demo/ContentView.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
// ScrollKit
44
//
55
// Created by Daniel Saidi on 2023-02-04.
6-
// Copyright © 2023-2024 Daniel Saidi. All rights reserved.
6+
// Copyright © 2023-2025 Daniel Saidi. All rights reserved.
77
//
88

99
import SwiftUI

Demo/Demo/DemoScreen.swift

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
// ScrollKit
44
//
55
// Created by Daniel Saidi on 2023-02-04.
6-
// Copyright © 2023-2024 Daniel Saidi. All rights reserved.
6+
// Copyright © 2023-2025 Daniel Saidi. All rights reserved.
77
//
88

99
import ScrollKit
@@ -21,7 +21,7 @@ struct DemoScreen<HeaderView: View>: View {
2121
let headerView: () -> HeaderView
2222

2323
@State
24-
private var headerVisibleRatio: CGFloat = 1
24+
private var visibleHeaderRatio: CGFloat = 1
2525

2626
@State
2727
private var scrollOffset: CGPoint = .zero
@@ -39,7 +39,7 @@ struct DemoScreen<HeaderView: View>: View {
3939
Text("Demo Title")
4040
.font(.headline)
4141
.previewHeaderContent()
42-
.opacity(1 - headerVisibleRatio)
42+
.opacity(1 - visibleHeaderRatio)
4343
}
4444
}
4545
.toolbarBackground(.hidden)
@@ -61,7 +61,7 @@ struct DemoScreen<HeaderView: View>: View {
6161
Text("Some additional information")
6262
}
6363
.padding(20)
64-
.opacity(headerVisibleRatio)
64+
.opacity(visibleHeaderRatio)
6565
}
6666

6767
var listItems: some View {
@@ -77,9 +77,9 @@ struct DemoScreen<HeaderView: View>: View {
7777
}
7878
}
7979

80-
func handleScrollOffset(_ offset: CGPoint, headerVisibleRatio: CGFloat) {
80+
func handleScrollOffset(_ offset: CGPoint, visibleHeaderRatio: CGFloat) {
8181
self.scrollOffset = offset
82-
self.headerVisibleRatio = headerVisibleRatio
82+
self.visibleHeaderRatio = visibleHeaderRatio
8383
}
8484
}
8585

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
MIT License
22

3-
Copyright (c) 2023-2024 Daniel Saidi
3+
Copyright (c) 2023-2025 Daniel Saidi
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

README.md

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -56,29 +56,30 @@ struct MyView: View {
5656

5757
@State
5858
private var visibleRatio = CGFloat.zero
59-
60-
func handleOffset(_ scrollOffset: CGPoint, visibleHeaderRatio: CGFloat) {
61-
self.offset = scrollOffset
62-
self.visibleRatio = visibleHeaderRatio
63-
}
64-
65-
func header() -> some View {
66-
ZStack(alignment: .bottomLeading) {
67-
Color.blue
68-
Color.yellow.opacity(visibleRatio) // Fades in
69-
}
70-
}
7159

7260
var body: some View {
7361
ScrollViewWithStickyHeader(
74-
header: header,
75-
headerHeight: 250,
76-
headerMinHeight: 150,
77-
onScroll: handleOffset
62+
header: stickyHeader, // A header view
63+
headerHeight: 250, // Its resting height
64+
headerMinHeight: 150, // Its minimum height
65+
onScroll: handleScroll // An optional scroll action
7866
) {
7967
// Add your scroll content here, e.g. a `LazyVStack`
8068
}
8169
}
70+
71+
func handleScroll(_ offset: CGPoint, visibleHeaderRatio: CGFloat) {
72+
self.scrollOffset = offset
73+
self.visibleRatio = visibleHeaderRatio
74+
}
75+
76+
func stickyHeader() -> some View {
77+
ZStack {
78+
Color.red
79+
ScrollViewHeaderGradient() // By default a dark gradient
80+
Text("Scroll offset: \(offset.y)")
81+
}
82+
}
8283
}
8384
```
8485

RELEASE_NOTES.md

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

77

88

9+
## 0.7
10+
11+
This version moves examples into a new namespace and renames some View extensions to make more sense.
12+
13+
### 🗑️ Deprecations
14+
15+
* All examples have been moved into a new `Examples` namespace.
16+
* The `hideStatusBarUntilScrolled` view extension has been renamed to `statusBarHiddenUntilScrolled`.
17+
* The `withScrollOffsetTracking` view extension has been renamed to `scrollViewOffsetTracking`.
18+
19+
20+
921
## 0.6.1
1022

1123
This version adjusts the code to address a concurrency warning.
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
//
2+
// Examples+Spotify.swift
3+
// ScrollKit
4+
//
5+
// Created by Daniel Saidi on 2023-12-04.
6+
// Copyright © 2023-2025 Daniel Saidi. All rights reserved.
7+
//
8+
9+
import Foundation
10+
11+
public extension Examples {
12+
13+
/// This namespace contains Spotify-related types.
14+
struct Spotify {}
15+
}

Sources/ScrollKit/Examples/Spotify+PreviewInfo.swift renamed to Sources/ScrollKit/Examples/Examples+SpotifyAlbum.swift

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
//
2-
// Spotify+PreviewInfo.swift
2+
// Examples+SpotifyAlbum.swift
33
// ScrollKit
44
//
55
// Created by Daniel Saidi on 2023-03-10.
6-
// Copyright © 2023-2024 Daniel Saidi. All rights reserved.
6+
// Copyright © 2023-2025 Daniel Saidi. All rights reserved.
77
//
88

99
import SwiftUI
1010

11-
public extension Spotify {
11+
public extension Examples.Spotify {
1212

1313
/// This model is used by the Spotify previews.
14-
struct PreviewInfo {
14+
struct Album {
1515

1616
public init(
1717
bandName: String,
@@ -20,7 +20,8 @@ public extension Spotify {
2020
releaseDate: Date,
2121
releaseCoverUrl: String,
2222
tintColor: Color,
23-
tracks: [String]) {
23+
tracks: [String]
24+
) {
2425
self.bandName = bandName
2526
self.releaseTitle = releaseTitle
2627
self.releaseType = releaseType
@@ -40,7 +41,7 @@ public extension Spotify {
4041
}
4142
}
4243

43-
public extension Spotify.PreviewInfo {
44+
public extension Examples.Spotify.Album {
4445

4546
static var anthrax: Self {
4647
.init(
@@ -77,7 +78,7 @@ public extension Spotify.PreviewInfo {
7778
releaseTitle: "Forsaken",
7879
releaseType: "Album",
7980
releaseDate: Calendar.current.date(from: DateComponents(year: 1999)) ?? .now,
80-
releaseCoverUrl: "https://i.discogs.com/75jm2NwzdkgIlEo9ucyl4_o1OCOzB4EQPZua8VQ5W94/rs:fit/g:sm/q:90/h:600/w:600/czM6Ly9kaXNjb2dz/LWRhdGFiYXNlLWlt/YWdlcy9SLTQzOTg5/NDUtMTM4NzIwNTE4/Ni02NTI1LmpwZWc.jpeg",
81+
releaseCoverUrl: "https://danielsaidi.com/assets/bands/misfortune/forsaken.jpg",
8182
tintColor: .init(red: 0.5, green: 0.3, blue: 0),
8283
tracks: [
8384
"Forsaken",

Sources/ScrollKit/Examples/Spotify+PreviewScreen.swift renamed to Sources/ScrollKit/Examples/Examples+SpotifyAlbumScreen.swift

Lines changed: 27 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,40 @@
11
//
2-
// Spotify+PreviewScreen.swift
2+
// Examples+SpotifyAlbumScreen.swift
33
// ScrollKit
44
//
55
// Created by Daniel Saidi on 2023-02-07.
6-
// Copyright © 2023-2024 Daniel Saidi. All rights reserved.
6+
// Copyright © 2023-2025 Daniel Saidi. All rights reserved.
77
//
88

99
import SwiftUI
1010

11-
public extension Spotify {
11+
public extension Examples.Spotify {
1212

1313
/// This view mimics a Spotify album screen.
14-
struct PreviewScreen: View {
14+
struct AlbumScreen: View {
1515

16-
public init(info: PreviewInfo) {
17-
self.info = info
16+
public init(album: Album) {
17+
self.album = album
1818
}
1919

20-
private var info: PreviewInfo
20+
private var album: Album
2121

2222
@Environment(\.dismiss)
2323
private var dismiss
2424

2525
@State
26-
private var headerVisibleRatio = 1.0
26+
private var visibleHeaderRatio = 1.0
2727

2828
@State
2929
private var scrollOffset = CGPoint.zero
3030

3131
public var body: some View {
3232
ScrollViewWithStickyHeader(
3333
header: scrollViewHeader,
34-
headerHeight: Spotify.PreviewScreenHeader.height,
34+
headerHeight: Examples.Spotify.AlbumScreen.Header.height,
3535
onScroll: handleScrollOffset
3636
) {
37-
Spotify.PreviewScreenContent(info: info)
37+
Examples.Spotify.AlbumScreen.Content(album: album)
3838
}
3939
.preferredColorScheme(.dark)
4040
#if os(iOS)
@@ -46,21 +46,21 @@ public extension Spotify {
4646
}
4747

4848
func scrollViewHeader() -> some View {
49-
Spotify.PreviewScreenHeader(
50-
info: info,
51-
headerVisibleRatio: headerVisibleRatio
49+
Examples.Spotify.AlbumScreen.Header(
50+
album: album,
51+
visibleHeaderRatio: visibleHeaderRatio
5252
)
5353
}
5454

5555
var toolbarTitleView: some View {
56-
Text(info.releaseTitle)
56+
Text(album.releaseTitle)
5757
.font(.headline.bold())
58-
.opacity(headerVisibleRatio > 0 ? 0 : -5 * headerVisibleRatio)
58+
.opacity(visibleHeaderRatio > 0 ? 0 : -5 * visibleHeaderRatio)
5959
}
6060

61-
func handleScrollOffset(_ offset: CGPoint, headerVisibleRatio: CGFloat) {
61+
func handleScrollOffset(_ offset: CGPoint, visibleHeaderRatio: CGFloat) {
6262
self.scrollOffset = offset
63-
self.headerVisibleRatio = headerVisibleRatio
63+
self.visibleHeaderRatio = visibleHeaderRatio
6464
}
6565
}
6666
}
@@ -90,14 +90,21 @@ private extension View {
9090
}
9191
}
9292

93-
#Preview("Navigation") {
93+
private var previewAlbum: Examples.Spotify.Album { .misfortune }
94+
95+
#Preview("Plain") {
96+
97+
Examples.Spotify.AlbumScreen(album: previewAlbum)
98+
}
99+
100+
#Preview("Push") {
94101

95102
NavigationView {
96103
#if os(macOS)
97104
Color.clear
98105
#endif
99106
NavigationLink("Test") {
100-
Spotify.PreviewScreen(info: .regina)
107+
Examples.Spotify.AlbumScreen(album: previewAlbum)
101108
}
102109
}
103110
#if os(iOS)
@@ -118,7 +125,7 @@ private extension View {
118125
}
119126
.sheet(isPresented: $isPresented) {
120127
NavigationView {
121-
Spotify.PreviewScreen(info: .regina)
128+
Examples.Spotify.AlbumScreen(album: previewAlbum)
122129
}
123130
.navigationViewStyle(.stack)
124131
}

Sources/ScrollKit/Examples/Spotify+PreviewScreenContent.swift renamed to Sources/ScrollKit/Examples/Examples+SpotifyAlbumScreenContent.swift

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,23 @@
11
//
2-
// Spotify+PreviewScreenContent.swift
2+
// Examples+SpotifyAlbumScreenContent.swift
33
// ScrollKit
44
//
55
// Created by Daniel Saidi on 2023-02-06.
6-
// Copyright © 2023-2024 Daniel Saidi. All rights reserved.
6+
// Copyright © 2023-2025 Daniel Saidi. All rights reserved.
77
//
88

99
import SwiftUI
1010

11-
public extension Spotify {
11+
public extension Examples.Spotify.AlbumScreen {
1212

1313
/// This view mimics a Spotify album screen content view.
14-
struct PreviewScreenContent: View {
14+
struct Content: View {
1515

16-
public init(info: PreviewInfo) {
17-
self.info = info
16+
public init(album: Examples.Spotify.Album) {
17+
self.album = album
1818
}
1919

20-
private let info: PreviewInfo
20+
private let album: Examples.Spotify.Album
2121

2222
public var body: some View {
2323
VStack(spacing: 20) {
@@ -30,16 +30,16 @@ public extension Spotify {
3030
}
3131
}
3232

33-
private extension Spotify.PreviewScreenContent {
33+
private extension Examples.Spotify.AlbumScreen.Content {
3434

3535
var title: some View {
3636
VStack(alignment: .leading, spacing: 8) {
37-
Text(info.releaseTitle)
37+
Text(album.releaseTitle)
3838
.font(.title2.bold())
3939
.frame(maxWidth: .infinity, alignment: .leading)
40-
Text(info.bandName)
40+
Text(album.bandName)
4141
.font(.footnote.bold())
42-
Text("\(info.releaseType) · \(info.releaseDate.formatted(.dateTime.year()))")
42+
Text("\(album.releaseType) · \(album.releaseDate.formatted(.dateTime.year()))")
4343
.font(.footnote.bold())
4444
.foregroundColor(.secondary)
4545
}
@@ -61,7 +61,7 @@ private extension Spotify.PreviewScreenContent {
6161

6262
var list: some View {
6363
LazyVStack(alignment: .leading, spacing: 30) {
64-
ForEach(Array(info.tracks.enumerated()), id: \.offset) {
64+
ForEach(Array(album.tracks.enumerated()), id: \.offset) {
6565
listItem($0.element)
6666
}
6767
}
@@ -70,7 +70,7 @@ private extension Spotify.PreviewScreenContent {
7070
func listItem(_ song: String) -> some View {
7171
VStack(alignment: .leading) {
7272
Text(song).font(.headline)
73-
Text(info.bandName)
73+
Text(album.bandName)
7474
.font(.footnote)
7575
.foregroundColor(.secondary)
7676
}
@@ -80,6 +80,6 @@ private extension Spotify.PreviewScreenContent {
8080
#Preview {
8181

8282
ScrollView {
83-
Spotify.PreviewScreenContent(info: .anthrax)
83+
Examples.Spotify.AlbumScreen.Content(album: .anthrax)
8484
}
8585
}

0 commit comments

Comments
 (0)