-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMainPortrait.swift
More file actions
108 lines (95 loc) · 3.58 KB
/
MainPortrait.swift
File metadata and controls
108 lines (95 loc) · 3.58 KB
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
//
// MainPortrait.swift
//
// Copyright 2023 OpenAlloc LLC
//
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at https://mozilla.org/MPL/2.0/.
//
import os
import SwiftUI
import TrackerUI
import TroutLib
import TroutUI
enum PortraitTab: String {
case routines
case history
case settings
}
let tabbedViewSelectedTabKey = "main-tab-str"
struct MainPortrait: View {
@Environment(\.managedObjectContext) private var viewContext
@EnvironmentObject private var manager: CoreDataStack
@SceneStorage(tabbedViewSelectedTabKey) private var selectedTab = PortraitTab.routines.rawValue
@SceneStorage(mainNavDataMRoutineKey) private var routinesNavData: Data?
@SceneStorage(mainNavDataHistoryKey) private var historyNavData: Data?
@SceneStorage(mainNavDataSettingKey) private var settingsNavData: Data?
// NOTE: this proxy is duplicated in Gym MRoutine Tracker Plus's ContentView.
// QUESTION: can this be moved to TrackerUI somehow?
private var selectedProxy: Binding<String> {
Binding(get: { selectedTab },
set: { nuTab in
if nuTab != selectedTab {
selectedTab = nuTab
} else {
NotificationCenter.default.post(name: .trackerPopNavStack,
object: nuTab)
}
})
}
var body: some View {
TabView(selection: selectedProxy) {
TroutNavStack(navData: $routinesNavData,
stackIdentifier: PortraitTab.routines.rawValue,
destination: destination)
{
MRoutineList()
}
.tabItem {
Label("Task Routines", systemImage: "wrench.and.screwdriver.fill")
}
.tag(PortraitTab.routines.rawValue)
TroutNavStack(navData: $historyNavData,
stackIdentifier: PortraitTab.history.rawValue,
destination: destination)
{
PlusRecentRoutineRun(withSettings: false)
}
.tabItem {
Label("Recent", systemImage: "fossil.shell")
}
.tag(PortraitTab.history.rawValue)
TroutNavStack(navData: $settingsNavData,
stackIdentifier: PortraitTab.settings.rawValue,
destination: destination)
{
PlusSettingsForm()
}
.tabItem {
Label("Settings", systemImage: "gear")
}
.tag(PortraitTab.settings.rawValue)
}
}
private func destination(router: TroutRouter, route: TroutRoute) -> some View {
Destination(route: route)
.environmentObject(router)
.environment(\.managedObjectContext, viewContext)
}
}
struct MainPortrait_Previews: PreviewProvider {
static var previews: some View {
let manager = CoreDataStack.getPreviewStack()
let ctx = manager.container.viewContext
let routine = MRoutine.create(ctx, userOrder: 0)
routine.name = "Back & Bicep"
let e1 = MTask.create(ctx, routine: routine, userOrder: 0)
e1.name = "Lat Pulldown"
let e2 = MTask.create(ctx, routine: routine, userOrder: 1)
e2.name = "Arm Curl"
return MainPortrait()
.environment(\.managedObjectContext, ctx)
.environmentObject(manager)
}
}