Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor/#146 report navigation mvi #176

Closed
wants to merge 18 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ struct FixedBottomSheetView: View {
title: "떠먹으러 가기",
disabled: $isDisabled
) {
navigationManager.selectedTab = .explore
navigationManager.dispatch(.changeTab(.explore))
}
.padding(.top, 8)
}
Expand Down
2 changes: 0 additions & 2 deletions Spoony-iOS/Spoony-iOS/Resource/Tab/Model/ViewType.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,5 @@ enum ViewType: Hashable {
case searchView // 검색 화면
case locationView(title: String) // 위치 선택 화면
case detailView(postId: Int) // 상세 화면

case explore
case report(postId: Int)
}
75 changes: 0 additions & 75 deletions Spoony-iOS/Spoony-iOS/Resource/Tab/NavigationManager.swift

This file was deleted.

18 changes: 18 additions & 0 deletions Spoony-iOS/Spoony-iOS/Resource/Tab/Store/NavigationIntent.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
//
// NavigationIntent.swift
// Spoony-iOS
//
// Created by 최주리 on 1/24/25.
//

import Foundation

enum NavigationIntent {
case changeTab(TabType)
case push(ViewType)
case pop(Int)
case popToRoot
case showPopup(PopupType?)
case changePath([ViewType], TabType)
case changeCurrentLocation(String?)
}
95 changes: 95 additions & 0 deletions Spoony-iOS/Spoony-iOS/Resource/Tab/Store/NavigationManager.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
//
// 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 .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
}
}

//TODO: 여기 어떻게 할지 생각해보기.........
@ViewBuilder
func build(_ view: ViewType) -> some View {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

고민을 해봐도 답이 안 나오네요...

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 Spoony-iOS/Spoony-iOS/Resource/Tab/Store/NavigationState.swift
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 SwiftUI

struct NavigationState {
var selectedTab: TabType = .map
var mapPath: [ViewType] = []
var explorePath: [ViewType] = []
var registerPath: [ViewType] = []
var currentLocation: String?
var popup: PopupType?
}
29 changes: 0 additions & 29 deletions Spoony-iOS/Spoony-iOS/Source/ContentView.swift

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ struct DetailView: View {
style: .detailWithChip,
spoonCount: store.state.spoonCount,
onBackTapped: {
navigationManager.pop(1)
navigationManager.dispatch(.pop(1))
}
)
ScrollView(.vertical) {
Expand All @@ -66,7 +66,7 @@ struct DetailView: View {
store.send(intent: .getInitialValue(userId: Config.userId, postId: postId))

if !store.state.successService {
navigationManager.pop(1)
navigationManager.dispatch(.pop(1))
}

}
Expand Down Expand Up @@ -290,9 +290,9 @@ extension DetailView {
if store.state.isScoop {
store.send(intent: .pathInfoInNaverMaps)
} else {
navigationManager.popup = .useSpoon(action: {
navigationManager.dispatch(.showPopup(.useSpoon(action: {
store.send(intent: .scoopButtonDidTap)
})
})))
}

print("⭐️")
Expand All @@ -314,7 +314,7 @@ extension DetailView {
items: ["신고하기"],
isPresented: $isPresented
) { _ in
navigationManager.push(.report(postId: postId))
navigationManager.dispatch(.push(.report(postId: store.state.postId)))
}
.frame(alignment: .topTrailing)
.padding(.top, 48.adjustedH)
Expand Down
8 changes: 4 additions & 4 deletions Spoony-iOS/Spoony-iOS/Source/Feature/Explore/Explore.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@ import SwiftUI
import Lottie

struct Explore: View {
@EnvironmentObject private var navigationManager: NavigationManager
@StateObject private var store: ExploreStore = ExploreStore()
@StateObject var store: ExploreStore

var body: some View {
VStack(spacing: 0) {
Expand Down Expand Up @@ -57,6 +56,7 @@ struct Explore: View {
.task {
store.dispatch(.onAppear)
}
.toolbar(.hidden, for: .navigationBar)
}
}

Expand Down Expand Up @@ -114,7 +114,7 @@ extension Explore {
title: "등록하러 가기",
disabled: .constant(false)
) {
navigationManager.selectedTab = .register
store.dispatch(.goRegisterButtonTapped)
}
.padding(.top, 18)

Expand All @@ -130,7 +130,7 @@ extension Explore {
.padding(.bottom, 12)
.padding(.horizontal, 20)
.onTapGesture {
navigationManager.push(.detailView(postId: list.postId))
store.dispatch(.cellTapped(list))
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,6 @@ enum ExploreIntent {
// Main
case categoryTapped(CategoryChip)
case cellTapped(FeedEntity)
case goRegisterButtonTapped

}
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@ import SwiftUI
final class ExploreStore: ObservableObject {
private let network: ExploreProtocol = DefaultExploreService()
// private let network: ExploreProtocol = MockExploreService()
//TODO: navigation MVI 리팩토링은 나중에 할거다..
// let navigationManager: NavigationManager

private var navigationManager: NavigationManager

@Published private(set) var state: ExploreState = ExploreState()
init(navigationManager: NavigationManager) {
self.navigationManager = navigationManager
}

// init(navigationManager: NavigationManager) {
// self.navigationManager = navigationManager
// }
@Published private(set) var state: ExploreState = ExploreState()

func dispatch(_ intent: ExploreIntent) {
switch intent {
Expand All @@ -40,13 +40,14 @@ final class ExploreStore: ObservableObject {
state.isPresentedFilter = false
case .categoryTapped(let category):
changeCategory(category: category)
case .cellTapped(let feed): break
//추후 feed 정보 detialview에 전달
// navigationManager.push(.detailView)
case .cellTapped(let feed):
navigationManager.dispatch(.push(.detailView(postId: feed.postId)))
case .isPresentedLocationChanged(let newValue):
state.isPresentedLocation = newValue
case .isPresentedFilterChanged(let newValue):
state.isPresentedFilter = newValue
case .goRegisterButtonTapped:
navigationManager.dispatch(.changeTab(.register))
}
}
}
Expand All @@ -60,7 +61,6 @@ extension ExploreStore {
getFeedList()
state.tempLocation = nil
state.isPresentedLocation = false
// state.isSelectLocationButtonDisabled = true
}

private func changeFilter(filter: FilterType) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ struct PlaceCard: View {
.padding(.horizontal, 26)
.onTapGesture {
let postId = places[index].postId
navigationManager.push(.detailView(postId: postId))
navigationManager.dispatch(.push(.detailView(postId: postId)))
}
}
}
Expand Down
Loading