Skip to content

Commit d8194de

Browse files
author
Trent Guillory
committed
WORKS AGAIN
1 parent ef8d85f commit d8194de

File tree

16 files changed

+317
-203
lines changed

16 files changed

+317
-203
lines changed

ScrollViewReactiveHeaderDemoApp/ScrollViewReactiveHeaderDemoApp.xcodeproj/project.pbxproj

Lines changed: 51 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,12 @@
77
objects = {
88

99
/* Begin PBXBuildFile section */
10-
8459FC1A26E25E0C00EB434F /* FlightHeaderView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8459FC1926E25E0C00EB434F /* FlightHeaderView.swift */; };
11-
8459FC1C26E25E5D00EB434F /* FlightViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8459FC1B26E25E5D00EB434F /* FlightViewModel.swift */; };
12-
8459FC1E26E2665D00EB434F /* FlightDetailView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8459FC1D26E2665D00EB434F /* FlightDetailView.swift */; };
10+
8459FC3026E39A7600EB434F /* Story.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8459FC2F26E39A7600EB434F /* Story.swift */; };
11+
8459FC3226E39AB400EB434F /* StoryListViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8459FC3126E39AB400EB434F /* StoryListViewModel.swift */; };
12+
8459FC3526E39DA600EB434F /* StoryListHeaderOverlay.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8459FC3426E39DA600EB434F /* StoryListHeaderOverlay.swift */; };
13+
8459FC3826E3B1D700EB434F /* StoryListView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8459FC3726E3B1D700EB434F /* StoryListView.swift */; };
14+
8459FC3B26E3B36E00EB434F /* StoryListCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8459FC3A26E3B36E00EB434F /* StoryListCell.swift */; };
15+
8459FC3D26E3C94900EB434F /* StoryListContentView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8459FC3C26E3C94900EB434F /* StoryListContentView.swift */; };
1316
848BCF8826DE4ED800F8D967 /* ScrollViewReactiveHeaderDemoAppApp.swift in Sources */ = {isa = PBXBuildFile; fileRef = 848BCF8726DE4ED800F8D967 /* ScrollViewReactiveHeaderDemoAppApp.swift */; };
1417
848BCF8A26DE4ED800F8D967 /* ContentView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 848BCF8926DE4ED800F8D967 /* ContentView.swift */; };
1518
848BCF8C26DE4EDA00F8D967 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 848BCF8B26DE4EDA00F8D967 /* Assets.xcassets */; };
@@ -18,9 +21,12 @@
1821
/* End PBXBuildFile section */
1922

2023
/* Begin PBXFileReference section */
21-
8459FC1926E25E0C00EB434F /* FlightHeaderView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FlightHeaderView.swift; sourceTree = "<group>"; };
22-
8459FC1B26E25E5D00EB434F /* FlightViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FlightViewModel.swift; sourceTree = "<group>"; };
23-
8459FC1D26E2665D00EB434F /* FlightDetailView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FlightDetailView.swift; sourceTree = "<group>"; };
24+
8459FC2F26E39A7600EB434F /* Story.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Story.swift; sourceTree = "<group>"; };
25+
8459FC3126E39AB400EB434F /* StoryListViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StoryListViewModel.swift; sourceTree = "<group>"; };
26+
8459FC3426E39DA600EB434F /* StoryListHeaderOverlay.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StoryListHeaderOverlay.swift; sourceTree = "<group>"; };
27+
8459FC3726E3B1D700EB434F /* StoryListView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StoryListView.swift; sourceTree = "<group>"; };
28+
8459FC3A26E3B36E00EB434F /* StoryListCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StoryListCell.swift; sourceTree = "<group>"; };
29+
8459FC3C26E3C94900EB434F /* StoryListContentView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StoryListContentView.swift; sourceTree = "<group>"; };
2430
848BCF8426DE4ED800F8D967 /* ScrollViewReactiveHeaderDemoApp.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = ScrollViewReactiveHeaderDemoApp.app; sourceTree = BUILT_PRODUCTS_DIR; };
2531
848BCF8726DE4ED800F8D967 /* ScrollViewReactiveHeaderDemoAppApp.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ScrollViewReactiveHeaderDemoAppApp.swift; sourceTree = "<group>"; };
2632
848BCF8926DE4ED800F8D967 /* ContentView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContentView.swift; sourceTree = "<group>"; };
@@ -42,13 +48,41 @@
4248
/* End PBXFrameworksBuildPhase section */
4349

