From bdb7eb2b7c7ebcf37a5f08d6f42aef6d7403fadd Mon Sep 17 00:00:00 2001 From: jeongwookim <112370814+JeongWo@users.noreply.github.com> Date: Sun, 27 Oct 2024 14:56:25 +0900 Subject: [PATCH] =?UTF-8?q?Fix:=20PhotoImporting,=20CustomTabView=20DIcont?= =?UTF-8?q?ainer=20=EC=A0=81=EC=9A=A9=20=EB=B0=8F=20EnvironmentObject=20?= =?UTF-8?q?=EC=9D=98=EC=A1=B4=EC=84=B1=EC=9D=84=20StateObject.ObservaedObj?= =?UTF-8?q?ect=EB=A1=9C=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Kabinett/Application/KabinettApp.swift | 16 ------- .../Commons/CustomTabView/CustomTabBar.swift | 4 +- .../Commons/CustomTabView/CustomTabView.swift | 42 ++++++++++++------- .../PhotoImporting/ImagePreview.swift | 23 ++++++++-- .../PhotoImporting/LetterWritingView.swift | 6 +-- 5 files changed, 51 insertions(+), 40 deletions(-) diff --git a/Kabinett/Application/KabinettApp.swift b/Kabinett/Application/KabinettApp.swift index a9d184b..5e35285 100644 --- a/Kabinett/Application/KabinettApp.swift +++ b/Kabinett/Application/KabinettApp.swift @@ -25,10 +25,6 @@ struct KabinettApp: App { // MARK: - SignUp Flow @StateObject private var signUpViewModel: SignUpViewModel - // MARK: - Componets Flow - @StateObject private var imagePickerViewModel: ImagePickerViewModel - @StateObject private var customTabViewModel: CustomTabViewModel - // MARK: - LetterWrite Flow @StateObject private var userSelectionViewModel: UserSelectionViewModel @StateObject private var stationerySelectionViewModel: StationerySelectionViewModel @@ -127,16 +123,6 @@ struct KabinettApp: App { ) ) - // MARK: - Componets ViewModels - _imagePickerViewModel = .init( - wrappedValue: ImagePickerViewModel( - componentsUseCase: photoLetterUseCase - ) - ) - _customTabViewModel = .init( - wrappedValue: CustomTabViewModel() - ) - // MARK: - LetterWrite ViewModels _userSelectionViewModel = .init( wrappedValue: UserSelectionViewModel( @@ -175,8 +161,6 @@ struct KabinettApp: App { .environmentObject(calendarViewModel) .environmentObject(profileViewModel) .environmentObject(signUpViewModel) - .environmentObject(imagePickerViewModel) - .environmentObject(customTabViewModel) .environmentObject(userSelectionViewModel) .environmentObject(stationerySelectionViewModel) .environmentObject(fontSelectionViewModel) diff --git a/Kabinett/Presentation/Commons/CustomTabView/CustomTabBar.swift b/Kabinett/Presentation/Commons/CustomTabView/CustomTabBar.swift index 6e76743..8e63715 100644 --- a/Kabinett/Presentation/Commons/CustomTabView/CustomTabBar.swift +++ b/Kabinett/Presentation/Commons/CustomTabView/CustomTabBar.swift @@ -9,8 +9,8 @@ import SwiftUI import Kingfisher struct CustomTabBar: View { - @EnvironmentObject var viewModel: CustomTabViewModel - @EnvironmentObject var profileViewModel: ProfileViewModel + @ObservedObject var viewModel: CustomTabViewModel + @ObservedObject var profileViewModel: ProfileViewModel var body: some View { GeometryReader { geometry in diff --git a/Kabinett/Presentation/Commons/CustomTabView/CustomTabView.swift b/Kabinett/Presentation/Commons/CustomTabView/CustomTabView.swift index bfb7356..9b53f2b 100644 --- a/Kabinett/Presentation/Commons/CustomTabView/CustomTabView.swift +++ b/Kabinett/Presentation/Commons/CustomTabView/CustomTabView.swift @@ -9,16 +9,24 @@ import SwiftUI import PhotosUI struct CustomTabView: View { - @EnvironmentObject var viewModel: CustomTabViewModel - @EnvironmentObject var imagePickerViewModel: ImagePickerViewModel - @EnvironmentObject var letterBoxViewModel: LetterBoxViewModel - @EnvironmentObject var calendarViewModel: CalendarViewModel + @StateObject private var customTabViewModel: CustomTabViewModel + @StateObject private var calendarViewModel: CalendarViewModel + @StateObject private var profileViewModel: ProfileViewModel @State private var letterWriteViewModel = LetterWriteModel() + init() { + @Injected(LetterBoxUseCaseKey.self) var letterBoxUseCase: LetterBoxUseCase + @Injected(ProfileUseCaseKey.self) var profileUseCase: ProfileUseCase + + self._customTabViewModel = StateObject(wrappedValue: CustomTabViewModel()) + self._calendarViewModel = StateObject(wrappedValue: CalendarViewModel()) + self._profileViewModel = StateObject(wrappedValue: ProfileViewModel(profileUseCase: profileUseCase)) + } + var body: some View { ZStack(alignment: .bottom) { - TabView(selection: $viewModel.selectedTab) { + TabView(selection: $customTabViewModel.selectedTab) { LetterBoxView() .tag(0) @@ -28,23 +36,29 @@ struct CustomTabView: View { ProfileView() .tag(2) } - .overlay(CustomTabBar(viewModel: _viewModel), alignment: .bottom) + .overlay( + CustomTabBar( + viewModel: customTabViewModel, + profileViewModel: profileViewModel + ), + alignment: .bottom + ) } .ignoresSafeArea(.keyboard, edges: .bottom) .onAppear { - viewModel.setupTabBarAppearance() + customTabViewModel.setupTabBarAppearance() } - .onChange(of: viewModel.selectedTab) { oldValue, newValue in + .onChange(of: customTabViewModel.selectedTab) { oldValue, newValue in if newValue == 1 { withAnimation { - viewModel.showOptions = true + customTabViewModel.showOptions = true } - viewModel.selectedTab = oldValue + customTabViewModel.selectedTab = oldValue } } .overlay( Group { - if viewModel.showOptions { + if customTabViewModel.showOptions { OptionOverlay() } CalendarOverlayView() @@ -52,13 +66,11 @@ struct CustomTabView: View { ) .overlay(ImportDialog()) .overlay(ImagePickerView()) - .fullScreenCover(isPresented: $viewModel.showCamera) { + .fullScreenCover(isPresented: $customTabViewModel.showCamera) { CameraView() } - .sheet(isPresented: $viewModel.showWriteLetterView) { + .sheet(isPresented: $customTabViewModel.showWriteLetterView) { ContentWriteView(letterContent: $letterWriteViewModel) } - .environmentObject(viewModel) - .environmentObject(imagePickerViewModel) } } diff --git a/Kabinett/Presentation/View/ImportLetter/PhotoImporting/ImagePreview.swift b/Kabinett/Presentation/View/ImportLetter/PhotoImporting/ImagePreview.swift index 0349d0b..79b820c 100644 --- a/Kabinett/Presentation/View/ImportLetter/PhotoImporting/ImagePreview.swift +++ b/Kabinett/Presentation/View/ImportLetter/PhotoImporting/ImagePreview.swift @@ -8,15 +8,24 @@ import SwiftUI struct ImagePreview: View { - @EnvironmentObject var customViewModel: CustomTabViewModel - @EnvironmentObject var imageViewModel: ImagePickerViewModel - @EnvironmentObject var envelopeStampSelectionViewModel: EnvelopeStampSelectionViewModel + @StateObject private var imageViewModel: ImagePickerViewModel + @StateObject private var customViewModel: CustomTabViewModel + @StateObject private var envelopeStampSelectionViewModel: EnvelopeStampSelectionViewModel @Environment(\.dismiss) var dismiss @State private var showDetailView = false @State private var showLetterWritingView = false @State private var navigateToEnvelopeStamp = false @State private var letterContent = LetterWriteModel() + init() { + @Injected(ImportLetterUseCaseKey.self) var importLetterUseCase: ImportLetterUseCase + @Injected(WriteLetterUseCaseKey.self) var writeLetterUseCase: WriteLetterUseCase + + self._imageViewModel = StateObject(wrappedValue: ImagePickerViewModel(componentsUseCase: importLetterUseCase)) + self._customViewModel = StateObject(wrappedValue: CustomTabViewModel()) + self._envelopeStampSelectionViewModel = StateObject(wrappedValue: EnvelopeStampSelectionViewModel(useCase: writeLetterUseCase)) + } + var body: some View { NavigationStack { ZStack { @@ -59,7 +68,13 @@ struct ImagePreview: View { ImageDetailView(images: imageViewModel.photoContents, showDetailView: $showDetailView) } .sheet(isPresented: $showLetterWritingView) { - LetterWritingView(letterContent: $letterContent, showEnvelopeStamp: $navigateToEnvelopeStamp) + LetterWritingView( + viewModel: imageViewModel, + customViewModel: customViewModel, + envelopeStampViewModel: envelopeStampSelectionViewModel, + letterContent: $letterContent, + showEnvelopeStamp: $navigateToEnvelopeStamp + ) } .background(Color.background.edgesIgnoringSafeArea(.all)) .navigationDestination(isPresented: $navigateToEnvelopeStamp) { diff --git a/Kabinett/Presentation/View/ImportLetter/PhotoImporting/LetterWritingView.swift b/Kabinett/Presentation/View/ImportLetter/PhotoImporting/LetterWritingView.swift index 1610078..2db50d3 100644 --- a/Kabinett/Presentation/View/ImportLetter/PhotoImporting/LetterWritingView.swift +++ b/Kabinett/Presentation/View/ImportLetter/PhotoImporting/LetterWritingView.swift @@ -8,9 +8,9 @@ import SwiftUI struct LetterWritingView: View { - @EnvironmentObject var viewModel: ImagePickerViewModel - @EnvironmentObject var customViewModel: CustomTabViewModel - @EnvironmentObject var envelopeStampSelectionViewModel: EnvelopeStampSelectionViewModel + @ObservedObject var viewModel: ImagePickerViewModel + @ObservedObject var customViewModel: CustomTabViewModel + @ObservedObject var envelopeStampViewModel: EnvelopeStampSelectionViewModel @Environment(\.dismiss) var dismiss @Binding var letterContent: LetterWriteModel @Binding var showEnvelopeStamp: Bool