Skip to content

Commit 34b1fa4

Browse files
lks574interactord
authored andcommitted
feat: SingleNavigator03 - Routing and Login
1 parent 2b5da0b commit 34b1fa4

5 files changed

Lines changed: 111 additions & 5 deletions

File tree

โ€ŽExamples/SingleNavigator/SingleTicTacToe/SingleTicTacToe/Page/Game/GameRoutebuilder.swiftโ€Ž

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,14 @@ struct GameRouteBuilder<RootNavigator: RootNavigatorType> {
66
static func generate() -> RouteBuilderOf<RootNavigator> {
77
var matchPath: String { "game" }
88
return .init(matchPath: matchPath) { navigator, items, diContainer -> RouteViewController? in
9+
let query: GameInjectionData? = items.decoded()
910
return WrappingController(matchPath: matchPath) {
10-
GameView(navigator: navigator)
11+
GameView(navigator: navigator, injectionData: query)
1112
}
1213
}
1314
}
1415
}
16+
17+
struct GameInjectionData: Equatable, Codable {
18+
let gameTitle: String
19+
}

โ€ŽExamples/SingleNavigator/SingleTicTacToe/SingleTicTacToe/Page/Game/GameView.swiftโ€Ž

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,27 @@ import LinkNavigator
44
struct GameView: View {
55

66
let navigator: RootNavigatorType
7+
let injectionData: GameInjectionData?
8+
9+
var gameTitle: String {
10+
injectionData?.gameTitle ?? ""
11+
}
712

813
var body: some View {
9-
Text("GameView")
14+
VStack(spacing: 30) {
15+
PathIndicator(currentPath: navigator.getCurrentPaths().joined(separator: " -> "))
16+
.padding(.top, 32)
17+
18+
Text("\(gameTitle) ๊ฒŒ์ž„")
19+
20+
Spacer()
21+
22+
Button(action: {
23+
navigator.back(isAnimated: true)
24+
}) {
25+
Text("๊ฒŒ์ž„ ์ข…๋ฃŒ")
26+
}
27+
}
28+
.padding()
1029
}
1130
}

โ€ŽExamples/SingleNavigator/SingleTicTacToe/SingleTicTacToe/Page/Home/HomeView.swiftโ€Ž

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,26 @@ struct HomeView: View {
55

66
let navigator: RootNavigatorType
77

8+
@State private var isLogin = UserDefaults.standard.bool(forKey: "isLogin")
9+
810
var body: some View {
9-
Text("HomeView")
11+
VStack(spacing: 30) {
12+
PathIndicator(currentPath: navigator.getCurrentPaths().joined(separator: " -> "))
13+
.padding(.top, 32)
14+
15+
Button(action: {
16+
navigator.sheet(linkItem: .init(path: "login"), isAnimated: true)
17+
}) {
18+
Text("go to Login")
19+
}
20+
21+
Spacer()
22+
}
23+
.padding()
24+
.onAppear {
25+
if isLogin {
26+
navigator.replace(linkItem: .init(path: "newGame"), isAnimated: true)
27+
}
28+
}
1029
}
1130
}

โ€ŽExamples/SingleNavigator/SingleTicTacToe/SingleTicTacToe/Page/Login/LoginView.swiftโ€Ž

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,34 @@ struct LoginView: View {
55

66
let navigator: RootNavigatorType
77

8+
@State private var message: String = ""
9+
@State private var password: String = ""
10+
811
var body: some View {
9-
Text("LoginView")
12+
VStack(spacing: 30) {
13+
PathIndicator(currentPath: navigator.getCurrentPaths().joined(separator: " -> "))
14+
.padding(.top, 32)
15+
16+
VStack(spacing: 16) {
17+
TextField("id", text: $message)
18+
.textFieldStyle(.roundedBorder)
19+
.padding(.horizontal)
20+
21+
SecureField("password", text: $password)
22+
.textFieldStyle(.roundedBorder)
23+
.padding(.horizontal)
24+
25+
Button(action: {
26+
UserDefaults.standard.setValue(true, forKey: "isLogin")
27+
navigator.close(isAnimated: true) {
28+
navigator.rootReloadLast(items: .init(path: "home"), isAnimated: true)
29+
}
30+
}) {
31+
Text("Login")
32+
}
33+
}
34+
Spacer()
35+
}
36+
.padding()
1037
}
1138
}

โ€ŽExamples/SingleNavigator/SingleTicTacToe/SingleTicTacToe/Page/NewGame/NewGameView.swiftโ€Ž

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,44 @@ import LinkNavigator
44
struct NewGameView: View {
55

66
let navigator: RootNavigatorType
7+
@State var gameTitle: String = ""
78

89
var body: some View {
9-
Text("NewGameView")
10+
VStack(spacing: 30) {
11+
PathIndicator(currentPath: navigator.getCurrentPaths().joined(separator: " -> "))
12+
.padding(.top, 32)
13+
14+
15+
VStack(spacing: 16) {
16+
Text("์ƒˆ๋กœ์šด ๊ฒŒ์ž„ ์ƒ์„ฑ")
17+
TextField("Type message here", text: $gameTitle)
18+
.textFieldStyle(.roundedBorder)
19+
.padding(.horizontal)
20+
21+
Button(action: {
22+
navigator.next(
23+
linkItem: .init(
24+
path: "game",
25+
items: GameInjectionData(gameTitle: gameTitle).encoded()
26+
),
27+
isAnimated: true)
28+
}) {
29+
Text("๊ฒŒ์ž„ ์‹œ์ž‘")
30+
}
31+
}
32+
33+
Spacer()
34+
35+
Button(action: {
36+
UserDefaults.standard.setValue(false, forKey: "isLogin")
37+
navigator.replace(linkItem: .init(path: "home"), isAnimated: true)
38+
}) {
39+
Text("logout")
40+
}
41+
42+
Spacer()
43+
}
44+
.padding()
1045
}
1146
}
47+

0 commit comments

Comments
ย (0)