Skip to content

Commit 14320ba

Browse files
committed
Implement until the section Composing Complex Interfaces.
1 parent 4ec2fd6 commit 14320ba

File tree

7 files changed

+158
-14
lines changed

7 files changed

+158
-14
lines changed

Landmarks.xcodeproj/project.pbxproj

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

99
/* Begin PBXBuildFile section */
10+
F23D7BE72348E09B004C05C4 /* Home.swift in Sources */ = {isa = PBXBuildFile; fileRef = F23D7BE62348E09B004C05C4 /* Home.swift */; };
11+
F23D7BE92348E591004C05C4 /* CategoryRow.swift in Sources */ = {isa = PBXBuildFile; fileRef = F23D7BE82348E591004C05C4 /* CategoryRow.swift */; };
1012
F29B7DDE233F564D0025D62A /* RotatedBadgeSymbol.swift in Sources */ = {isa = PBXBuildFile; fileRef = F29B7DDD233F564D0025D62A /* RotatedBadgeSymbol.swift */; };
1113
F29B7E0B233F80EB0025D62A /* HikeView.swift in Sources */ = {isa = PBXBuildFile; fileRef = F29B7E0A233F80EB0025D62A /* HikeView.swift */; };
1214
F29B7E0D233F821F0025D62A /* Hike.swift in Sources */ = {isa = PBXBuildFile; fileRef = F29B7E0C233F821F0025D62A /* Hike.swift */; };
@@ -64,6 +66,8 @@
6466
/* End PBXContainerItemProxy section */
6567

