Skip to content

Commit 1cc8468

Browse files
author
Trent Guillory
committed
Wrapped up examples.
1 parent e7152e2 commit 1cc8468

File tree

23 files changed

+443
-52
lines changed

23 files changed

+443
-52
lines changed

SnapToScrollDemo/SnapToScrollDemo.xcodeproj/project.pbxproj

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

99
/* Begin PBXBuildFile section */
10-
84C99CD826D99BA100C1D5C4 /* CellModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84C99CD726D99BA100C1D5C4 /* CellModel.swift */; };
10+
841B0F8326DD39A4008A436B /* TripTupleView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 841B0F8226DD39A4008A436B /* TripTupleView.swift */; };
11+
84B568D926DD271000D37CF2 /* TagView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84B568D826DD271000D37CF2 /* TagView.swift */; };
12+
84B568DB26DD309400D37CF2 /* Example1HeaderView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84B568DA26DD309400D37CF2 /* Example1HeaderView.swift */; };
13+
84B568DE26DD351900D37CF2 /* TripModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84B568DD26DD351900D37CF2 /* TripModel.swift */; };
14+
84B568E026DD37A600D37CF2 /* TripView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84B568DF26DD37A600D37CF2 /* TripView.swift */; };
15+
84C99CD826D99BA100C1D5C4 /* TagModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84C99CD726D99BA100C1D5C4 /* TagModel.swift */; };
1116
84D9FA3626D9753600F87EF5 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84D9FA3526D9753600F87EF5 /* AppDelegate.swift */; };
1217
84D9FA3826D9753600F87EF5 /* SceneDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84D9FA3726D9753600F87EF5 /* SceneDelegate.swift */; };
1318
84D9FA3A26D9753600F87EF5 /* ContentView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84D9FA3926D9753600F87EF5 /* ContentView.swift */; };
@@ -18,7 +23,12 @@
1823
/* End PBXBuildFile section */
1924

2025
/* Begin PBXFileReference section */
21-
84C99CD726D99BA100C1D5C4 /* CellModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CellModel.swift; sourceTree = "<group>"; };
26+
841B0F8226DD39A4008A436B /* TripTupleView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TripTupleView.swift; sourceTree = "<group>"; };
27+
84B568D826DD271000D37CF2 /* TagView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TagView.swift; sourceTree = "<group>"; };
28+
84B568DA26DD309400D37CF2 /* Example1HeaderView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Example1HeaderView.swift; sourceTree = "<group>"; };
29+
84B568DD26DD351900D37CF2 /* TripModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TripModel.swift; sourceTree = "<group>"; };
30+
84B568DF26DD37A600D37CF2 /* TripView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TripView.swift; sourceTree = "<group>"; };
31+
84C99CD726D99BA100C1D5C4 /* TagModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TagModel.swift; sourceTree = "<group>"; };
2232
84D9FA3226D9753600F87EF5 /* SnapToScrollDemo.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = SnapToScrollDemo.app; sourceTree = BUILT_PRODUCTS_DIR; };
2333
84D9FA3526D9753600F87EF5 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = "<group>"; };
2434
84D9FA3726D9753600F87EF5 /* SceneDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SceneDelegate.swift; sourceTree = "<group>"; };
@@ -42,6 +52,26 @@
4252
/* End PBXFrameworksBuildPhase section */
4353

