Skip to content

Commit

Permalink
Adjust documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
danielsaidi committed May 30, 2024
1 parent e07bcd3 commit e8ab4a0
Show file tree
Hide file tree
Showing 12 changed files with 242 additions and 253 deletions.
142 changes: 74 additions & 68 deletions Sources/ScrollKit/Examples/Spotify+PreviewInfo.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import SwiftUI

public extension Spotify {

/// This type mimics a Spotify preview screen view model.
/// This model is used by the Spotify previews.
struct PreviewInfo {

public init(
Expand Down Expand Up @@ -42,73 +42,79 @@ public extension Spotify {

public extension Spotify.PreviewInfo {

static var anthrax = Self(
bandName: "Anthrax",
releaseTitle: "We've Come for You All",
releaseType: "Album",
releaseDate: Calendar.current.date(from: DateComponents(year: 2003)) ?? .now,
releaseCoverUrl: "https://upload.wikimedia.org/wikipedia/en/8/8f/AnthraxWCFYA.jpg",
tintColor: .init(red: 0.5, green: 0.4, blue: 0.5),
tracks: [
"Contact",
"What Doesn't Die",
"Superhero",
"Refuse to Be Denied",
"Safe Home",
"Any Place But Here",
"Nobody Knows Anything",
"Strap It On",
"Black Dahlia",
"Cadillac Rock Box",
"Taking the Music Back",
"Crash",
"Think About an End",
"We've Come for You All",
"Safe Home - Acoustic Version",
"We're Happy Family"
]
)
static var anthrax: Self {
.init(
bandName: "Anthrax",
releaseTitle: "We've Come for You All",
releaseType: "Album",
releaseDate: Calendar.current.date(from: DateComponents(year: 2003)) ?? .now,
releaseCoverUrl: "https://upload.wikimedia.org/wikipedia/en/8/8f/AnthraxWCFYA.jpg",
tintColor: .init(red: 0.5, green: 0.4, blue: 0.5),
tracks: [
"Contact",
"What Doesn't Die",
"Superhero",
"Refuse to Be Denied",
"Safe Home",
"Any Place But Here",
"Nobody Knows Anything",
"Strap It On",
"Black Dahlia",
"Cadillac Rock Box",
"Taking the Music Back",
"Crash",
"Think About an End",
"We've Come for You All",
"Safe Home - Acoustic Version",
"We're Happy Family"
]
)
}

static var misfortune = Self(
bandName: "Misfortune",
releaseTitle: "Forsaken",
releaseType: "Album",
releaseDate: Calendar.current.date(from: DateComponents(year: 1999)) ?? .now,
releaseCoverUrl: "https://i.discogs.com/75jm2NwzdkgIlEo9ucyl4_o1OCOzB4EQPZua8VQ5W94/rs:fit/g:sm/q:90/h:600/w:600/czM6Ly9kaXNjb2dz/LWRhdGFiYXNlLWlt/YWdlcy9SLTQzOTg5/NDUtMTM4NzIwNTE4/Ni02NTI1LmpwZWc.jpeg",
tintColor: .init(red: 0.5, green: 0.3, blue: 0),
tracks: [
"Forsaken",
"A Scenery of Dispair",
"Rape of Bewildered Dreams",
"In Mating",
"Burn!",
"Through Chaos Fulfilled",
"A Realm of the Unblessed",
"Apostates of Hate"
]
)
static var misfortune: Self {
.init(
bandName: "Misfortune",
releaseTitle: "Forsaken",
releaseType: "Album",
releaseDate: Calendar.current.date(from: DateComponents(year: 1999)) ?? .now,
releaseCoverUrl: "https://i.discogs.com/75jm2NwzdkgIlEo9ucyl4_o1OCOzB4EQPZua8VQ5W94/rs:fit/g:sm/q:90/h:600/w:600/czM6Ly9kaXNjb2dz/LWRhdGFiYXNlLWlt/YWdlcy9SLTQzOTg5/NDUtMTM4NzIwNTE4/Ni02NTI1LmpwZWc.jpeg",
tintColor: .init(red: 0.5, green: 0.3, blue: 0),
tracks: [
"Forsaken",
"A Scenery of Dispair",
"Rape of Bewildered Dreams",
"In Mating",
"Burn!",
"Through Chaos Fulfilled",
"A Realm of the Unblessed",
"Apostates of Hate"
]
)
}

static var regina = Self(
bandName: "Regina Spector",
releaseTitle: "Far",
releaseType: "Album",
releaseDate: Calendar.current.date(from: DateComponents(year: 2009)) ?? .now,
releaseCoverUrl: "https://i.scdn.co/image/ab67616d0000b2738c8d5428b693308705e7caca",
tintColor: .init(red: 0.5, green: 0.7, blue: 1),
tracks: [
"The Calculation",
"Eet",
"Blue Lips",
"Folding Chair",
"Machine",
"Laughing With",
"Human of the Year",
"Two Birds",
"Dance Anthem of the 80's",
"Genius Next Door",
"Wallet",
"One More Time With Feeling",
"Man of a Thousand Faces"
]
)
static var regina: Self {
.init(
bandName: "Regina Spector",
releaseTitle: "Far",
releaseType: "Album",
releaseDate: Calendar.current.date(from: DateComponents(year: 2009)) ?? .now,
releaseCoverUrl: "https://i.scdn.co/image/ab67616d0000b2738c8d5428b693308705e7caca",
tintColor: .init(red: 0.5, green: 0.7, blue: 1),
tracks: [
"The Calculation",
"Eet",
"Blue Lips",
"Folding Chair",
"Machine",
"Laughing With",
"Human of the Year",
"Two Birds",
"Dance Anthem of the 80's",
"Genius Next Door",
"Wallet",
"One More Time With Feeling",
"Man of a Thousand Faces"
]
)
}
}
2 changes: 1 addition & 1 deletion Sources/ScrollKit/Examples/Spotify+PreviewScreen.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import SwiftUI

public extension Spotify {

/// This view mimics the Spotify album screen.
/// This view mimics a Spotify album screen.
struct PreviewScreen: View {

public init(info: PreviewInfo) {
Expand Down
8 changes: 3 additions & 5 deletions Sources/ScrollKit/Examples/Spotify+PreviewScreenContent.swift
Original file line number Diff line number Diff line change
Expand Up @@ -77,11 +77,9 @@ private extension Spotify.PreviewScreenContent {
}
}

struct SpotifyPreviewScreenContent_Previews: PreviewProvider {
#Preview {

static var previews: some View {
ScrollView {
Spotify.PreviewScreenContent(info: .anthrax)
}
ScrollView {
Spotify.PreviewScreenContent(info: .anthrax)
}
}
12 changes: 5 additions & 7 deletions Sources/ScrollKit/Examples/Spotify+PreviewScreenHeader.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import SwiftUI

public extension Spotify {

/// This view mimics the Spotify album screen header.
/// This view mimics a Spotify album screen header.
struct PreviewScreenHeader: View {

public init(
Expand All @@ -21,7 +21,7 @@ public extension Spotify {
self.headerVisibleRatio = headerVisibleRatio
}

public static var height: CGFloat = 280
public static let height: CGFloat = 280

private var info: PreviewInfo
private var headerVisibleRatio: CGFloat
Expand Down Expand Up @@ -79,10 +79,8 @@ private extension CGFloat {
}
}

struct SpotifyPreviewScreenHeader_Previews: PreviewProvider {
#Preview {

static var previews: some View {
Spotify.PreviewScreenHeader(info: .anthrax)
.frame(height: Spotify.PreviewScreenHeader.height)
}
Spotify.PreviewScreenHeader(info: .anthrax)
.frame(height: Spotify.PreviewScreenHeader.height)
}
55 changes: 27 additions & 28 deletions Sources/ScrollKit/Helpers/ScrollViewOffsetTracker.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,31 +8,30 @@

import SwiftUI

/**
This view can be wrap any `ScrollView` or `List` content to
get offset tracking working when the view is scrolled.
To use this view, add it to the `ScrollView` or `List`, add
the content to it then apply the `withScrollOffsetTracking`
view modifier to the view, for instance like this:
```swift
List {
ScrollViewOffsetTracker {
ForEach(0...100, id: \.self) {
Text("\($0)")
.frame(width: 200, height: 200)
}
}
}
.withScrollOffsetTracking { offset in
print(offset)
}
```
The offset tracking action will trigger whenever the scroll
view scrolls, and provide you with the scroll offset.
*/
/// This view can wrap any `ScrollView` or `List` content to
/// get offset tracking working when the view is scrolled.
///
/// To use this view, add it to a `ScrollView` or `List` and
/// add a content view to it, then simply apply the modifier
/// ``SwiftUI/View/withScrollOffsetTracking(action:)``, just
/// like this:
///
/// ```swift
/// List {
/// ScrollViewOffsetTracker {
/// ForEach(0...100, id: \.self) {
/// Text("\($0)")
/// .frame(width: 200, height: 200)
/// }
/// }
/// }
/// .withScrollOffsetTracking {
/// offset in print(offset)
/// }
/// ```
///
/// The offset action will trigger when the list scrolls and
/// provide you with the scroll offset.
public struct ScrollViewOffsetTracker<Content: View>: View {

public init(
Expand Down Expand Up @@ -62,8 +61,8 @@ public struct ScrollViewOffsetTracker<Content: View>: View {
public extension View {

/// Add this modifier to a `ScrollView`, a `List` or any
/// other view that has a ``ScrollViewOffsetTracker`` in
/// itself, to track its scroll offset.
/// view that has a ``ScrollViewOffsetTracker`` to track
/// its scroll offset.
func withScrollOffsetTracking(
action: @escaping (_ offset: CGPoint) -> Void
) -> some View {
Expand All @@ -80,7 +79,7 @@ enum ScrollOffsetNamespace {

struct ScrollOffsetPreferenceKey: PreferenceKey {

static var defaultValue: CGPoint = .zero
static var defaultValue: CGPoint { .zero }

static func reduce(value: inout CGPoint, nextValue: () -> CGPoint) {}
}
Expand Down
88 changes: 44 additions & 44 deletions Sources/ScrollKit/ScrollViewHeader.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,50 +8,50 @@

import SwiftUI

/**
This view can be used as a scroll view header and stretches
its content when pulled down.
For instance, this creates a header with a background color
gradient, a dark gradient overlay and a bottom-leading text:
```swift
struct MyHeader: View {
var body: some View {
ScrollViewHeader {
ZStack(alignment: .bottomLeading) {
LinearGradient(
colors: [.blue, .yellow],
startPoint: .topLeading,
endPoint: .bottomTrailing)
LinearGradient(
colors: [.clear, .black.opacity(0.6)],
startPoint: .top,
endPoint: .bottom)
Text("Header title")
.padding()
}
}.frame(height: 250)
}
}
```
To add this title to a scroll view, with more content below
the header, just add the header topmost in a `VStack`:
```swift
ScrollView(.vertical) {
VStack(spacing: 0) {
MyHeader()
// More content here
}
}
```
The `MyHeader` view will now automatically stretch out when
the scroll view is pulled down.
*/
/// This view can be used as a scroll view header, that will
/// automatically stretch its content when pulled down.
///
/// For instance, this creates a header view with a gradient
/// background, a gradient overlay and a bottom-leading text:
///
/// ```swift
/// struct MyHeader: View {
///
/// var body: some View {
/// ScrollViewHeader {
/// ZStack(alignment: .bottomLeading) {
/// LinearGradient(
/// colors: [.blue, .yellow],
/// startPoint: .topLeading,
/// endPoint: .bottomTrailing
/// )
/// LinearGradient(
/// colors: [.clear, .black.opacity(0.6)],
/// startPoint: .top,
/// endPoint: .bottom
/// )
/// Text("Header title")
/// .padding()
/// }
/// .frame(height: 250)
/// }
/// }
/// ```
///
/// To add the view to a scroll view with more content below
/// the header, just add the header topmost in a `VStack`:
///
/// ```swift
/// ScrollView(.vertical) {
/// VStack(spacing: 0) {
/// MyHeader()
/// // More content here
/// }
/// }
/// ```
///
/// Your header view will now automatically stretch out when
/// the scroll view is pulled down.
public struct ScrollViewHeader<Content: View>: View {

/// Create a stretchable scroll view header.
Expand Down
Loading

0 comments on commit e8ab4a0

Please sign in to comment.