-
Notifications
You must be signed in to change notification settings - Fork 0
/
Home.swift
113 lines (105 loc) · 3.72 KB
/
Home.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
//
// Home.swift
// ExpenseTracker (iOS)
//
// Created by Balaji on 20/05/22.
//
import SwiftUI
struct Home: View {
@StateObject var expenseViewModel: ExpenseViewModel = .init()
var body: some View {
ScrollView(.vertical, showsIndicators: false) {
VStack(spacing: 12){
HStack(spacing: 15){
VStack(alignment: .leading, spacing: 4) {
Text("Welcome!")
.font(.caption)
.fontWeight(.semibold)
.foregroundColor(.gray)
Text("Ridhima")
.font(.title2.bold())
}
.frame(maxWidth: .infinity,alignment: .leading)
NavigationLink {
FilteredDetailView()
.environmentObject(expenseViewModel)
} label: {
Image(systemName: "hexagon.fill")
.foregroundColor(.gray)
.overlay(content: {
Circle()
.stroke(.white,lineWidth: 2)
.padding(7)
})
.frame(width: 40, height: 40)
.background(Color.white,in: RoundedRectangle(cornerRadius: 10, style: .continuous))
.shadow(color: .black.opacity(0.1), radius: 5, x: 5, y: 5)
}
}
ExpenseCard()
.environmentObject(expenseViewModel)
TransactionsView()
}
.padding()
}
.background{
Color("BG")
.ignoresSafeArea()
}
.fullScreenCover(isPresented: $expenseViewModel.addNewExpense) {
expenseViewModel.clearData()
} content: {
NewExpense()
.environmentObject(expenseViewModel)
}
.overlay(alignment: .bottomTrailing) {
AddButton()
}
}
// MARK: Add New Expense Button
@ViewBuilder
func AddButton()->some View{
Button {
expenseViewModel.addNewExpense.toggle()
} label: {
Image(systemName: "plus")
.font(.system(size: 25, weight: .medium))
.foregroundColor(.white)
.frame(width: 55, height: 55)
.background{
Circle()
.fill(
.linearGradient(colors: [
Color("Gradient1"),
Color("Gradient2"),
Color("Gradient3"),
], startPoint: .topLeading, endPoint: .bottomTrailing)
)
}
.shadow(color: .black.opacity(0.1), radius: 5, x: 5, y: 5)
}
.padding()
}
// MARK: Transactions View
@ViewBuilder
func TransactionsView()->some View{
VStack(spacing: 15){
Text("Transactions")
.font(.title2.bold())
.opacity(0.7)
.frame(maxWidth: .infinity,alignment: .leading)
.padding(.bottom)
ForEach(expenseViewModel.expenses){expense in
// MARK: Transaction Card View
TransactionCardView(expense: expense)
.environmentObject(expenseViewModel)
}
}
.padding(.top)
}
}
struct Home_Previews: PreviewProvider {
static var previews: some View {
ContentView()
}
}