Skip to content

Commit 56be310

Browse files
committed
refactor: FullScreenCoverState 적용
1 parent 9a4564d commit 56be310

3 files changed

Lines changed: 42 additions & 19 deletions

File tree

Application/DevLogPresentation/Sources/Home/Home/HomeFeature+Effects.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -150,14 +150,14 @@ extension HomeFeature {
150150
case .reorderTodo:
151151
state.sheet = isPresented ? .reorderTodo : state.sheet == .reorderTodo ? nil : state.sheet
152152
case .todoEditor:
153-
state.showTodoEditor = isPresented
153+
state.fullScreenCover = isPresented ? state.selectedTodoCategory.map(FullScreenCoverState.todoEditor) : nil
154154
if !isPresented {
155155
state.selectedTodoCategory = nil
156156
}
157157
case .contentPicker:
158158
state.sheet = isPresented ? .contentPicker : state.showContentPicker ? nil : state.sheet
159159
case .searchView:
160-
state.showSearchView = isPresented
160+
state.fullScreenCover = isPresented ? .search : nil
161161
}
162162
}
163163

Application/DevLogPresentation/Sources/Home/Home/HomeFeature.swift

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,21 +16,22 @@ struct HomeFeature {
1616
struct State: Equatable {
1717
@Presents var alert: AlertState<Never>?
1818
@Presents var sheet: SheetState?
19+
@Presents var fullScreenCover: FullScreenCoverState?
1920
@Presents var webPageInput: WebPageInputState?
2021
var preferences = [TodoCategoryItem]()
2122
var recentTodos = [RecentTodoItem]()
2223
var webPages = [WebPageItem]()
2324
var needsWebPageRefresh = false
2425
var isNetworkConnected = true
25-
var showTodoEditor = false
26-
var showSearchView = false
2726
var webPageURLInput = "https://"
2827
var selectedTodoCategory: TodoCategory?
2928
var deletedWebPageURLString: String?
3029
var loading = LoadingFeature.State()
3130

3231
var showContentPicker: Bool { sheet == .contentPicker }
3332
var reorderTodo: Bool { sheet == .reorderTodo }
33+
var showTodoEditor: Bool { fullScreenCover?.destination == .todoEditor }
34+
var showSearchView: Bool { fullScreenCover?.destination == .search }
3435

3536
var isPreferencesLoading: Bool {
3637
loading.visibleTargets.contains(LoadingTarget.preferences.target)
@@ -52,6 +53,7 @@ struct HomeFeature {
5253
enum Action: Equatable {
5354
case alert(PresentationAction<Never>)
5455
case sheet(PresentationAction<Sheet>)
56+
case fullScreenCover(PresentationAction<Never>)
5557
case webPageInput(PresentationAction<Never>)
5658
case startObserving
5759
case fetchData
@@ -91,6 +93,23 @@ struct HomeFeature {
9193
let id = UUID()
9294
}
9395

96+
@ObservableState
97+
struct FullScreenCoverState: Equatable {
98+
var destination: Destination
99+
var selectedTodoCategory: TodoCategory?
100+
101+
enum Destination: Equatable {
102+
case todoEditor
103+
case search
104+
}
105+
106+
static func todoEditor(_ category: TodoCategory) -> Self {
107+
Self(destination: .todoEditor, selectedTodoCategory: category)
108+
}
109+
110+
static let search = Self(destination: .search)
111+
}
112+
94113
@ObservableState
95114
@CasePathable
96115
enum SheetState: Equatable {
@@ -152,6 +171,11 @@ struct HomeFeature {
152171
switch action {
153172
case .alert:
154173
break
174+
case .fullScreenCover(.dismiss):
175+
state.fullScreenCover = nil
176+
state.selectedTodoCategory = nil
177+
case .fullScreenCover:
178+
break
155179
case .webPageInput(.dismiss):
156180
state.webPageInput = nil
157181
case .webPageInput:

Application/DevLogPresentation/Sources/Home/Home/HomeView.swift

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,19 @@ struct HomeView: View {
3737
.toolbar { toolbar }
3838
.alert($store.scope(state: \.alert, action: \.alert))
3939
.sheet(item: $store.scope(state: \.sheet, action: \.sheet), content: sheetContent)
40-
.fullScreenCover(isPresented: Binding(
41-
get: { store.showTodoEditor },
42-
set: { store.send(.setPresentation(.todoEditor, $0)) }
43-
)) {
44-
if let selectedCategory = store.selectedTodoCategory {
40+
.fullScreenCover(item: $store.scope(state: \.fullScreenCover, action: \.fullScreenCover), content: coverContent)
41+
.overlay {
42+
if store.isAppending {
43+
LoadingView()
44+
}
45+
}
46+
}
47+
48+
@ViewBuilder
49+
private func coverContent(_ coverStore: Store<HomeFeature.FullScreenCoverState, Never>) -> some View {
50+
switch coverStore.destination {
51+
case .todoEditor:
52+
if let selectedCategory = coverStore.selectedTodoCategory {
4553
TodoEditorView(
4654
store: coordinator.makeTodoEditorStore(category: selectedCategory),
4755
onCreateSuccess: {
@@ -50,18 +58,9 @@ struct HomeView: View {
5058
}
5159
)
5260
}
53-
}
54-
.fullScreenCover(isPresented: Binding(
55-
get: { store.showSearchView },
56-
set: { store.send(.setPresentation(.searchView, $0)) }
57-
)) {
61+
case .search:
5862
SearchView(store: coordinator.makeSearchStore())
5963
}
60-
.overlay {
61-
if store.isAppending {
62-
LoadingView()
63-
}
64-
}
6564
}
6665

6766
@ViewBuilder

0 commit comments

Comments
 (0)