twigs-ios/Twigs/TabbedBudgetView.swift

89 lines
2.9 KiB
Swift
Raw Normal View History

//
// TabbedBudgetView.swift
// Budget
//
// Created by Billy Brawner on 9/29/19.
// Copyright © 2019 William Brawner. All rights reserved.
//
import SwiftUI
struct TabbedBudgetView: View {
@EnvironmentObject var budgetDataStore: BudgetsDataStore
@EnvironmentObject var categoryDataStore: CategoryDataStore
let budget: Budget
@State var isAddingTransaction = false
@State var tabSelection: Int = 0
var body: some View {
TabView(selection: $tabSelection) {
2021-10-10 02:27:54 +00:00
BudgetDetailsView(budget: self.budget)
.tabItem {
Image(systemName: "chart.line.uptrend.xyaxis.circle.fill")
2021-10-10 02:27:54 +00:00
Text("Overview")
}
.tag(0)
.keyboardShortcut("1")
TransactionListView(self.budget)
.sheet(isPresented: $isAddingTransaction,
onDismiss: {
isAddingTransaction = false
},
content: {
AddTransactionView(showSheet: self.$isAddingTransaction, budgetId: self.budget.id)
.navigationBarTitle("add_transaction")
})
.tabItem {
Image(systemName: "dollarsign.circle.fill")
Text("transactions")
}
.tag(1)
.keyboardShortcut("2")
CategoryListView(self.budget).tabItem {
Image(systemName: "chart.pie.fill")
Text("categories")
}
.tag(2)
.keyboardShortcut("3")
ProfileView().tabItem {
Image(systemName: "person.circle.fill")
Text("profile")
}
.tag(3)
.keyboardShortcut("4")
}.navigationBarItems(
trailing: HStack {
if tabSelection == 1 {
Button(action: {
self.isAddingTransaction = true
}) {
Image(systemName: "plus")
.padding()
}
.keyboardShortcut("n")
}
}
)
.onReceive(NotificationCenter.default.publisher(for: Notification.Name("switchTabs"))) { notification in
if let tabTag = notification.object as? Int {
if 0...3 ~= tabTag {
self.tabSelection = tabTag
print("Updating tabSelection to \(tabTag)")
} else {
print("Ignoring value \(tabTag)")
}
}
}
}
init (_ budget: Budget) {
self.budget = budget
}
}
//
//struct TabbedBudgetView_Previews: PreviewProvider {
// static var previews: some View {
// TabbedBudgetView()
// }
//}