Skip to content

Commit 83f60bc

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

File tree

8 files changed

+56
-59
lines changed

8 files changed

+56
-59
lines changed

README.md

Lines changed: 25 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -32,32 +32,42 @@ struct RouterExampleApp: App {
3232
.Else {
3333
EmptyView()
3434
}
35+
.navigationBarHidden(true)
3536
}
36-
.path("myapp://onboarding1") { _ in
37-
OnboardingView()
38-
}
39-
.path("myapp://onboarding2") { _ in
40-
OnboardingView2()
41-
}
42-
.path("myapp://content") { _ in
43-
ContentView()
37+
.path("myapp://onboarding") { data in
38+
Switch(data.page.flatMap { Int($0) })
39+
.Case(1) { _ in
40+
OnboardingView()
41+
}
42+
.Case(2) { _ in
43+
OnboardingView2()
44+
}
45+
.Else {
46+
EmptyView()
47+
}
4448
.navigationBarHidden(true)
4549
}
46-
.path("myapp://content.as.root") { _ in
47-
ContentView()
50+
.path("myapp://content") { data in
51+
Switch(data.as_root.flatMap { Bool($0) })
52+
.Case(true) { _ in
53+
ContentView()
54+
.asRouterRootView()
55+
}
56+
.Else {
57+
ContentView()
58+
}
4859
.navigationBarHidden(true)
49-
.asRouterRootView()
5060
}
5161
.path("myapp://counter") { data in
5262
CounterView(count: data.bindings.count)
63+
.navigationBarHidden(true)
5364
}
5465
.path("myapp://color") { data in
55-
If<String>(data.color).Let { color in
66+
If(data.color).Let { color in
5667
ColorView(color: MyColor.from(string: color))
57-
.navigationBarHidden(true)
5868
}
59-
// or
60-
// Switch<String>(data.color)
69+
.navigationBarHidden(true)
70+
// Switch(data.color)
6171
// .Case("red") { color in
6272
// ColorView(color: MyColor.from(string: color))
6373
// .navigationBarHidden(true)

RouterExample.xcodeproj/project.pbxproj

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
4E59BC5225F268C90069B248 /* OnboardingView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4E59BC5125F268C90069B248 /* OnboardingView.swift */; };
1818
4E59BC5625F26B9E0069B248 /* OnboardingView2.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4E59BC5525F26B9E0069B248 /* OnboardingView2.swift */; };
1919
4E59BC5A25F26DD90069B248 /* ColorView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4E59BC5925F26DD90069B248 /* ColorView.swift */; };
20-
4E59BC5E25F26E560069B248 /* GreenView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4E59BC5D25F26E560069B248 /* GreenView.swift */; };
2120
4E59BC6325F2749C0069B248 /* CounterView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4E59BC6225F2749C0069B248 /* CounterView.swift */; };
2221
/* End PBXBuildFile section */
2322

@@ -32,7 +31,6 @@
3231
4E59BC5125F268C90069B248 /* OnboardingView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = OnboardingView.swift; sourceTree = "<group>"; };
3332
4E59BC5525F26B9E0069B248 /* OnboardingView2.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = OnboardingView2.swift; sourceTree = "<group>"; };
3433
4E59BC5925F26DD90069B248 /* ColorView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ColorView.swift; sourceTree = "<group>"; };
35-
4E59BC5D25F26E560069B248 /* GreenView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GreenView.swift; sourceTree = "<group>"; };
3634
4E59BC6225F2749C0069B248 /* CounterView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CounterView.swift; sourceTree = "<group>"; };
3735
/* End PBXFileReference section */
3836

