Skip to content

Commit 190a7bb

Browse files
committed
update Router package and apply it
1 parent fffd8d1 commit 190a7bb

File tree

4 files changed

+57
-20
lines changed

4 files changed

+57
-20
lines changed

README.md

Lines changed: 26 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,15 @@ struct RouterExampleApp: App {
2222
var body: some Scene {
2323
WindowGroup {
2424
RouterRootView { router in
25-
EmptyView()
26-
.onAppear {
27-
if isFirstLaunch {
28-
router.route("myapp://onboarding1", .replace)
29-
} else {
30-
router.route("myapp://content", .replace)
31-
}
25+
Switch(isFirstLaunch)
26+
.Case(true) { _ in
27+
OnboardingView()
28+
}
29+
.Case(false) { _ in
30+
ContentView()
31+
}
32+
.Else {
33+
EmptyView()
3234
}
3335
}
3436
.path("myapp://onboarding1") { _ in
@@ -50,8 +52,23 @@ struct RouterExampleApp: App {
5052
CounterView(count: data.bindings.count)
5153
}
5254
.path("myapp://color") { data in
53-
ColorView(color: MyColor(rawValue: data.color ?? "red") ?? .red)
54-
.navigationBarHidden(true)
55+
If<String>(data.color).Let { color in
56+
ColorView(color: MyColor.from(string: color))
57+
.navigationBarHidden(true)
58+
}
59+
// or
60+
// Switch<String>(data.color)
61+
// .Case("red") { color in
62+
// ColorView(color: MyColor.from(string: color))
63+
// .navigationBarHidden(true)
64+
// }
65+
// .Case("green") { color in
66+
// ColorView(color: MyColor.from(string: color))
67+
// .navigationBarHidden(true)
68+
// }
69+
// .Else {
70+
// Text("OMG")
71+
// }
5572
}
5673
}
5774
}

RouterExample.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

RouterExample/ColorView.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@ enum MyColor: String {
1515
case yellow
1616
case purple
1717
case white
18+
19+
static func from(string: String) -> MyColor {
20+
return MyColor(rawValue: string) ?? .white
21+
}
1822
}
1923

2024
struct ColorView: View {

RouterExample/RouterExampleApp.swift

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,15 @@ struct RouterExampleApp: App {
1818
var body: some Scene {
1919
WindowGroup {
2020
RouterRootView { router in
21-
EmptyView()
22-
.onAppear {
23-
if isFirstLaunch {
24-
router.route("myapp://onboarding1", .replace)
25-
} else {
26-
router.route("myapp://content", .replace)
27-
}
21+
Switch(isFirstLaunch)
22+
.Case(true) { _ in
23+
OnboardingView()
24+
}
25+
.Case(false) { _ in
26+
ContentView()
27+
}
28+
.Else {
29+
EmptyView()
2830
}
2931
}
3032
.path("myapp://onboarding1") { _ in
@@ -46,8 +48,22 @@ struct RouterExampleApp: App {
4648
CounterView(count: data.bindings.count)
4749
}
4850
.path("myapp://color") { data in
49-
ColorView(color: MyColor(rawValue: data.color ?? "red") ?? .red)
50-
.navigationBarHidden(true)
51+
If<String>(data.color).Let { color in
52+
ColorView(color: MyColor.from(string: color))
53+
.navigationBarHidden(true)
54+
}
55+
// Switch<String>(data.color)
56+
// .Case("red") { color in
57+
// ColorView(color: MyColor.from(string: color))
58+
// .navigationBarHidden(true)
59+
// }
60+
// .Case("green") { color in
61+
// ColorView(color: MyColor.from(string: color))
62+
// .navigationBarHidden(true)
63+
// }
64+
// .Else {
65+
// Text("OMG")
66+
// }
5167
}
5268
}
5369
}

0 commit comments

Comments
 (0)