Skip to content

Commit 129046e

Browse files
97chosinteractord
authored andcommitted
feat: TabLinkNavigator - Implemented TabEventSubscriber example
1 parent fe8c078 commit 129046e

23 files changed

Lines changed: 570 additions & 18 deletions

Examples/TabNavigator/02-TabInjectionParameter/TabInjectionParameter/Pages/Common/Step3/Step3Page.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ struct Step3Page: View {
1818

1919
Button(action: {
2020
navigator.reloadLast(linkItem: .init(path: "step2", items: Step2InjectionData(message: "Replaced message!")), isAnimated: true) }) {
21-
Text("Replaced 'Step3' message")
21+
Text("Replaced 'Step2' message")
2222
}
2323

2424
Button(action: { navigator.back(isAnimated: true) }) {
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import LinkNavigator
2+
3+
struct AppDependency: DependencyType { }
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import LinkNavigator
2+
3+
public typealias RootNavigatorType = TabLinkNavigatorProtocol & LinkNavigatorFindLocationUsable
4+
5+
struct AppRouterBuilderGroup<RootNavigator: RootNavigatorType> {
6+
init() { }
7+
8+
var routers: [RouteBuilderOf<RootNavigator>] {
9+
[
10+
Tab1RouteBuilder.generate(),
11+
Tab2RouteBuilder.generate(),
12+
Tab3RouteBuilder.generate(),
13+
Tab4RouteBuilder.generate(),
14+
Step1RouteBuilder.generate(),
15+
Step2RouteBuilder.generate(),
16+
Step3RouteBuilder.generate(),
17+
Step4RouteBuilder.generate(),
18+
]
19+
}
20+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import SwiftUI
2+
3+
public struct PathIndicator: View {
4+
let currentPath: String
5+
6+
public var body: some View {
7+
VStack(spacing: 16) {
8+
Text("currentPath")
9+
.font(.headline)
10+
11+
Text(currentPath)
12+
.font(.subheadline)
13+
}
14+
.padding()
15+
.frame(maxWidth: .infinity)
16+
.background(
17+
RoundedRectangle(cornerRadius: 12).fill(.green.opacity(0.3)))
18+
.padding(.horizontal)
19+
}
20+
}

Examples/TabNavigator/03-TabEventSubscriber/TabEventSubscriber/ContentView.swift

Lines changed: 0 additions & 16 deletions
This file was deleted.
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import SwiftUI
2+
import LinkNavigator
3+
4+
struct Step1Page: View {
5+
let navigator: RootNavigatorType
6+
@State var currentPath: String = ""
7+
8+
var body: some View {
9+
VStack(spacing: 16) {
10+
PathIndicator(currentPath: currentPath)
11+
.padding(.top, 32)
12+
13+
Spacer()
14+
15+
Button(action: { navigator.next(linkItem: .init(path: "step2"), isAnimated: true) }) {
16+
Text("Next to 'Step2'")
17+
}
18+
19+
Button(action: { navigator.close(isAnimated: true, completeAction: { }) }) {
20+
Text("Close Sheet")
21+
}
22+
23+
Spacer()
24+
}
25+
.onAppear {
26+
currentPath = navigator.getCurrentPaths().joined(separator: " > ")
27+
}
28+
}
29+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import LinkNavigator
2+
import SwiftUI
3+
4+
struct Step1RouteBuilder<RootNavigator: RootNavigatorType> {
5+
6+
static func generate() -> RouteBuilderOf<RootNavigator> {
7+
var matchPath: String { "step1" }
8+
return .init(matchPath: matchPath) { navigator, items, diContainer -> RouteViewController? in
9+
return WrappingController(matchPath: matchPath) {
10+
Step1Page(navigator: navigator)
11+
}
12+
}
13+
}
14+
}
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
import SwiftUI
2+
import LinkNavigator
3+
4+
struct Step2Page: View {
5+
let navigator: RootNavigatorType
6+
let injectionData: Step2InjectionData
7+
8+
@State var currentPath: String = ""
9+
10+
var body: some View {
11+
VStack(spacing: 16) {
12+
PathIndicator(currentPath: currentPath)
13+
.padding(.top, 32)
14+
15+
GroupBox {
16+
VStack(spacing: 10) {
17+
HStack {
18+
Image(systemName: "envelope")
19+
Text("injected message from send event")
20+
}
21+
.font(.footnote)
22+
.foregroundColor(.secondary)
23+
24+
Text(injectionData.message)
25+
}
26+
}
27+
28+
Spacer()
29+
30+
Button(action: { navigator.next(linkItem: .init(path: "step3"), isAnimated: true) }) {
31+
Text("Next to 'Step3'")
32+
}
33+
34+
Button(action: { navigator.fullSheet(linkItem: .init(path: "step1"), isAnimated: true, prefersLargeTitles: false) }) {
35+
Text("Open Full-Sheet 'Step1'")
36+
}
37+
38+
Button(action: { navigator.back(isAnimated: true) }) {
39+
Text("Back")
40+
}
41+
42+
Spacer()
43+
}
44+
.onAppear {
45+
currentPath = navigator.getCurrentPaths().joined(separator: " > ")
46+
}
47+
}
48+
}
49+
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import LinkNavigator
2+
import SwiftUI
3+
4+
struct Step2RouteBuilder<RootNavigator: RootNavigatorType> {
5+
6+
static func generate() -> RouteBuilderOf<RootNavigator> {
7+
var matchPath: String { "step2" }
8+
return .init(matchPath: matchPath) { navigator, items, diContainer -> RouteViewController? in
9+
let param: Step2InjectionData = items.decoded() ?? .init(message: "")
10+
11+
return WrappingController(matchPath: matchPath) {
12+
Step2Page(navigator: navigator, injectionData: param)
13+
}
14+
}
15+
}
16+
}
17+
18+
public struct Step2InjectionData: Codable {
19+
public let message: String
20+
21+
public init(message: String) {
22+
self.message = message
23+
}
24+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import SwiftUI
2+
import LinkNavigator
3+
4+
struct Step3Page: View {
5+
let navigator: RootNavigatorType
6+
@State var currentPath: String = ""
7+
8+
var body: some View {
9+
VStack(spacing: 16) {
10+
PathIndicator(currentPath: currentPath)
11+
.padding(.top, 32)
12+
13+
Spacer()
14+
15+
Button(action: { navigator.next(linkItem: .init(path: "step4"), isAnimated: true) }) {
16+
Text("Next to 'Step4'")
17+
}
18+
19+
Button(action: { navigator.back(isAnimated: true) }) {
20+
Text("Back")
21+
}
22+
23+
Spacer()
24+
}
25+
.onAppear {
26+
currentPath = navigator.getCurrentPaths().joined(separator: " > ")
27+
}
28+
}
29+
}

0 commit comments

Comments
 (0)