6668
/* Begin PBXFileReference section */
69+
F23D7BE62348E09B004C05C4 /* Home.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Home.swift; sourceTree = "<group>"; };
70+
F23D7BE82348E591004C05C4 /* CategoryRow.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CategoryRow.swift; sourceTree = "<group>"; };
6771
F29B7DDD233F564D0025D62A /* RotatedBadgeSymbol.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RotatedBadgeSymbol.swift; sourceTree = "<group>"; };
6872
F29B7E0A233F80EB0025D62A /* HikeView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HikeView.swift; sourceTree = "<group>"; };
6973
F29B7E0C233F821F0025D62A /* Hike.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Hike.swift; sourceTree = "<group>"; };
@@ -168,6 +172,7 @@
168172
F29B7E35233F85F60025D62A /* Supporting Views */ = {
169173
isa = PBXGroup;
170174
children = (
175+
F23D7BE82348E591004C05C4 /* CategoryRow.swift */,
171176
F29B7E09233F7F880025D62A /* Badge */,
172177
F2BCE68A233A541E00D23078 /* LandmarkRow.swift */,
173178
F2BCE683233A479E00D23078 /* MapView.swift */,
@@ -212,6 +217,7 @@
212217
F2BCE690233A57FD00D23078 /* LandmarkList.swift */,
213218
F29B7E0A233F80EB0025D62A /* HikeView.swift */,
214219
F29B7E3A233F8A5D0025D62A /* HikeDetail.swift */,
220+
F23D7BE62348E09B004C05C4 /* Home.swift */,
215221
);
216222
path = Landmarks;
217223
sourceTree = "<group>";
@@ -380,6 +386,7 @@
380386
isa = PBXSourcesBuildPhase;
381387
buildActionMask = 2147483647;
382388
files = (
389+
F23D7BE92348E591004C05C4 /* CategoryRow.swift in Sources */,
383390
F29B7E0D233F821F0025D62A /* Hike.swift in Sources */,
384391
F29B7E37233F87100025D62A /* HikeGraph.swift in Sources */,
385392
F2C8B1A5233BB0460041D0BF /* HexagonParameters.swift in Sources */,
@@ -393,6 +400,7 @@
393400
F2C8B1A9233BB8850041D0BF /* BadgeSymbol.swift in Sources */,
394401
F29B7DDE233F564D0025D62A /* RotatedBadgeSymbol.swift in Sources */,
395402
F2BCE656233A2FA600D23078 /* LandmarkDetail.swift in Sources */,
403+
F23D7BE72348E09B004C05C4 /* Home.swift in Sources */,
396404
F2C8B1A7233BB6DC0041D0BF /* BadgeBackground.swift in Sources */,
397405
F2BCE68B233A541E00D23078 /* LandmarkRow.swift in Sources */,
398406
F2BCE688233A4EE700D23078 /* Landmark.swift in Sources */,

Landmarks/Home.swift

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
//
2+
// Home.swift
3+
// Landmarks
4+
//
5+
// Created by Eunae Jang on 05/10/2019.
6+
// Copyright © 2019 Eunae Jang. All rights reserved.
7+
//
8+
9+
import SwiftUI
10+
11+
struct CategoryHome: View {
12+
var categories: [String: [Landmark]] {
13+
Dictionary(
14+
grouping: landmarkData,
15+
by: { $0.category.rawValue }
16+
)
17+
}
18+
19+
var featured: [Landmark] {
20+
landmarkData.filter { $0.isFeatured }
21+
}
22+
23+
@State var showingProfile = false
24+
25+
var profileButton: some View {
26+
Button(action: { self.showingProfile.toggle() }) {
27+
Image(systemName: "person.crop.circle")
28+
.imageScale(.large)
29+
.accessibility(label: Text("User Profile"))
30+
.padding()
31+
}
32+
}
33+
34+
var body: some View {
35+
NavigationView {
36+
List {
37+
FeaturedLandmarks(landmarks: featured)
38+
.scaledToFill()
39+
.frame(height: 200)
40+
.clipped()
41+
.listRowInsets(EdgeInsets())
42+
ForEach(categories.keys.sorted(), id: \.self) { key in
43+
CategoryRow(categoryName: key, items: self.categories[key]!)
44+
}
45+
.listRowInsets(EdgeInsets())
46+
47+
NavigationLink(destination: LandmarkList()) {
48+
Text("See All")
49+
}
50+
}
51+
.navigationBarTitle(Text("Featured"))
52+
.navigationBarItems(trailing: profileButton)
53+
.sheet(isPresented: $showingProfile) {
54+
Text("User Profile")
55+
}
56+
}
57+
}
58+
}
59+
60+
struct FeaturedLandmarks: View {
61+
var landmarks: [Landmark]
62+
var body: some View {
63+
landmarks[0].image.resizable()
64+
}
65+
}
66+
67+
struct CategoryHome_Previews: PreviewProvider {
68+
static var previews: some View {
69+
CategoryHome()
70+
}
71+
}

Landmarks/LandmarkList.swift

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -12,28 +12,28 @@ struct LandmarkList: View {
1212
@EnvironmentObject var userData: UserData
1313

1414
var body: some View {
15-
NavigationView {
16-
List {
17-
Toggle(isOn: $userData.showFavoritesOnly) {
18-
Text("Favorites only")
19-
}
20-
ForEach(userData.landmarks) { landmark in
21-
if !self.userData.showFavoritesOnly || landmark.isFavorite {
22-
NavigationLink(destination: LandmarkDetail(landmark: landmark)) {
23-
LandmarkRow(landmark: landmark)
24-
}
15+
List {
16+
Toggle(isOn: $userData.showFavoritesOnly) {
17+
Text("Favorites only")
18+
}
19+
ForEach(userData.landmarks) { landmark in
20+
if !self.userData.showFavoritesOnly || landmark.isFavorite {
21+
NavigationLink(destination: LandmarkDetail(landmark: landmark)) {
22+
LandmarkRow(landmark: landmark)
2523
}
2624
}
2725
}
28-
.navigationBarTitle(Text("Landmarks"))
2926
}
27+
.navigationBarTitle(Text("Landmarks"))
3028
}
3129
}
3230

3331
struct LandmarkList_Previews: PreviewProvider {
3432
static var previews: some View {
35-
LandmarkList()
36-
.environmentObject(UserData())
33+
NavigationView {
34+
LandmarkList()
35+
.environmentObject(UserData())
36+
}
3737
}
3838
}
3939

Landmarks/Models/Landmark.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ struct Landmark: Hashable, Codable, Identifiable {
1818
var park: String
1919
var category: Category
2020
var isFavorite: Bool
21+
var isFeatured: Bool
2122

2223
var locationCoordinate: CLLocationCoordinate2D {
2324
CLLocationCoordinate2D(

Landmarks/SceneDelegate.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ class SceneDelegate: UIResponder, UIWindowSceneDelegate {
2323
if let windowScene = scene as? UIWindowScene {
2424
let window = UIWindow(windowScene: windowScene)
2525
window.rootViewController = UIHostingController(
26-
rootView: LandmarkList().environmentObject(UserData())
26+
rootView: CategoryHome().environmentObject(UserData())
2727
)
2828
self.window = window
2929
window.makeKeyAndVisible()
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
//
2+
// CategoryRow.swift
3+
// Landmarks
4+
//
5+
// Created by Eunae Jang on 05/10/2019.
6+
// Copyright © 2019 Eunae Jang. All rights reserved.
7+
//
8+
9+
import SwiftUI
10+
11+
struct CategoryRow: View {
12+
var categoryName: String
13+
var items: [Landmark]
14+
15+
var body: some View {
16+
VStack(alignment: .leading) {
17+
Text(self.categoryName)
18+
.font(.headline)
19+
.padding(.leading, 15)
20+
.padding(.top, 5)
21+
22+
ScrollView(.horizontal, showsIndicators: false) {
23+
HStack(alignment: .top, spacing: 0) {
24+
ForEach(self.items) { landmark in
25+
NavigationLink(
26+
destination: LandmarkDetail(
27+
landmark: landmark
28+
)
29+
) {
30+
CategoryItem(landmark: landmark)
31+
}
32+
}
33+
}
34+
}
35+
.frame(height: 185)
36+
}
37+
}
38+
}
39+
40+
struct CategoryItem: View {
41+
var landmark: Landmark
42+
var body: some View {
43+
VStack(alignment: .leading) {
44+
landmark.image
45+
.renderingMode(.original)
46+
.resizable()
47+
.frame(width: 155, height: 155)
48+
.cornerRadius(5)
49+
Text(landmark.name)
50+
.foregroundColor(.primary)
51+
.font(.caption)
52+
}
53+
.padding(.leading, 15)
54+
}
55+
}
56+
57+
struct CategoryRow_Previews: PreviewProvider {
58+
static var previews: some View {
59+
CategoryRow(
60+
categoryName: landmarkData[0].category.rawValue,
61+
items: Array(landmarkData.prefix(4))
62+
)
63+
}
64+
}

screenshot01.gif

23 MB
Loading

0 commit comments

Comments
 (0)