@@ -74,7 +72,6 @@
7472
4E59BC5125F268C90069B248 /* OnboardingView.swift */,
7573
4E59BC5525F26B9E0069B248 /* OnboardingView2.swift */,
7674
4E59BC5925F26DD90069B248 /* ColorView.swift */,
77-
4E59BC5D25F26E560069B248 /* GreenView.swift */,
7875
4E59BC6225F2749C0069B248 /* CounterView.swift */,
7976
4E59BC3825F266BD0069B248 /* Assets.xcassets */,
8077
4E59BC3D25F266BD0069B248 /* Info.plist */,
@@ -171,7 +168,6 @@
171168
4E59BC4E25F268520069B248 /* Prefs.swift in Sources */,
172169
4E59BC5225F268C90069B248 /* OnboardingView.swift in Sources */,
173170
4E59BC5A25F26DD90069B248 /* ColorView.swift in Sources */,
174-
4E59BC5E25F26E560069B248 /* GreenView.swift in Sources */,
175171
4E59BC3725F266BC0069B248 /* ContentView.swift in Sources */,
176172
4E59BC3525F266BC0069B248 /* RouterExampleApp.swift in Sources */,
177173
4E59BC6325F2749C0069B248 /* CounterView.swift in Sources */,

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: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ struct ColorView: View {
5757
}
5858
}
5959

60-
Button(action: { router.route("myapp://content.as.root", .sheet) }) {
60+
Button(action: { router.route("myapp://content?as_root=true", .sheet) }) {
6161
Text("Go to Sheet")
6262
.foregroundColor(.black)
6363
}

RouterExample/ContentView.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,12 @@ struct ContentView: View {
2323
Text("\(count)")
2424
.font(.title)
2525

26-
Button("Go to Sheet") {
26+
Button("Go to Counter Sheet") {
2727
//router.route("myapp://color?color=red", .sheet)
2828
router.builder()
2929
.route("myapp://counter")
3030
.presentation(mode: .sheet)
31-
.binding(name: "count", $count)
31+
.binding(name: "count", to: $count)
3232
.go()
3333
}
3434
}

RouterExample/GreenView.swift

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

RouterExample/OnboardingView.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ struct OnboardingView: View {
1717
VStack {
1818
Text("Onboarding View Page 1")
1919
Button("Next") {
20-
router.route("myapp://onboarding2", .push)
20+
router.route("myapp://onboarding?page=2", .push)
2121
}
2222
}
2323
}

RouterExample/RouterExampleApp.swift

Lines changed: 25 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -28,31 +28,42 @@ struct RouterExampleApp: App {
2828
.Else {
2929
EmptyView()
3030
}
31+
.navigationBarHidden(true)
3132
}
32-
.path("myapp://onboarding1") { _ in
33-
OnboardingView()
34-
}
35-
.path("myapp://onboarding2") { _ in
36-
OnboardingView2()
37-
}
38-
.path("myapp://content") { _ in
39-
ContentView()
33+
.path("myapp://onboarding") { data in
34+
Switch(data.page.flatMap { Int($0) })
35+
.Case(1) { _ in
36+
OnboardingView()
37+
}
38+
.Case(2) { _ in
39+
OnboardingView2()
40+
}
41+
.Else {
42+
EmptyView()
43+
}
4044
.navigationBarHidden(true)
4145
}
42-
.path("myapp://content.as.root") { _ in
43-
ContentView()
46+
.path("myapp://content") { data in
47+
Switch(data.as_root.flatMap { Bool($0) })
48+
.Case(true) { _ in
49+
ContentView()
50+
.asRouterRootView()
51+
}
52+
.Else {
53+
ContentView()
54+
}
4455
.navigationBarHidden(true)
45-
.asRouterRootView()
4656
}
4757
.path("myapp://counter") { data in
4858
CounterView(count: data.bindings.count)
59+
.navigationBarHidden(true)
4960
}
5061
.path("myapp://color") { data in
51-
If<String>(data.color).Let { color in
62+
If(data.color).Let { color in
5263
ColorView(color: MyColor.from(string: color))
53-
.navigationBarHidden(true)
5464
}
55-
// Switch<String>(data.color)
65+
.navigationBarHidden(true)
66+
// Switch(data.color)
5667
// .Case("red") { color in
5768
// ColorView(color: MyColor.from(string: color))
5869
// .navigationBarHidden(true)

0 commit comments

Comments
 (0)