Skip to content

Commit

Permalink
Merge pull request #238 from APP-iOS5th/ImportLetterDIContainer
Browse files Browse the repository at this point in the history
Fix: PhotoImporting, CustomTabView DIcontainer 적용 및 EnvironmentObject…
  • Loading branch information
jinwoong16 authored Nov 2, 2024
2 parents 9299344 + c37d3b2 commit e29c14d
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 39 deletions.
16 changes: 0 additions & 16 deletions Kabinett/Application/KabinettApp.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,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

init() {
// Init Firebase App
FirebaseApp.configure()
Expand Down Expand Up @@ -88,25 +84,13 @@ struct KabinettApp: App {
signUpUseCase: signUpUseCase
)
)

// MARK: - Componets ViewModels
_imagePickerViewModel = .init(
wrappedValue: ImagePickerViewModel(
componentsUseCase: photoLetterUseCase
)
)
_customTabViewModel = .init(
wrappedValue: CustomTabViewModel()
)
}

var body: some Scene {
WindowGroup {
CustomTabView()
.environmentObject(profileViewModel)
.environmentObject(signUpViewModel)
.environmentObject(imagePickerViewModel)
.environmentObject(customTabViewModel)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
41 changes: 27 additions & 14 deletions Kabinett/Presentation/Commons/CustomTabView/CustomTabView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,23 @@ import SwiftUI
import PhotosUI

struct CustomTabView: View {
@EnvironmentObject var viewModel: CustomTabViewModel
@EnvironmentObject var imagePickerViewModel: ImagePickerViewModel

@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)

Expand All @@ -26,36 +35,40 @@ 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()
}
}
)
.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)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit e29c14d

Please sign in to comment.