4450
/* Begin PBXGroup section */
45-
8459FC1826E25DEF00EB434F /* FlightView */ = {
51+
8459FC2E26E39A5300EB434F /* StoryList */ = {
4652
isa = PBXGroup;
4753
children = (
48-
8459FC1926E25E0C00EB434F /* FlightHeaderView.swift */,
49-
8459FC1D26E2665D00EB434F /* FlightDetailView.swift */,
54+
8459FC3926E3B2AA00EB434F /* Model */,
55+
8459FC3326E39D9400EB434F /* Views */,
5056
);
51-
path = FlightView;
57+
path = StoryList;
58+
sourceTree = "<group>";
59+
};
60+
8459FC3326E39D9400EB434F /* Views */ = {
61+
isa = PBXGroup;
62+
children = (
63+
8459FC3426E39DA600EB434F /* StoryListHeaderOverlay.swift */,
64+
8459FC3A26E3B36E00EB434F /* StoryListCell.swift */,
65+
8459FC3C26E3C94900EB434F /* StoryListContentView.swift */,
66+
);
67+
path = Views;
68+
sourceTree = "<group>";
69+
};
70+
8459FC3626E3B1B100EB434F /* Example3 */ = {
71+
isa = PBXGroup;
72+
children = (
73+
8459FC2E26E39A5300EB434F /* StoryList */,
74+
8459FC3726E3B1D700EB434F /* StoryListView.swift */,
75+
);
76+
path = Example3;
77+
sourceTree = "<group>";
78+
};
79+
8459FC3926E3B2AA00EB434F /* Model */ = {
80+
isa = PBXGroup;
81+
children = (
82+
8459FC2F26E39A7600EB434F /* Story.swift */,
83+
8459FC3126E39AB400EB434F /* StoryListViewModel.swift */,
84+
);
85+
path = Model;
5286
sourceTree = "<group>";
5387
};
5488
848BCF7B26DE4ED800F8D967 = {
@@ -75,8 +109,7 @@
75109
848BCF9626DE4EFC00F8D967 /* Resource Files */,
76110
848BCF8726DE4ED800F8D967 /* ScrollViewReactiveHeaderDemoAppApp.swift */,
77111
848BCF8926DE4ED800F8D967 /* ContentView.swift */,
78-
8459FC1B26E25E5D00EB434F /* FlightViewModel.swift */,
79-
8459FC1826E25DEF00EB434F /* FlightView */,
112+
8459FC3626E3B1B100EB434F /* Example3 */,
80113
);
81114
path = Sources;
82115
sourceTree = "<group>";
@@ -178,11 +211,14 @@
178211
isa = PBXSourcesBuildPhase;
179212
buildActionMask = 2147483647;
180213
files = (
181-
8459FC1A26E25E0C00EB434F /* FlightHeaderView.swift in Sources */,
214+
8459FC3D26E3C94900EB434F /* StoryListContentView.swift in Sources */,
215+
8459FC3226E39AB400EB434F /* StoryListViewModel.swift in Sources */,
216+
8459FC3526E39DA600EB434F /* StoryListHeaderOverlay.swift in Sources */,
217+
8459FC3826E3B1D700EB434F /* StoryListView.swift in Sources */,
182218
848BCF8A26DE4ED800F8D967 /* ContentView.swift in Sources */,
183-
8459FC1C26E25E5D00EB434F /* FlightViewModel.swift in Sources */,
184-
8459FC1E26E2665D00EB434F /* FlightDetailView.swift in Sources */,
185219
848BCF8826DE4ED800F8D967 /* ScrollViewReactiveHeaderDemoAppApp.swift in Sources */,
220+
8459FC3026E39A7600EB434F /* Story.swift in Sources */,
221+
8459FC3B26E3B36E00EB434F /* StoryListCell.swift in Sources */,
186222
);
187223
runOnlyForDeploymentPostprocessing = 0;
188224
};