4454
/* Begin PBXGroup section */
55+
84B568D626DD26A800D37CF2 /* Example1 */ = {
56+
isa = PBXGroup;
57+
children = (
58+
84C99CD726D99BA100C1D5C4 /* TagModel.swift */,
59+
84B568D826DD271000D37CF2 /* TagView.swift */,
60+
84B568DA26DD309400D37CF2 /* Example1HeaderView.swift */,
61+
);
62+
path = Example1;
63+
sourceTree = "<group>";
64+
};
65+
84B568DC26DD311F00D37CF2 /* Example 2 */ = {
66+
isa = PBXGroup;
67+
children = (
68+
84B568DD26DD351900D37CF2 /* TripModel.swift */,
69+
84B568DF26DD37A600D37CF2 /* TripView.swift */,
70+
841B0F8226DD39A4008A436B /* TripTupleView.swift */,
71+
);
72+
path = "Example 2";
73+
sourceTree = "<group>";
74+
};
4575
84D9FA2926D9753600F87EF5 = {
4676
isa = PBXGroup;
4777
children = (
@@ -65,9 +95,10 @@
6595
children = (
6696
84D9FA4926D9757400F87EF5 /* Resource Files */,
6797
84D9FA3526D9753600F87EF5 /* AppDelegate.swift */,
98+
84B568D626DD26A800D37CF2 /* Example1 */,
99+
84B568DC26DD311F00D37CF2 /* Example 2 */,
68100
84D9FA3726D9753600F87EF5 /* SceneDelegate.swift */,
69101
84D9FA3926D9753600F87EF5 /* ContentView.swift */,
70-
84C99CD726D99BA100C1D5C4 /* CellModel.swift */,
71102
);
72103
path = Sources;
73104
sourceTree = "<group>";
@@ -171,10 +202,15 @@
171202
isa = PBXSourcesBuildPhase;
172203
buildActionMask = 2147483647;
173204
files = (
205+
84B568DB26DD309400D37CF2 /* Example1HeaderView.swift in Sources */,
174206
84D9FA3626D9753600F87EF5 /* AppDelegate.swift in Sources */,
207+
841B0F8326DD39A4008A436B /* TripTupleView.swift in Sources */,
208+
84B568D926DD271000D37CF2 /* TagView.swift in Sources */,
209+
84B568E026DD37A600D37CF2 /* TripView.swift in Sources */,
210+
84B568DE26DD351900D37CF2 /* TripModel.swift in Sources */,
175211
84D9FA3826D9753600F87EF5 /* SceneDelegate.swift in Sources */,
176212
84D9FA3A26D9753600F87EF5 /* ContentView.swift in Sources */,
177-
84C99CD826D99BA100C1D5C4 /* CellModel.swift in Sources */,
213+
84C99CD826D99BA100C1D5C4 /* TagModel.swift in Sources */,
178214
);
179215
runOnlyForDeploymentPostprocessing = 0;
180216
};
@@ -315,15 +351,15 @@
315351
ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor;
316352
CODE_SIGN_STYLE = Automatic;
317353
DEVELOPMENT_ASSET_PATHS = "\"Sources/Resource Files/Preview Content\"";
318-
DEVELOPMENT_TEAM = AA73357GBH;
354+
DEVELOPMENT_TEAM = 3XTTWH436M;
319355
ENABLE_PREVIEWS = YES;
320356
INFOPLIST_FILE = "Sources/Resource Files/Info.plist";
321357
IPHONEOS_DEPLOYMENT_TARGET = 13.0;
322358
LD_RUNPATH_SEARCH_PATHS = (
323359
"$(inherited)",
324360
"@executable_path/Frameworks",
325361
);
326-
PRODUCT_BUNDLE_IDENTIFIER = com.trentguillory.SnapToScrollDemo;
362+
PRODUCT_BUNDLE_IDENTIFIER = com.trentguillory.SnapToScrollDemoApp;
327363
PRODUCT_NAME = "$(TARGET_NAME)";
328364
SWIFT_VERSION = 5.0;
329365
TARGETED_DEVICE_FAMILY = "1,2";
@@ -337,15 +373,15 @@
337373
ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor;
338374
CODE_SIGN_STYLE = Automatic;
339375
DEVELOPMENT_ASSET_PATHS = "\"Sources/Resource Files/Preview Content\"";
340-
DEVELOPMENT_TEAM = AA73357GBH;
376+
DEVELOPMENT_TEAM = 3XTTWH436M;
341377
ENABLE_PREVIEWS = YES;
342378
INFOPLIST_FILE = "Sources/Resource Files/Info.plist";
343379
IPHONEOS_DEPLOYMENT_TARGET = 13.0;
344380
LD_RUNPATH_SEARCH_PATHS = (
345381
"$(inherited)",
346382
"@executable_path/Frameworks",
347383
);
348-
PRODUCT_BUNDLE_IDENTIFIER = com.trentguillory.SnapToScrollDemo;
384+
PRODUCT_BUNDLE_IDENTIFIER = com.trentguillory.SnapToScrollDemoApp;
349385
PRODUCT_NAME = "$(TARGET_NAME)";
350386
SWIFT_VERSION = 5.0;
351387
TARGETED_DEVICE_FAMILY = "1,2";

SnapToScrollDemo/Sources/CellModel.swift

Lines changed: 0 additions & 9 deletions
This file was deleted.

SnapToScrollDemo/Sources/ContentView.swift

Lines changed: 62 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -4,44 +4,76 @@ import SwiftUI
44
// MARK: - ContentView
55

66
struct ContentView: View {
7-
7+
88
@State var items = [("one", 1), ("two", 2), ("three", 3), ("four", 4), ("five", 5), ("six", 6)]
9-
10-
9+
1110
var body: some View {
1211
VStack {
13-
14-
HStackSnap(leadingOffset: 16) {
12+
13+
ScrollView {
14+
15+
VerticalSpace
1516

16-
ForEach(items, id: \.1) { item in
17-
18-
Text(item.0)
19-
.font(.largeTitle)
20-
.padding(16)
21-
.overlay(GeometryReaderOverlay(id: item.1))
22-
.onTapGesture {
23-
24-
print(item.0)
17+
VStack {
18+
19+
LargeHeader(text: "Example 1")
20+
21+
Example1HeaderView()
22+
23+
// Don't forget to attach GeometryReaderOverlay!
24+
HStackSnap(leadingOffset: 16) {
25+
26+
ForEach(TagModel.exampleModels) { viewModel in
27+
28+
TagView(viewModel: viewModel)
29+
.overlay(GeometryReaderOverlay(id: viewModel.id))
30+
}
31+
}.padding(.top, 4)
32+
}
33+
34+
VerticalSpace
35+
36+
VStack {
37+
38+
LargeHeader(text: "Example 2")
39+
40+
Text("Explore Nearby")
41+
.font(.system(size: 22, weight: .semibold, design: .rounded))
42+
.frame(maxWidth: .infinity, alignment: .leading)
43+
.padding([.top, .leading], 16)
44+
45+
HStackSnap(leadingOffset: 16) {
46+
47+
ForEach(TripTupleModel.exampleModels) { viewModel in
48+
49+
TripTupleView(viewModel: viewModel)
50+
.frame(maxWidth: 250)
51+
.overlay(GeometryReaderOverlay(id: viewModel.id))
2552
}
53+
}
54+
.frame(height: 200)
55+
.padding(.top, 4)
2656
}
2757
}
28-
// HStackSnap(snapLocation: .center) {
29-
//
30-
// ForEach(items, id: \.1) { item in
31-
//
32-
// Text(item.0)
33-
// .font(.largeTitle)
34-
// .padding()
35-
// .overlay(GeometryReaderOverlay(id: item.1))
36-
// }
37-
// }
3858
}
39-
40-
/// SnapHStack {
41-
/// customForEach { item in
42-
///
43-
/// }
44-
/// }
59+
.preferredColorScheme(.light)
60+
}
61+
62+
var VerticalSpace: some View {
63+
64+
VStack {}
65+
.frame(height: 64)
66+
}
67+
68+
func LargeHeader(text: String) -> some View {
69+
70+
return
71+
Text(text)
72+
.font(.largeTitle)
73+
.fontWeight(.bold)
74+
.opacity(0.5)
75+
.frame(maxWidth: .infinity, alignment: .leading)
76+
.padding(.leading, 16)
4577
}
4678
}
4779

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
import Foundation
2+
3+
// MARK: - TripModel
4+
5+
struct TripModel {
6+
7+
static let newYork: TripModel = .init(
8+
imageName: "NewYork",
9+
destination: "New York",
10+
startingPrice: 1230)
11+
static let newOrleans: TripModel = .init(
12+
imageName: "NewOrleans",
13+
destination: "New Orleans",
14+
startingPrice: 1850)
15+
static let venice: TripModel = .init(
16+
imageName: "Venice",
17+
destination: "Venice",
18+
startingPrice: 2340)
19+
static let london: TripModel = .init(
20+
imageName: "London",
21+
destination: "London",
22+
startingPrice: 2200)
23+
static let mtFuji: TripModel = .init(
24+
imageName: "MtFuji",
25+
destination: "Mt. Fuji",
26+
startingPrice: 2900)
27+
static let egypt: TripModel = .init(
28+
imageName: "Egypt",
29+
destination: "Egypt",
30+
startingPrice: 2450)
31+
32+
let imageName: String
33+
let destination: String
34+
let startingPrice: Double
35+
}
36+
37+
// MARK: - TripModelTuple
38+
39+
struct TripTupleModel: Identifiable {
40+
41+
static let exampleModels: [TripTupleModel] = [
42+
.init(id: 0, trip1: TripModel.newYork, trip2: TripModel.newOrleans),
43+
.init(id: 1, trip1: TripModel.venice, trip2: TripModel.london),
44+
.init(id: 2, trip1: TripModel.mtFuji, trip2: TripModel.egypt),
45+
]
46+
47+
let id: Int
48+
let trip1: TripModel
49+
let trip2: TripModel
50+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import SwiftUI
2+
3+
// MARK: - TripTupleView
4+
5+
struct TripTupleView: View {
6+
7+
let viewModel: TripTupleModel
8+
9+
var body: some View {
10+
11+
VStack(alignment: .leading) {
12+
13+
TripView(viewModel: viewModel.trip1)
14+
15+
16+
TripView(viewModel: viewModel.trip2)
17+
}
18+
}
19+
}
20+
21+
// MARK: - TripTupleView_Previews
22+
23+
struct TripTupleView_Previews: PreviewProvider {
24+
static var previews: some View {
25+
26+
TripTupleView(viewModel: TripTupleModel.exampleModels.first!)
27+
}
28+
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
import SwiftUI
2+
3+
// MARK: - TripView
4+
5+
struct TripView: View {
6+
7+
let viewModel: TripModel
8+
9+
var body: some View {
10+
11+
VStack(alignment: .leading) {
12+
13+
HStack(spacing: 12) {
14+
15+
Image(viewModel.imageName)
16+
.resizable()
17+
.aspectRatio(contentMode: .fill)
18+
.frame(width: 75, height: 75)
19+
.cornerRadius(18)
20+
.clipped()
21+
22+
VStack(alignment: .leading, spacing: 6) {
23+
24+
Text(viewModel.destination)
25+
.font(.headline)
26+
Text("$\(Int(viewModel.startingPrice)) starting")
27+
.font(.subheadline)
28+
}
29+
30+
Spacer()
31+
}
32+
}
33+
}
34+
}
35+
36+
// MARK: - TripView_Previews
37+
38+
struct TripView_Previews: PreviewProvider {
39+
40+
static var previews: some View {
41+
42+
TripView(viewModel: TripModel.newYork)
43+
}
44+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import SwiftUI
2+
3+
// MARK: - Example1HeaderView
4+
5+
struct Example1HeaderView: View {
6+
var body: some View {
7+
8+
HStack {
9+
10+
Text("Downtown")
11+
.foregroundColor(.gray)
12+
13+
Spacer()
14+
15+
Image(systemName: "magnifyingglass")
16+
.foregroundColor(.gray)
17+
}
18+
.padding(8)
19+
.background(Color.white)
20+
.cornerRadius(8)
21+
.shadow(color: Color.gray.opacity(0.4), radius: 4, x: 0, y: 3)
22+
.padding([.leading, .trailing], 16)
23+
}
24+
}
25+
26+
// MARK: - Example1HeaderView_Previews
27+
28+
struct Example1HeaderView_Previews: PreviewProvider {
29+
static var previews: some View {
30+
Example1HeaderView()
31+
}
32+
}

0 commit comments

Comments
 (0)