-
-
Notifications
You must be signed in to change notification settings - Fork 15
/
ContainerView.swift
128 lines (121 loc) · 5.26 KB
/
ContainerView.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
import SwiftUI
struct ContainerView: View {
enum Action {
case openScene(AppScene)
case sidebar(SidebarView.Action)
case content(ContentView.Action)
case detail(DetailView.Action)
}
@Environment(\.undoManager) private var undoManager
@ObservedObject private var navigationPublisher = NavigationPublisher()
@Binding private var contentState: ContentStore.State
private let onAction: (Action, UndoManager?) -> Void
private let applicationTriggerSelectionManager: SelectionManager<DetailViewModel.ApplicationTrigger>
private let commandSelectionManager: SelectionManager<CommandViewModel>
private let configSelectionManager: SelectionManager<ConfigurationViewModel>
private let contentSelectionManager: SelectionManager<ContentViewModel>
private let groupsSelectionManager: SelectionManager<GroupViewModel>
private let keyboardShortcutSelectionManager: SelectionManager<KeyShortcut>
private let publisher: ContentPublisher
private let triggerPublisher: TriggerPublisher
private let infoPublisher: InfoPublisher
private let commandPublisher: CommandsPublisher
private var focus: FocusState<AppFocus?>.Binding
init(_ focus: FocusState<AppFocus?>.Binding,
contentState: Binding<ContentStore.State>,
publisher: ContentPublisher,
applicationTriggerSelectionManager: SelectionManager<DetailViewModel.ApplicationTrigger>,
commandSelectionManager: SelectionManager<CommandViewModel>,
configSelectionManager: SelectionManager<ConfigurationViewModel>,
contentSelectionManager: SelectionManager<ContentViewModel>,
groupsSelectionManager: SelectionManager<GroupViewModel>,
keyboardShortcutSelectionManager: SelectionManager<KeyShortcut>,
triggerPublisher: TriggerPublisher,
infoPublisher: InfoPublisher,
commandPublisher: CommandsPublisher,
onAction: @escaping (Action, UndoManager?) -> Void) {
_contentState = contentState
self.focus = focus
self.publisher = publisher
self.applicationTriggerSelectionManager = applicationTriggerSelectionManager
self.commandSelectionManager = commandSelectionManager
self.configSelectionManager = configSelectionManager
self.contentSelectionManager = contentSelectionManager
self.groupsSelectionManager = groupsSelectionManager
self.keyboardShortcutSelectionManager = keyboardShortcutSelectionManager
self.triggerPublisher = triggerPublisher
self.infoPublisher = infoPublisher
self.commandPublisher = commandPublisher
self.onAction = onAction
}
var body: some View {
NavigationSplitView(
columnVisibility: $navigationPublisher.columnVisibility,
sidebar: {
SidebarView(
focus,
configSelectionManager: configSelectionManager,
groupSelectionManager: groupsSelectionManager,
contentSelectionManager: contentSelectionManager,
onAction: { onAction(.sidebar($0), undoManager) })
.onChange(of: contentState, perform: { newValue in
guard newValue == .initialized else { return }
guard let groupId = groupsSelectionManager.lastSelection else { return }
onAction(.sidebar(.selectGroups([groupId])), undoManager)
})
.opacity(contentState == .initialized ? 1 : 0)
.frame(height: contentState == .initialized ? nil : 0)
.navigationSplitViewColumnWidth(ideal: 250)
},
content: {
ContentView(
focus,
groupId: groupsSelectionManager.lastSelection ?? groupsSelectionManager.selections.first ?? "empty",
contentSelectionManager: contentSelectionManager,
onAction: {
onAction(.content($0), undoManager)
if case .addWorkflow = $0 {
Task { @MainActor in focus.wrappedValue = .detail(.name) }
}
})
.opacity(contentState == .initialized ? 1 : 0)
.navigationSplitViewColumnWidth(min: 180, ideal: 250)
},
detail: {
DetailView(
focus,
applicationTriggerSelectionManager: applicationTriggerSelectionManager,
commandSelectionManager: commandSelectionManager,
keyboardShortcutSelectionManager: keyboardShortcutSelectionManager,
triggerPublisher: triggerPublisher,
infoPublisher: infoPublisher,
commandPublisher: commandPublisher,
onAction: { onAction(.detail($0), undoManager) })
.opacity(contentState == .initialized ? 1 : 0)
.frame(minHeight: 400)
.navigationSplitViewColumnWidth(min: 350, ideal: 400)
})
.navigationSplitViewStyle(.balanced)
}
}
struct ContainerView_Previews: PreviewProvider {
@FocusState static var focus: AppFocus?
static var previews: some View {
ContainerView(
$focus,
contentState: .readonly(.initialized),
publisher: DesignTime.contentPublisher,
applicationTriggerSelectionManager: .init(),
commandSelectionManager: .init(),
configSelectionManager: .init(),
contentSelectionManager: .init(),
groupsSelectionManager: .init(),
keyboardShortcutSelectionManager: .init(),
triggerPublisher: DesignTime.triggerPublisher,
infoPublisher: DesignTime.infoPublisher,
commandPublisher: DesignTime.commandsPublisher
) { _, _ in }
.designTime()
.frame(height: 800)
}
}