-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
10f90e6
commit b04100f
Showing
10 changed files
with
370 additions
and
3 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
40 changes: 40 additions & 0 deletions
40
Projects/App/Sources/Presentation/Tabbar+Navigation/Router/Ex+View+Navigation.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,40 @@ | ||
// | ||
// Ex+View+Navigation.swift | ||
// DesignSystem | ||
// | ||
// Created by 박서연 on 2024/06/12. | ||
// Copyright © 2024 iOS. All rights reserved. | ||
// | ||
|
||
import SwiftUI | ||
|
||
public extension View { | ||
func navigationBackButton(_ action: @escaping () -> Void) -> some View { | ||
self.navigationBarBackButtonHidden() | ||
.toolbar { | ||
ToolbarItem(placement: .topBarLeading) { | ||
Button(action: action, label: { | ||
// TODO: - 백버튼 이미지 수정 | ||
|
||
Image("arrowBack") | ||
.resizable() | ||
.frame(width: 24, height: 24) | ||
}) | ||
} | ||
} | ||
} | ||
|
||
func navigationTitle(with text: Text) -> some View { | ||
VStack(spacing: 31) { | ||
HStack(spacing: 0) { | ||
text | ||
.applyFont(font: .heading1) | ||
.frame(height: 47) | ||
.frame(maxWidth: .infinity, alignment: .leading) | ||
.padding(.init(top: 10, leading: 22, bottom: 10, trailing: 0)) | ||
Spacer() | ||
} | ||
self | ||
} | ||
} | ||
} |
62 changes: 62 additions & 0 deletions
62
Projects/App/Sources/Presentation/Tabbar+Navigation/Router/Router.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,62 @@ | ||
// | ||
// Router.swift | ||
// DesignSystem | ||
// | ||
// Created by 박서연 on 2024/06/12. | ||
// Copyright © 2024 iOS. All rights reserved. | ||
// | ||
|
||
import Foundation | ||
import SwiftUI | ||
|
||
public class Router: ObservableObject { | ||
public enum Route: Hashable, Identifiable { | ||
public var id: Self { self } | ||
|
||
case tabView | ||
case login | ||
case home | ||
case category | ||
case mypage | ||
case review | ||
case setting | ||
} | ||
|
||
@Published public var path: NavigationPath = NavigationPath() | ||
|
||
@ViewBuilder public func view(for route: Route) -> some View { | ||
switch route { | ||
case .tabView: | ||
TabbarMainView() | ||
case .login: | ||
Text("login") | ||
case .home: | ||
HomeView() | ||
case .category: | ||
CategoryView() | ||
case .mypage: | ||
MypageView() | ||
case .review: | ||
AnotherView() | ||
case .setting: | ||
Text("setting") | ||
} | ||
} | ||
|
||
public func navigateTo(_ page: Route) { | ||
path.append(page) | ||
} | ||
|
||
public func navigateBack() { | ||
path.removeLast() | ||
} | ||
|
||
public func popToRoot() { | ||
path.removeLast(path.count) | ||
} | ||
|
||
public func replaceNavigationStack(_ page: Route) { | ||
path.removeLast(path.count) | ||
path.append(page) | ||
} | ||
} |
38 changes: 38 additions & 0 deletions
38
Projects/App/Sources/Presentation/Tabbar+Navigation/Router/RouterView.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,38 @@ | ||
// | ||
// RouterView.swift | ||
// DesignSystem | ||
// | ||
// Created by 박서연 on 2024/06/12. | ||
// Copyright © 2024 iOS. All rights reserved. | ||
// | ||
|
||
import SwiftUI | ||
|
||
struct RouterView<Content: View>: View { | ||
@StateObject var router: Router = Router() | ||
private let content: Content | ||
|
||
init(@ViewBuilder content: @escaping () -> Content) { | ||
self.content = content() | ||
} | ||
|
||
var body: some View { | ||
NavigationStack(path: $router.path) { | ||
VStack { | ||
content | ||
} | ||
.navigationDestination(for: Router.Route.self) { route in | ||
router.view(for: route) | ||
} | ||
.onAppear { | ||
router.navigateTo(.tabView) | ||
} | ||
.navigationBarTitle("", displayMode: .inline) | ||
} | ||
.environmentObject(router) | ||
} | ||
} | ||
|
||
//#Preview { | ||
// RouterView() | ||
//} |
19 changes: 19 additions & 0 deletions
19
Projects/App/Sources/Presentation/Tabbar+Navigation/Tabbar/Sample/AnotherView.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 @@ | ||
// | ||
// AnotherView.swift | ||
// App | ||
// | ||
// Created by 박서연 on 2024/06/13. | ||
// Copyright © 2024 iOS. All rights reserved. | ||
// | ||
|
||
import SwiftUI | ||
|
||
struct AnotherView: View { | ||
var body: some View { | ||
Text("Saaaaample Viewwwwww") | ||
} | ||
} | ||
|
||
#Preview { | ||
AnotherView() | ||
} |
62 changes: 62 additions & 0 deletions
62
Projects/App/Sources/Presentation/Tabbar+Navigation/Tabbar/Sample/SampleView.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,62 @@ | ||
// | ||
// HomeView.swift | ||
// DesignSystem | ||
// | ||
// Created by 박서연 on 2024/06/12. | ||
// Copyright © 2024 iOS. All rights reserved. | ||
// | ||
|
||
import SwiftUI | ||
|
||
struct HomeView: View { | ||
@EnvironmentObject var router: Router | ||
@EnvironmentObject var viewModel: TabbarViewModel | ||
|
||
var body: some View { | ||
ZStack { | ||
Color.red | ||
.ignoresSafeArea() | ||
Text("Go TO CATEGORY VIEW") | ||
.onTapGesture { | ||
viewModel.selected = .category | ||
} | ||
.foregroundStyle(.white) | ||
} | ||
} | ||
} | ||
|
||
struct CategoryView: View { | ||
@EnvironmentObject var router: Router | ||
@EnvironmentObject var viewModel: TabbarViewModel | ||
|
||
var body: some View { | ||
ZStack { | ||
Color.yellow | ||
.ignoresSafeArea() | ||
Text("GO TO MYPAGEVIEW") | ||
.onTapGesture { | ||
viewModel.selected = .mypage | ||
} | ||
} | ||
} | ||
} | ||
|
||
struct MypageView: View { | ||
@EnvironmentObject var router: Router | ||
@EnvironmentObject var viewModel: TabbarViewModel | ||
|
||
var body: some View { | ||
ZStack { | ||
Color.green | ||
.ignoresSafeArea() | ||
Text("GO TO Another View") | ||
.onTapGesture { | ||
router.replaceNavigationStack(.review) | ||
} | ||
} | ||
} | ||
} | ||
|
||
#Preview { | ||
HomeView() | ||
} |
58 changes: 58 additions & 0 deletions
58
Projects/App/Sources/Presentation/Tabbar+Navigation/Tabbar/Tabbar.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,58 @@ | ||
// | ||
// Tabbar.swift | ||
// DesignSystem | ||
// | ||
// Created by 박서연 on 2024/06/12. | ||
// Copyright © 2024 iOS. All rights reserved. | ||
// | ||
|
||
import SwiftUI | ||
|
||
enum Tabbar: CaseIterable { | ||
case home, category, mypage | ||
|
||
@ViewBuilder | ||
var view: some View { | ||
switch self { | ||
case .home: | ||
HomeView() | ||
case .category: | ||
CategoryView() | ||
case .mypage: | ||
MypageView() | ||
} | ||
} | ||
|
||
var title: String { | ||
switch self { | ||
case .home: | ||
"홈" | ||
case .category: | ||
"키테고리 검색" | ||
case .mypage: | ||
"마이페이지" | ||
} | ||
} | ||
|
||
// var image: Image { | ||
// switch self { | ||
// case .home: | ||
// <#code#> | ||
// case .category: | ||
// <#code#> | ||
// case .mypage: | ||
// <#code#> | ||
// } | ||
// } | ||
|
||
// var image_fill: Image { | ||
// switch self { | ||
// case .home: | ||
// <#code#> | ||
// case .category: | ||
// <#code#> | ||
// case .mypage: | ||
// <#code#> | ||
// } | ||
// } | ||
} |
35 changes: 35 additions & 0 deletions
35
Projects/App/Sources/Presentation/Tabbar+Navigation/Tabbar/TabbarMainView.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,35 @@ | ||
// | ||
// TabbarMainView.swift | ||
// DesignSystem | ||
// | ||
// Created by 박서연 on 2024/06/12. | ||
// Copyright © 2024 iOS. All rights reserved. | ||
// | ||
|
||
import SwiftUI | ||
|
||
struct TabbarMainView: View { | ||
@StateObject public var viewModel = TabbarViewModel() | ||
|
||
var body: some View { | ||
NavigationStack { | ||
TabView(selection: $viewModel.selected) { | ||
ForEach(Tabbar.allCases, id: \.self) { tab in | ||
tab.view | ||
} | ||
.toolbarBackground(.hidden, for: .tabBar) | ||
} | ||
} | ||
.overlay { | ||
VStack { | ||
Spacer() | ||
TabbarView(viewModel: viewModel) | ||
} | ||
} | ||
.environmentObject(viewModel) | ||
} | ||
} | ||
|
||
#Preview { | ||
TabbarMainView() | ||
} |
40 changes: 40 additions & 0 deletions
40
Projects/App/Sources/Presentation/Tabbar+Navigation/Tabbar/TabbarView.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,40 @@ | ||
// | ||
// TabbarView.swift | ||
// DesignSystem | ||
// | ||
// Created by 박서연 on 2024/06/12. | ||
// Copyright © 2024 iOS. All rights reserved. | ||
// | ||
|
||
import SwiftUI | ||
|
||
struct TabbarView: View { | ||
@ObservedObject var viewModel: TabbarViewModel | ||
|
||
var body: some View { | ||
HStack { | ||
ForEach(Tabbar.allCases, id: \.self) { item in | ||
Button { | ||
viewModel.selected = item | ||
} label: { | ||
VStack(spacing: 0) { | ||
Image(systemName: "house") | ||
.frame(width: 39, height: 39) | ||
Text(item.title) | ||
.applyFont(font: .label1) | ||
.foregroundStyle(Color.neutral400) | ||
} | ||
} | ||
.frame(maxWidth: .infinity, alignment: .center) | ||
.padding(.bottom, 10) | ||
.onTapGesture { | ||
viewModel.selected = item | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
#Preview { | ||
TabbarView(viewModel: TabbarViewModel()) | ||
} |
13 changes: 13 additions & 0 deletions
13
Projects/App/Sources/Presentation/Tabbar+Navigation/Tabbar/ViewModel/TabbarViewModel.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,13 @@ | ||
// | ||
// TabbarViewModel.swift | ||
// App | ||
// | ||
// Created by 박서연 on 2024/06/13. | ||
// Copyright © 2024 iOS. All rights reserved. | ||
// | ||
|
||
import SwiftUI | ||
|
||
final class TabbarViewModel: ObservableObject { | ||
@Published var selected: Tabbar = .home | ||
} |