Skip to content

Commit

Permalink
[Feat/#118] 화면전환코드 구현
Browse files Browse the repository at this point in the history
  • Loading branch information
HELLOHIDI committed Nov 23, 2024
1 parent dee0746 commit f88c2e3
Show file tree
Hide file tree
Showing 20 changed files with 256 additions and 198 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
//
// DIContainer.swift
// NetworksDemo
//
// Created by 류희재 on 11/23/24.
// Copyright © 2024 HMH-iOS. All rights reserved.
//

import Foundation

typealias NavigationRoutableType = NavigationRoutable & ObservableObjectSettable

final class DIContainer: ObservableObject {

var service: HMHServiceType
var navigationRouter: NavigationRoutableType

private init(
service: HMHServiceType,
navigationRouter: NavigationRoutableType = NavigationRouter()
) {
self.service = service
self.navigationRouter = navigationRouter

navigationRouter.setObjectWillChange(objectWillChange)
}
}

extension DIContainer {
static let `default` = DIContainer(service: HMHService())
static let stub = DIContainer(service: StubHMHSerivce())
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,10 @@
import Foundation

enum NavigationDestination: Hashable {

case auth
case challenge
case point
case user

case home
}

Original file line number Diff line number Diff line change
Expand Up @@ -6,41 +6,52 @@
//// Copyright © 2024 HMH-iOS. All rights reserved.
////
//
//import Foundation
//import Combine
//
//protocol NavigationRoutable {
// var destinations: [NavigationDestination] { get set }
//
// func push(to view: NavigationDestination)
// func pop()
// func popToRootView()
//}
//
//
//class NavigationRouter: NavigationRoutable, ObservableObjectSettable {
//
// var objectWillChange: ObservableObjectPublisher?
//
// var destinations: [NavigationDestination] = [] {
// didSet {
// objectWillChange?.send()
// }
// }
//
// func push(to view: NavigationDestination) {
// destinations.append(view)
// }
//
// func pop() {
// _ = destinations.popLast()
// }
//
// func popToRootView() {
// destinations = []
// }
//
//
//}
//
//
import Foundation
import Combine

import Combine

protocol ObservableObjectSettable: AnyObject {
var objectWillChange: ObservableObjectPublisher? { get set }
func setObjectWillChange(_ objectWillChange: ObservableObjectPublisher?)
}

extension ObservableObjectSettable {
func setObjectWillChange(_ objectWillChange: ObservableObjectPublisher?) {
self.objectWillChange = objectWillChange
}
}

protocol NavigationRoutable {
var destinations: [NavigationDestination] { get set }

func push(to view: NavigationDestination)
func pop()
func popToRootView()
}


class NavigationRouter: NavigationRoutable, ObservableObjectSettable {

var objectWillChange: ObservableObjectPublisher?

var destinations: [NavigationDestination] = [] {
didSet {
objectWillChange?.send()
}
}

func push(to view: NavigationDestination) {
destinations.append(view)
}

func pop() {
_ = destinations.popLast()
}

func popToRootView() {
destinations = []
}
}


Original file line number Diff line number Diff line change
Expand Up @@ -6,100 +6,62 @@
//// Copyright © 2024 HMH-iOS. All rights reserved.
////
//
//import Foundation
//import SwiftUI
//
//struct NavigationRoutingView: View {
//
// @EnvironmentObject var container: DIContainer
// @State var destination: NavigationDestination
//
// var body: some View {
// switch destination {
// case let .editRoom(viewType):
// EditRoomInfoView(
// viewModel: .init(
// viewType: viewType,
// roomService: container.service.roomService,
// navigationRouter: container.navigationRouter
// ))
// case let .makeMission(roomInfo):
// EditMissionView(
// viewModel: EditMissionViewModel(
// roomInfo: roomInfo,
// navigationRouter: container.navigationRouter
// )
// )
// case let .roomInfo(roomInfo, missionList):
// CheckRoomInfoView(
// viewModel: .init(
// roomInfo: roomInfo,
// missionList: missionList,
// roomService: container.service.roomService,
// navigationRouter: container.navigationRouter
// )
// )
//
// case .enterRoom:
// EnterRoomView(
// viewModel: .init(
// roomService: container.service.roomService,
// navigationRouter: container.navigationRouter
// )
// )
// case let .manitoWaitingRoom(roomDetail):
// ManitoWaitingRoomView(
// viewModel: .init(
// roomService: container.service.roomService,
// navigationRouter: container.navigationRouter,
// roomDetail: roomDetail
// )
// )
//
// case .myPage:
// MyPageView(viewModel: MyPageViewModel(navigationRouter: container.navigationRouter))
//
// case .editUsername:
// EditUsernameView(
// viewModel: EditUsernameViewModel(
// userService: container.service.userService,
// navigationRouter: container.navigationRouter,
// windowRouter: container.windowRouter
// )
// )
//
// case .matchRoom(let roomID):
// MatchingView(
// viewModel: MatchingViewModel(
// roomService: container.service.roomService,
// navigationRouter: container.navigationRouter,
// roomID: roomID
// )
// )
// case .matchedRoom(let roomDetail):
// MatchingResultView(
// viewModel: MatchingResultViewModel(
// roomService: container.service.roomService,
// navigationRouter: container.navigationRouter,
// roomInfo: roomDetail
// )
// )
// case .finish(let roomDetail):
// FinishView(viewModel: FinishViewModel(roomService: container.service.roomService, navigationRouter: container.navigationRouter, roomInfo: roomDetail))
// }
//
// }
//}
//
//
//extension View {
//
// func setSMNavigation() -> some View {
// self.navigationDestination(for: NavigationDestination.self) { destination in
// return NavigationRoutingView(destination: destination)
// }
// }
//
//
//}
//
import Foundation
import SwiftUI
import Networks

struct NavigationRoutingView: View {

@State var destination: NavigationDestination
@EnvironmentObject var container: DIContainer

var body: some View {
switch destination {
case .home:
NetworkTestHomeView()
case .auth:
AuthServiceView(
viewModel: AuthServiceViewModel(
service: container.service.authService,
navigationRouter: container.navigationRouter
)
)
case .challenge:
ChallengeServiceView(
viewModel: ChallengeServiceViewModel(
service: container.service.challengeService,
navigationRouter: container.navigationRouter
)
)
.environmentObject(DIContainer.default)
case .point:
PointServiceView(
viewModel: PointServiceViewModel(
service: container.service.pointService,
navigationRouter: container.navigationRouter
)
)
case .user:
UserServiceView(
viewModel: UserServiceViewModel(
service: container.service.userService,
navigationRouter: container.navigationRouter
)
)
}

}
}


extension View {

func setHMHNavigation() -> some View {
self.navigationDestination(for: NavigationDestination.self) { destination in
return NavigationRoutingView(destination: destination)
}
}


}

Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,12 @@ struct NetworkTestApp: App {
// print(Networks.Config.baseURL)
}

@StateObject var container = DIContainer.default

var body: some Scene {
WindowGroup {
NetworkTestHomeView()
.environmentObject(container)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,10 @@ import Core
//디버그(Debug) 모드와 릴리즈(Release) 모드에서 Xcode의 프리뷰(Preview) 활성화 여부 다름 So QA를 다시 debug로 변경

struct NetworkTestHomeView: View {
@EnvironmentObject var container: DIContainer

var body: some View {
NavigationView {
NavigationStack(path: $container.navigationRouter.destinations) {
VStack(alignment: .center) {
Spacer()
.frame(height: 25)
Expand Down Expand Up @@ -51,8 +52,8 @@ struct NetworkTestHomeView: View {
Spacer()
ServiceButton(
imageResource: .auth,
title: "Point") {
print("포인트 서비스 테스트로 이동")
title: "Auth") {
container.navigationRouter.push(to: .auth)
}

Spacer()
Expand All @@ -61,7 +62,7 @@ struct NetworkTestHomeView: View {
ServiceButton(
imageResource: .challenge,
title: "Challenge") {
print("포인트 서비스 테스트로 이동")
container.navigationRouter.push(to: .challenge)
}

Spacer()
Expand All @@ -77,13 +78,7 @@ struct NetworkTestHomeView: View {
ServiceButton(
imageResource: .point,
title: "Point") {
// NavigationLink(<#LocalizedStringKey#>, destination: PointServiceView(
// viewModel: PointServiceViewModel(
// service: PointService()
// )
// )
// )
//
container.navigationRouter.push(to: .point)
}

Spacer()
Expand All @@ -92,7 +87,7 @@ struct NetworkTestHomeView: View {
ServiceButton(
imageResource: .user,
title: "User") {
print("포인트 서비스 테스트로 이동")
container.navigationRouter.push(to: .user)
}

Spacer()
Expand Down Expand Up @@ -144,5 +139,6 @@ fileprivate struct ServiceButton : View {

#Preview {
return NetworkTestHomeView()
.environmentObject(DIContainer.default)
}

Loading

0 comments on commit f88c2e3

Please sign in to comment.