Skip to content
Merged
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 @@ -30,13 +30,13 @@ struct CustomTabView: View {
var body: some View {
ZStack(alignment: .bottom) {
TabView(selection: $customTabViewModel.selectedTab) {
LetterBoxView()
LetterBoxView(customTabViewModel: customTabViewModel)
.tag(0)

Color.clear
.tag(1)

ProfileView()
ProfileView(customTabViewModel: customTabViewModel)
.tag(2)
}
.overlay(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ final class CustomTabViewModel: ObservableObject {
@Published var isLetterWrite: Bool = false
@Published var previousTab: Int?

static let profileTabTappedNotification = Notification.Name("profileTabTapped")
static let resetProfileNavigationNotification = Notification.Name("resetProfileNavigation")

private var lastTabSelectionTime: Date?
private let doubleTapInterval: TimeInterval = 0.2
Expand Down Expand Up @@ -50,30 +50,24 @@ final class CustomTabViewModel: ObservableObject {
}

func handleTabSelection(_ tab: Int) {
if tab == selectedTab {
if tab == 2 {
NotificationCenter.default.post(name: CustomTabViewModel.profileTabTappedNotification, object: nil)
}
if tab == 0 {
letterBoxNavigationPath.removeLast(letterBoxNavigationPath.count)
}
} else if tab == 1 {
withAnimation(.easeInOut(duration: 0.3)) {
showOptions = true
}
} else {
selectedTab = tab
if tab == selectedTab {
if tab == 2 {
NotificationCenter.default.post(name: CustomTabViewModel.resetProfileNavigationNotification, object: nil)
}
if tab == 0 {
letterBoxNavigationPath.removeLast(letterBoxNavigationPath.count)
}
} else if tab == 1 {
withAnimation(.easeInOut(duration: 0.3)) {
showOptions = true
}
} else {
selectedTab = tab
if tab == 0 {
letterBoxNavigationPath.removeLast(letterBoxNavigationPath.count)
} else if tab == 2 {
profileNavigationPath.removeLast(profileNavigationPath.count)
}
}

private func resetNavigationForTab(_ tab: Int) {
switch tab {
case 0:
letterBoxNavigationPath.removeLast(letterBoxNavigationPath.count)
case 2:
profileNavigationPath.removeLast(profileNavigationPath.count)
default:
break
}
}

Expand Down
16 changes: 13 additions & 3 deletions Kabinett/Presentation/View/LetterBox/LetterBoxView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,11 @@ struct LetterBoxView: View {
@StateObject private var calendarViewModel = CalendarViewModel()
@StateObject private var searchBarViewModel = SearchBarViewModel()

init() {
@ObservedObject var customTabViewModel: CustomTabViewModel

init(customTabViewModel: CustomTabViewModel) {
self.customTabViewModel = customTabViewModel

@Injected(LetterBoxUseCaseKey.self) var letterBoxUseCase: LetterBoxUseCase
_letterBoxViewModel = StateObject(wrappedValue: LetterBoxViewModel(letterBoxUseCase: letterBoxUseCase))

Expand All @@ -25,7 +29,7 @@ struct LetterBoxView: View {

var body: some View {
ZStack {
NavigationStack {
NavigationStack(path: $customTabViewModel.letterBoxNavigationPath) {
ZStack {
Color.background
.ignoresSafeArea()
Expand All @@ -34,7 +38,7 @@ struct LetterBoxView: View {
ForEach(LetterType.allCases, id: \.self) { type in
let unreadCount = letterBoxViewModel.getIsReadLetters(for: type)

NavigationLink(destination: LetterBoxDetailView(viewModel: letterBoxDetailViewModel, calendarViewModel: calendarViewModel, searchBarViewModel: searchBarViewModel)) {
NavigationLink(value: type) {
LetterBoxCell(viewModel: letterBoxViewModel, type: type, unreadCount: unreadCount)
}
.simultaneousGesture(TapGesture().onEnded {
Expand All @@ -43,6 +47,12 @@ struct LetterBoxView: View {
}
}
.padding(.top, LayoutHelper.shared.getSize(forSE: 0.035, forOthers: 0.035))
.navigationDestination(for: LetterType.self) { type in
LetterBoxDetailView(viewModel: letterBoxDetailViewModel, calendarViewModel: calendarViewModel, searchBarViewModel: searchBarViewModel)
.onAppear {
letterBoxDetailViewModel.currentLetterType = type
}
}

VStack {
Spacer()
Expand Down
24 changes: 15 additions & 9 deletions Kabinett/Presentation/View/Profile/ProfileView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,11 @@ import Kingfisher
struct ProfileView: View {
//
@StateObject private var viewModel: ProfileViewModel
@ObservedObject var customTabViewModel: CustomTabViewModel

init() {
init(customTabViewModel: CustomTabViewModel) {
self.customTabViewModel = customTabViewModel

@Injected(ProfileUseCaseKey.self)
var profileUseCase: ProfileUseCase

Expand All @@ -23,21 +26,21 @@ struct ProfileView: View {
}

var body: some View {
NavigationStack {
NavigationStack(path: $customTabViewModel.profileNavigationPath) {
Group {
if case .toLogin = viewModel.navigateState {
SignUpView()
} else {
ZStack {
Color.background.ignoresSafeArea(.all)
if viewModel.profileUpdateError != nil {
// VStack {
// Text("ํ”„๋กœํ•„์„ ๋ถˆ๋Ÿฌ์˜ค๋Š” ๋ฐ ๋ฌธ์ œ๊ฐ€ ๋ฐœ์ƒํ–ˆ์–ด์š”.")
// .fontWeight(.regular)
// .foregroundColor(.alert)
// .font(.headline)
// .padding()
// }
// VStack {
// Text("ํ”„๋กœํ•„์„ ๋ถˆ๋Ÿฌ์˜ค๋Š” ๋ฐ ๋ฌธ์ œ๊ฐ€ ๋ฐœ์ƒํ–ˆ์–ด์š”.")
// .fontWeight(.regular)
// .foregroundColor(.alert)
// .font(.headline)
// .padding()
// }
} else {
VStack {
if let image = viewModel.currentWriter.imageUrlString {
Expand Down Expand Up @@ -95,5 +98,8 @@ struct ProfileView: View {
SettingsView(viewModel: viewModel)
}
}
.onReceive(NotificationCenter.default.publisher(for: CustomTabViewModel.resetProfileNavigationNotification)) { _ in
viewModel.showSettingsView = false
}
}
}