ScrollViewReactiveHeaderDemoApp/Sources/ContentView.swift

Lines changed: 14 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -6,52 +6,21 @@ import SwiftUI
66
struct ContentView: View {
77

88
var body: some View {
9-
10-
ZStack(alignment: .topLeading) {
11-
12-
ScrollViewReactiveHeader(header: {
13-
14-
HeaderView()
15-
}, headerOverlay: {
16-
17-
HeaderOverlay()
18-
}, body: {
19-
20-
ScrollViewContent()
21-
})
22-
23-
HStack {
24-
25-
Spacer()
26-
27-
Image(systemName: "magnifyingglass")
28-
.imageScale(.medium)
29-
30-
Text("Where are you going?")
31-
.font(.callout)
32-
.fontWeight(.medium)
33-
34-
Spacer()
35-
}
36-
.opacity(0.8)
37-
.padding(6)
38-
.background(Color.white)
39-
.cornerRadius(20)
40-
.padding()
9+
10+
// TabView {
11+
//
12+
// StoryListView()
13+
// .tabItem {
14+
// VStack {
15+
// Image(systemName: "book")
16+
// Text("Reader")
17+
// }
18+
// }
19+
// }
20+
VStack {
21+
StoryListView()
4122
}
42-
}
43-
}
44-
45-
// MARK: - HeaderView
46-
47-
struct HeaderView: View {
48-
49-
var body: some View {
50-
51-
Image("night-sky")
52-
.resizable()
53-
.aspectRatio(contentMode: .fill)
54-
.frame(height: 450)
23+
5524
}
5625
}
5726

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import Foundation
2+
3+
struct Story: Identifiable {
4+
5+
let id: Int
6+
7+
let title: String
8+
let description: String
9+
10+
let reads: Int
11+
let favorites: Int
12+
13+
static let peculiar: Story = .init(id: 0, title: "The Peculiar Guillotine", description: "Alex Parkes had always loved urban Sleepford with its dark, delicious ditches. It was a place where he felt barmy.", reads: 13, favorites: 4)
14+
static let teapot: Story = .init(id: 1, title: "The Damp Teapot", description: "James Rockatansky looked at the damp teapot in his hands and felt unstable.", reads: 8, favorites: 2)
15+
static let elixir: Story = .init(id: 2, title: "The Elixir", description: "Tristan gulped. He glanced at his own reflection. He was a giving, greedy, squash drinker with spiky fingers and skinny fingers", reads: 16, favorites: 5)
16+
static let piano: Story = .init(id: 3, title: "The Warped Piano", description: "Alex Raymond was thinking about Michelle Blast again. Michelle was a brave volcano with short arms and fiery gaze.", reads: 21, favorites: 4)
17+
static let windingPath: Story = .init(id: 4, title: "The Winding Path", description: "Alex Smart walked over to the window and reflected on his rural surroundings. He had always loved his hometown.", reads: 8, favorites: 1)
18+
static let darkWeather: Story = .init(id: 5, title: "Darker Nights", description: "The hail pounded like bopping donkeys, making Suki puzzled. Suki grabbed a bendy gun that had been strewn nearby.", reads: 24, favorites: 11)
19+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import Foundation
2+
3+
struct StoryListViewModel {
4+
5+
let stories: [Story]
6+
7+
let header: String = "Our Newest Stories"
8+
9+
static let example: StoryListViewModel = .init(stories: [.darkWeather, .elixir, .peculiar, .piano, .teapot, .windingPath])
10+
}
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
import SwiftUI
2+
3+
// MARK: - StoryListCell
4+
5+
struct StoryListCell: View {
6+
7+
let viewModel: Story
8+
let iconWidth: CGFloat = 30
9+
let labelWidth: CGFloat = 20
10+
11+
var body: some View {
12+
13+
HStack {
14+
15+
VStack {
16+
17+
Text(viewModel.title)
18+
.font(.system(size: 16, weight: .semibold, design: .serif))
19+
.frame(maxWidth: .infinity, alignment: .leading)
20+
21+
Text(viewModel.description)
22+
.font(.system(size: 13, weight: .regular, design: .serif))
23+
.frame(maxWidth: .infinity, alignment: .leading)
24+
}
25+
26+
VStack(alignment: .trailing) {
27+
28+
HStack {
29+
30+
Image(systemName: "book")
31+
.frame(width: iconWidth)
32+
Text(String(viewModel.reads))
33+
.font(.system(size: 15))
34+
.frame(width: labelWidth)
35+
}
36+
37+
Divider()
38+
39+
HStack {
40+
41+
Image(systemName: "bookmark")
42+
.frame(width: iconWidth)
43+
Text(String(viewModel.favorites))
44+
.font(.system(size: 15))
45+
.frame(width: labelWidth)
46+
}
47+
}
48+
.frame(width: 60)
49+
.opacity(0.5)
50+
}.padding()
51+
.overlay(
52+
RoundedRectangle(cornerRadius: 6, style: .continuous)
53+
.stroke(Color.black.opacity(0.1), lineWidth: 2))
54+
}
55+
}
56+
57+
// MARK: - StoryListCell_Previews
58+
59+
struct StoryListCell_Previews: PreviewProvider {
60+
static var previews: some View {
61+
62+
StoryListCell(viewModel: .peculiar)
63+
.padding()
64+
}
65+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import SwiftUI
2+
3+
// MARK: - StoryListContentView
4+
5+
struct StoryListContentView: View {
6+
7+
let viewModel: StoryListViewModel
8+
9+
var body: some View {
10+
11+
VStack {
12+
13+
VStack {}
14+
.frame(height: 300)
15+
16+
ForEach(viewModel.stories) { story in
17+
18+
StoryListCell(viewModel: story)
19+
}
20+
}.padding()
21+
}
22+
}
23+
24+
// MARK: - StoryListContentView_Previews
25+
26+
struct StoryListContentView_Previews: PreviewProvider {
27+
static var previews: some View {
28+
29+
StoryListContentView(viewModel: StoryListViewModel.example)
30+
}
31+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import SwiftUI
2+
3+
// MARK: - StoryListHeaderOverlay
4+
5+
struct StoryListHeaderOverlay: View {
6+
7+
let header: String
8+
9+
var body: some View {
10+
11+
VStack(alignment: .center) {
12+
13+
ZStack {
14+
15+
Rectangle()
16+
.fill(Color.yellow)
17+
.offset(x: -24, y: 0)
18+
.rotationEffect(.init(degrees: -1))
19+
.frame(width: 112, height: 30)
20+
.opacity(0.7)
21+
22+
Text(header)
23+
.font(.system(size: 32, weight: .semibold, design: .serif))
24+
.frame(maxWidth: .infinity)
25+
}
26+
}
27+
}
28+
}
29+
30+
// MARK: - StoryListHeaderOverlay_Previews
31+
32+
struct StoryListHeaderOverlay_Previews: PreviewProvider {
33+
static var previews: some View {
34+
StoryListHeaderOverlay(header: "Our Newest Stories")
35+
}
36+
}

0 commit comments

Comments
 (0)