Skip to content

Commit f11478a

Browse files
committed
Upgrade "App Design and Layout"
1 parent 1c3a22c commit f11478a

29 files changed

+204
-227
lines changed

App-Design-and-Layout/AppDelegate.swift

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@ import UIKit
1010
@UIApplicationMain
1111
class AppDelegate: UIResponder, UIApplicationDelegate {
1212

13-
14-
1513
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
1614
// Override point for customization after application launch.
1715
return true
@@ -22,7 +20,6 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
2220
}
2321

2422
// MARK: UISceneSession Lifecycle
25-
2623
func application(_ application: UIApplication, configurationForConnecting connectingSceneSession: UISceneSession, options: UIScene.ConnectionOptions) -> UISceneConfiguration {
2724
// Called when a new scene session is being created.
2825
// Use this method to select a configuration to create the new scene with.
@@ -35,6 +32,4 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
3532
// Use this method to release any resources that were specific to the discarded scenes, as they will not return.
3633
}
3734

38-
3935
}
40-

App-Design-and-Layout/Assets.xcassets/AppIcon.appiconset/Contents.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,15 @@
3636
"scale" : "3x"
3737
},
3838
{
39-
"idiom" : "iphone",
4039
"size" : "60x60",
40+
"idiom" : "iphone",
41+
"filename" : "landmark_app_icon_120x120-1.png",
4142
"scale" : "2x"
4243
},
4344
{
44-
"idiom" : "iphone",
4545
"size" : "60x60",
46+
"idiom" : "iphone",
47+
"filename" : "landmark_app_icon_180x180.png",
4648
"scale" : "3x"
4749
},
4850
{
Loading
Loading

App-Design-and-Layout/CategoryRow.swift

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,10 @@ struct CategoryRow: View {
1818
.padding(.leading, 15)
1919
.padding(.top, 5)
2020

21-
ScrollView(showsHorizontalIndicator: false) {
21+
ScrollView(.horizontal, showsIndicators: false) {
2222
HStack(alignment: .top, spacing: 0) {
2323
ForEach(self.items) { landmark in
24-
NavigationButton(
24+
NavigationLink(
2525
destination: LandmarkDetail(
2626
landmark: landmark
2727
)
@@ -30,8 +30,8 @@ struct CategoryRow: View {
3030
}
3131
}
3232
}
33-
}
34-
.frame(height: 185)
33+
}
34+
.frame(height: 185)
3535
}
3636
}
3737
}
@@ -40,25 +40,25 @@ struct CategoryItem: View {
4040
var landmark: Landmark
4141
var body: some View {
4242
VStack(alignment: .leading) {
43-
landmark
44-
.image(forSize: 155)
43+
landmark.image
4544
.renderingMode(.original)
45+
.resizable()
46+
.frame(width: 155, height: 155)
4647
.cornerRadius(5)
4748
Text(landmark.name)
48-
.color(.primary)
49+
.foregroundColor(.primary)
4950
.font(.caption)
50-
}
51-
.padding(.leading, 15)
51+
}
52+
.padding(.leading, 15)
5253
}
5354
}
5455

55-
#if DEBUG
5656
struct CategoryRow_Previews: PreviewProvider {
5757
static var previews: some View {
5858
CategoryRow(
5959
categoryName: landmarkData[0].category.rawValue,
6060
items: Array(landmarkData.prefix(4))
6161
)
62+
.environmentObject(UserData())
6263
}
6364
}
64-
#endif

App-Design-and-Layout/ContentView.swift

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

App-Design-and-Layout/HikeBadge.swift

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,8 @@ struct HikeBadge: View {
2222
}
2323
}
2424

