Skip to content

Commit

Permalink
Merge pull request #231 from APP-iOS5th/Feature/DILetterBoxView
Browse files Browse the repository at this point in the history
Feature: LetterBoxView 내 DIContainer 적용
  • Loading branch information
jinwoong16 authored Nov 2, 2024
2 parents 880eeaf + 1b643b0 commit 3a55b22
Show file tree
Hide file tree
Showing 10 changed files with 41 additions and 59 deletions.
34 changes: 0 additions & 34 deletions Kabinett/Application/KabinettApp.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,6 @@ import FirebaseFirestore

@main
struct KabinettApp: App {
// MARK: - LetterBox Flow
@StateObject private var letterViewModel: LetterViewModel
@StateObject private var letterBoxViewModel: LetterBoxViewModel
@StateObject private var letterBoxDetailViewModel: LetterBoxDetailViewModel
@StateObject private var calendarViewModel: CalendarViewModel

// MARK: - Profile Flow
@StateObject private var profileViewModel: ProfileViewModel

Expand Down Expand Up @@ -88,30 +82,6 @@ struct KabinettApp: App {
letterManager: letterManager,
letterStorageManager: letterStorageManager
)
let letterboxUseCase = DefaultLetterBoxUseCase(
letterManager: letterManager,
authManager: authManager
)

// MARK: - LetterBox ViewModels
_letterViewModel = .init(
wrappedValue: LetterViewModel(
letterBoxUseCase: letterboxUseCase
)
)
_letterBoxViewModel = .init(
wrappedValue: LetterBoxViewModel(
letterBoxUseCase: letterboxUseCase
)
)
_letterBoxDetailViewModel = .init(
wrappedValue: LetterBoxDetailViewModel(
letterBoxUseCase: letterboxUseCase
)
)
_calendarViewModel = .init(
wrappedValue: CalendarViewModel()
)

// MARK: - Profile ViewModel
_profileViewModel = .init(
Expand Down Expand Up @@ -169,10 +139,6 @@ struct KabinettApp: App {
var body: some Scene {
WindowGroup {
CustomTabView()
.environmentObject(letterViewModel)
.environmentObject(letterBoxViewModel)
.environmentObject(letterBoxDetailViewModel)
.environmentObject(calendarViewModel)
.environmentObject(profileViewModel)
.environmentObject(signUpViewModel)
.environmentObject(imagePickerViewModel)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ import PhotosUI
struct CustomTabView: View {
@EnvironmentObject var viewModel: CustomTabViewModel
@EnvironmentObject var imagePickerViewModel: ImagePickerViewModel
@EnvironmentObject var letterBoxViewModel: LetterBoxViewModel
@EnvironmentObject var calendarViewModel: CalendarViewModel

@State private var letterWriteViewModel = LetterWriteModel()

Expand Down Expand Up @@ -47,7 +45,6 @@ struct CustomTabView: View {
if viewModel.showOptions {
OptionOverlay()
}
CalendarOverlayView()
}
)
.overlay(ImportDialog())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import SwiftUI

struct LetterBoxCell: View {
@EnvironmentObject var viewModel: LetterBoxViewModel
@ObservedObject var viewModel: LetterBoxViewModel

var type: LetterType
var unreadCount: Int
Expand Down Expand Up @@ -74,6 +74,5 @@ struct LetterBoxCell: View {
}

#Preview {
LetterBoxCell(type: .all, unreadCount: 1)
.environmentObject(LetterBoxViewModel(letterBoxUseCase: LetterBoxUseCaseStub()))
LetterBoxCell(viewModel: LetterBoxViewModel(letterBoxUseCase: LetterBoxUseCaseStub()), type: .all, unreadCount: 1)
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import SwiftUI
import Kingfisher

struct SmallEnvelopeCell: View {
@EnvironmentObject var fontViewModel: FontSelectionViewModel
@StateObject private var fontViewModel = FontSelectionViewModel()
var letter: Letter

var body: some View {
Expand Down Expand Up @@ -64,7 +64,7 @@ struct SmallEnvelopeCell: View {
}

struct LargeEnvelopeCell: View {
@EnvironmentObject var fontViewModel: FontSelectionViewModel
@StateObject private var fontViewModel = FontSelectionViewModel()
var letter: Letter

var body: some View {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
import SwiftUI

struct CalendarView: View {
@EnvironmentObject var letterBoxDetailviewModel: LetterBoxDetailViewModel
@EnvironmentObject var calendarViewModel: CalendarViewModel
@ObservedObject var letterBoxDetailviewModel: LetterBoxDetailViewModel
@ObservedObject var calendarViewModel: CalendarViewModel

@State private var selectedStartDate = Date()
@State private var selectedEndDate = Date()
Expand Down Expand Up @@ -171,7 +171,8 @@ struct CalendarView: View {
}

struct CalendarOverlayView: View {
@EnvironmentObject var calendarViewModel: CalendarViewModel
@ObservedObject var letterBoxDetailViewModel: LetterBoxDetailViewModel
@ObservedObject var calendarViewModel: CalendarViewModel

var body: some View {
if calendarViewModel.showCalendarView {
Expand All @@ -184,7 +185,8 @@ struct CalendarOverlayView: View {
}
}

CalendarView()
CalendarView(letterBoxDetailviewModel: letterBoxDetailViewModel,
calendarViewModel: calendarViewModel)
.cornerRadius(20)
.padding(.top, 32)
}
Expand All @@ -193,8 +195,8 @@ struct CalendarOverlayView: View {
}

struct CalendarBar: View {
@EnvironmentObject var letterBoxDetailviewModel: LetterBoxDetailViewModel
@EnvironmentObject var calendarViewModel: CalendarViewModel
@ObservedObject var letterBoxDetailviewModel: LetterBoxDetailViewModel
@ObservedObject var calendarViewModel: CalendarViewModel

var body: some View {
VStack {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import SwiftUI
import Kingfisher

struct ContentRectangleView: View {
@EnvironmentObject var fontViewModel: FontSelectionViewModel
@StateObject var fontViewModel = FontSelectionViewModel()

var stationeryImageUrlString: String?
var fromUserName: String
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import SwiftUI

struct SearchBarView: View {
@EnvironmentObject var viewModel: LetterBoxDetailViewModel
@ObservedObject var viewModel: LetterBoxDetailViewModel

@Binding var searchText: String
@Binding var showSearchBarView: Bool
Expand Down
18 changes: 14 additions & 4 deletions Kabinett/Presentation/View/LetterBox/LetterBoxDetailView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import SwiftUI
import UIKit

struct LetterBoxDetailView: View {
@EnvironmentObject var viewModel: LetterBoxDetailViewModel
@EnvironmentObject var calendarViewModel: CalendarViewModel
@StateObject var viewModel: LetterBoxDetailViewModel
@ObservedObject var calendarViewModel: CalendarViewModel

@State private var navigationBarHeight: CGFloat = 0
@State private var calendarBarHeight: CGFloat = 0
Expand All @@ -23,14 +23,21 @@ struct LetterBoxDetailView: View {
return [-8, 10, 6, -2, 16]
}

init(calendarViewModel: CalendarViewModel) {
@Injected(LetterBoxUseCaseKey.self) var letterBoxUseCase: LetterBoxUseCase
_viewModel = StateObject(wrappedValue: LetterBoxDetailViewModel(letterBoxUseCase: letterBoxUseCase))

self.calendarViewModel = calendarViewModel
}

var body: some View {
ZStack {
Color.background
.ignoresSafeArea()

VStack {
if showSearchBarView {
SearchBarView(searchText: $searchText, showSearchBarView: $showSearchBarView, isTextFieldFocused: $isTextFieldFocused, letterType: calendarViewModel.currentLetterType)
SearchBarView(viewModel: viewModel, searchText: $searchText, showSearchBarView: $showSearchBarView, isTextFieldFocused: $isTextFieldFocused, letterType: calendarViewModel.currentLetterType)
} else {
NavigationBarView(titleName: calendarViewModel.currentLetterType.description, isColor: false, toolbarContent: {
toolbarItems()
Expand All @@ -52,7 +59,7 @@ struct LetterBoxDetailView: View {
}

if calendarViewModel.startDateFiltering {
CalendarBar()
CalendarBar(letterBoxDetailviewModel: viewModel, calendarViewModel: calendarViewModel)
.background(
GeometryReader { geo in
Color.clear
Expand Down Expand Up @@ -96,6 +103,9 @@ struct LetterBoxDetailView: View {
showSearchBarView.toggle()
}
})
.overlay(
CalendarOverlayView(letterBoxDetailViewModel: viewModel, calendarViewModel: calendarViewModel)
)
.navigationBarBackButtonHidden()
.ignoresSafeArea(.keyboard, edges: .bottom)
.onAppear {
Expand Down
13 changes: 9 additions & 4 deletions Kabinett/Presentation/View/LetterBox/LetterBoxView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,13 @@ import SwiftUI
struct LetterBoxView: View {
@AppStorage("isFirstLaunch") private var isFirstLaunch: Bool = true

@EnvironmentObject var letterBoxViewModel: LetterBoxViewModel
@EnvironmentObject var calendarViewModel: CalendarViewModel
@StateObject private var letterBoxViewModel: LetterBoxViewModel
@StateObject private var calendarViewModel = CalendarViewModel()

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

var body: some View {
NavigationStack {
Expand All @@ -23,8 +28,8 @@ struct LetterBoxView: View {
ForEach(LetterType.allCases, id: \.self) { type in
let unreadCount = letterBoxViewModel.getIsReadLetters(for: type)

NavigationLink(destination: LetterBoxDetailView()) {
LetterBoxCell(type: type, unreadCount: unreadCount)
NavigationLink(destination: LetterBoxDetailView(calendarViewModel: calendarViewModel)) {
LetterBoxCell(viewModel: letterBoxViewModel, type: type, unreadCount: unreadCount)
}
.simultaneousGesture(TapGesture().onEnded {
calendarViewModel.currentLetterType = type
Expand Down
5 changes: 4 additions & 1 deletion Kabinett/Presentation/View/LetterBox/LetterView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import SwiftUI

struct LetterView: View {
@EnvironmentObject var viewModel: LetterViewModel
@StateObject var viewModel: LetterViewModel

@State private var showDetailLetter = false

Expand All @@ -21,6 +21,9 @@ struct LetterView: View {
@Environment(\.dismiss) private var dismiss

init(letterType: LetterType, letter: Letter) {
@Injected(LetterBoxUseCaseKey.self) var letterBoxUseCase: LetterBoxUseCase
_viewModel = StateObject(wrappedValue: LetterViewModel(letterBoxUseCase: letterBoxUseCase))

self.letterType = letterType
_letter = State(initialValue: letter)
}
Expand Down

0 comments on commit 3a55b22

Please sign in to comment.