-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: #146 explore, report - navigation MVI 적용
- Loading branch information
1 parent
29f5753
commit bc3a8a0
Showing
20 changed files
with
242 additions
and
141 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
75 changes: 0 additions & 75 deletions
75
Spoony-iOS/Spoony-iOS/Resource/Tab/NavigationManager.swift
This file was deleted.
Oops, something went wrong.
19 changes: 19 additions & 0 deletions
19
Spoony-iOS/Spoony-iOS/Resource/Tab/Store/NavigationIntent.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
// | ||
// NavigationIntent.swift | ||
// Spoony-iOS | ||
// | ||
// Created by 최주리 on 1/24/25. | ||
// | ||
|
||
import Foundation | ||
|
||
enum NavigationIntent { | ||
// case build | ||
case changeTab(TabType) | ||
case push(ViewType) | ||
case pop(Int) | ||
case popToRoot | ||
case showPopup(PopupType?) | ||
case changePath([ViewType], TabType) | ||
case changeCurrentLocation(String?) | ||
} |
96 changes: 96 additions & 0 deletions
96
Spoony-iOS/Spoony-iOS/Resource/Tab/Store/NavigationManager.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
// | ||
// NavigationManager.swift | ||
// SpoonMe | ||
// | ||
// Created by 최주리 on 1/7/25. | ||
// | ||
|
||
import SwiftUI | ||
|
||
final class NavigationManager: ObservableObject { | ||
@Published private(set) var state = NavigationState() | ||
|
||
func dispatch(_ intent: NavigationIntent) { | ||
switch intent { | ||
// case .build: | ||
// <#code#> | ||
case .changeTab(let tab): | ||
state.selectedTab = tab | ||
case .push(let nextView): | ||
push(nextView) | ||
case .pop(let depth): | ||
pop(depth) | ||
case .popToRoot: | ||
popToRoot() | ||
case .showPopup(let popup): | ||
state.popup = popup | ||
case .changePath(let path, let tab): | ||
switch tab { | ||
case .map: | ||
state.mapPath = path | ||
case .explore: | ||
state.explorePath = path | ||
case .register: | ||
state.registerPath = path | ||
} | ||
case .changeCurrentLocation(let location): | ||
state.currentLocation = location | ||
} | ||
} | ||
|
||
@ViewBuilder | ||
func build(_ view: ViewType) -> some View { | ||
switch view { | ||
case .searchView: | ||
SearchView() | ||
case .locationView: | ||
Home() | ||
case .detailView(let postId): | ||
DetailView(postId: postId) | ||
case .report(let postId): | ||
Report(postId: postId) | ||
} | ||
} | ||
} | ||
|
||
extension NavigationManager { | ||
private func push(_ view: ViewType) { | ||
switch state.selectedTab { | ||
case .map: | ||
state.mapPath.append(view) | ||
case .explore: | ||
state.explorePath.append(view) | ||
case .register: | ||
state.registerPath.append(view) | ||
} | ||
} | ||
|
||
private func pop(_ depth: Int) { | ||
switch state.selectedTab { | ||
case .map: | ||
if state.mapPath.isEmpty || state.mapPath.contains(where: { | ||
if case .locationView = $0 { return true } | ||
return false | ||
}) { | ||
state.currentLocation = nil | ||
} | ||
state.mapPath.removeLast(depth) | ||
|
||
case .explore: | ||
state.explorePath.removeLast(depth) | ||
case .register: | ||
state.registerPath.removeLast(depth) | ||
} | ||
} | ||
|
||
private func popToRoot() { | ||
switch state.selectedTab { | ||
case .map: | ||
state.mapPath = [] | ||
case .explore: | ||
state.explorePath = [] | ||
case .register: | ||
state.registerPath = [] | ||
} | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
Spoony-iOS/Spoony-iOS/Resource/Tab/Store/NavigationState.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
// | ||
// NavigationState.swift | ||
// Spoony-iOS | ||
// | ||
// Created by 최주리 on 1/24/25. | ||
// | ||
|
||
import Foundation | ||
|
||
struct NavigationState { | ||
var selectedTab: TabType = .map | ||
var mapPath: [ViewType] = [] | ||
var explorePath: [ViewType] = [] | ||
var registerPath: [ViewType] = [] | ||
var currentLocation: String? | ||
var popup: PopupType? | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.