25-
#if DEBUG
26-
struct HikeBadge_Previews : PreviewProvider {
25+
struct HikeBadge_Previews: PreviewProvider {
2726
static var previews: some View {
2827
HikeBadge(name: "Preview Testing")
2928
}
3029
}
31-
#endif

App-Design-and-Layout/HikeDetail.swift

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,13 @@ struct HikeDetail: View {
2323
.frame(height: 200, alignment: .center)
2424

2525
HStack(spacing: 25) {
26-
ForEach(buttons.identified(by: \.0)) { value in
26+
ForEach(buttons, id: \.0) { value in
2727
Button(action: {
2828
self.dataToShow = value.1
2929
}) {
3030
Text(verbatim: value.0)
3131
.font(.system(size: 15))
32-
.color(value.1 == self.dataToShow
32+
.foregroundColor(value.1 == self.dataToShow
3333
? Color.gray
3434
: Color.accentColor)
3535
.animation(nil)
@@ -40,10 +40,8 @@ struct HikeDetail: View {
4040
}
4141
}
4242

43-
#if DEBUG
4443
struct HikeDetail_Previews: PreviewProvider {
4544
static var previews: some View {
4645
HikeDetail(hike: hikeData[0])
4746
}
4847
}
49-
#endif

App-Design-and-Layout/HikeView.swift

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ struct HikeView: View {
1414
var transition: AnyTransition {
1515
let insertion = AnyTransition.move(edge: .trailing)
1616
.combined(with: .opacity)
17-
let removal = AnyTransition.scale()
17+
let removal = AnyTransition.scale
1818
.combined(with: .opacity)
1919
return .asymmetric(insertion: insertion, removal: removal)
2020
}
@@ -36,7 +36,7 @@ struct HikeView: View {
3636

3737
Button(action: {
3838
withAnimation {
39-
self.showDetail.toggle()
39+
self.showDetail.toggle()
4040
}
4141
}) {
4242
Image(systemName: "chevron.right.circle")
@@ -49,13 +49,12 @@ struct HikeView: View {
4949

5050
if showDetail {
5151
HikeDetail(hike: hike)
52-
.transition(transition)
52+
.transition(transition)
5353
}
5454
}
5555
}
5656
}
5757

58-
#if DEBUG
5958
struct HikeView_Previews: PreviewProvider {
6059
static var previews: some View {
6160
VStack {
@@ -65,4 +64,3 @@ struct HikeView_Previews: PreviewProvider {
6564
}
6665
}
6766
}
68-
#endif

App-Design-and-Layout/Home.swift

Lines changed: 26 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import SwiftUI
99

1010
struct CategoryHome: View {
1111
var categories: [String: [Landmark]] {
12-
.init(
12+
Dictionary(
1313
grouping: landmarkData,
1414
by: { $0.category.rawValue }
1515
)
@@ -19,6 +19,18 @@ struct CategoryHome: View {
1919
landmarkData.filter { $0.isFeatured }
2020
}
2121

22+
@State var showingProfile = false
23+
@EnvironmentObject var userData: UserData
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+
2234
var body: some View {
2335
NavigationView {
2436
List {
@@ -28,39 +40,35 @@ struct CategoryHome: View {
2840
.clipped()
2941
.listRowInsets(EdgeInsets())
3042

31-
ForEach(categories.keys.sorted().identified(by: \.self)) { key in
43+
ForEach(categories.keys.sorted(), id: \.self) { key in
3244
CategoryRow(categoryName: key, items: self.categories[key]!)
33-
}
34-
.listRowInsets(EdgeInsets())
45+
}
46+
.listRowInsets(EdgeInsets())
3547

36-
NavigationButton(destination: LandmarkList()) {
48+
NavigationLink(destination: LandmarkList()) {
3749
Text("See All")
3850
}
39-
}
40-
.navigationBarTitle(Text("Featured"))
41-
.navigationBarItems(trailing:
42-
PresentationButton(destination: Text("User Profile")) {
43-
Image(systemName: "person.crop.circle")
44-
.imageScale(.large)
45-
.accessibility(label: Text("User Profile"))
46-
.padding()
47-
}
48-
)
51+
}
52+
.navigationBarTitle(Text("Featured"))
53+
.navigationBarItems(trailing: profileButton)
54+
.sheet(isPresented: $showingProfile) {
55+
ProfileHost()
56+
.environmentObject(self.userData)
57+
}
4958
}
5059
}
5160
}
5261

5362
struct FeaturedLandmarks: View {
5463
var landmarks: [Landmark]
5564
var body: some View {
56-
landmarks[0].image(forSize: 250).resizable()
65+
landmarks[0].image.resizable()
5766
}
5867
}
5968

60-
#if DEBUG
6169
struct CategoryHome_Previews: PreviewProvider {
6270
static var previews: some View {
6371
CategoryHome()
72+
.environmentObject(UserData())
6473
}
6574
}
66-
#endif

App-Design-and-Layout/LandmarkDetail.swift

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ struct LandmarkDetail: View {
2121
.edgesIgnoringSafeArea(.top)
2222
.frame(height: 300)
2323

24-
CircleImage(image: landmark.image(forSize: 250))
24+
CircleImage(image: landmark.image)
2525
.offset(x: 0, y: -130)
2626
.padding(.bottom, -130)
2727

@@ -60,12 +60,10 @@ struct LandmarkDetail: View {
6060
}
6161
}
6262

63-
#if DEBUG
6463
struct LandmarkDetail_Preview: PreviewProvider {
6564
static var previews: some View {
6665
let userData = UserData()
6766
return LandmarkDetail(landmark: userData.landmarks[0])
6867
.environmentObject(userData)
6968
}
7069
}
71-
#endif

App-Design-and-Layout/LandmarkList.swift

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,33 +8,38 @@ A view showing a list of landmarks.
88
import SwiftUI
99

1010
struct LandmarkList: View {
11-
@EnvironmentObject var userData: UserData
11+
@EnvironmentObject private var userData: UserData
1212

1313
var body: some View {
14-
1514
List {
1615
Toggle(isOn: $userData.showFavoritesOnly) {
17-
Text("Favorites only")
16+
Text("Show Favorites Only")
1817
}
1918

2019
ForEach(userData.landmarks) { landmark in
2120
if !self.userData.showFavoritesOnly || landmark.isFavorite {
22-
NavigationButton(destination: LandmarkDetail(landmark: landmark)) {
21+
NavigationLink(
22+
destination: LandmarkDetail(landmark: landmark)
23+
.environmentObject(self.userData)
24+
) {
2325
LandmarkRow(landmark: landmark)
2426
}
2527
}
2628
}
27-
}
28-
.navigationBarTitle(Text("Landmarks"))
29-
29+
}
30+
.navigationBarTitle(Text("Landmarks"))
3031
}
3132
}
3233

33-
struct LandmarkList_Previews: PreviewProvider {
34+
struct LandmarksList_Previews: PreviewProvider {
3435
static var previews: some View {
35-
NavigationView {
36-
LandmarkList()
37-
.environmentObject(UserData())
36+
ForEach(["iPhone SE", "iPhone XS Max"], id: \.self) { deviceName in
37+
NavigationView {
38+
LandmarkList()
39+
}
40+
.previewDevice(PreviewDevice(rawValue: deviceName))
41+
.previewDisplayName(deviceName)
3842
}
43+
.environmentObject(UserData())
3944
}
4045
}
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
/*
2-
See LICENSE folder for this sample’s licensing information.
3-
4-
Abstract:
5-
A single row to be displayed in a list of landmarks.
6-
*/
1+
//
2+
// LandmarkRow.swift
3+
// App-Design-and-Layout
4+
//
5+
// Created by 王炜 on 2019/10/12.
6+
//
77

88
import SwiftUI
99

@@ -12,7 +12,9 @@ struct LandmarkRow: View {
1212

1313
var body: some View {
1414
HStack {
15-
landmark.image(forSize: 50)
15+
landmark.image
16+
.resizable()
17+
.frame(width: 50, height: 50)
1618
Text(verbatim: landmark.name)
1719
Spacer()
1820

@@ -25,7 +27,6 @@ struct LandmarkRow: View {
2527
}
2628
}
2729

28-
#if DEBUG
2930
struct LandmarkRow_Previews: PreviewProvider {
3031
static var previews: some View {
3132
Group {
@@ -35,4 +36,3 @@ struct LandmarkRow_Previews: PreviewProvider {
3536
.previewLayout(.fixed(width: 300, height: 70))
3637
}
3738
}
38-
#endif

0 commit comments

Comments
 (0)