-
Notifications
You must be signed in to change notification settings - Fork 7
/
HomeView.swift
113 lines (102 loc) · 3.96 KB
/
HomeView.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
//
// HomeView.swift
// Created by Abdullah Kardas on 20.08.2022.
//
import SwiftUI
import SideMenu
struct HomeView: View {
@State var isMenuOpen:Bool = true
let tabs = [MenuTabModel(title: "Home", imageName: "house"),MenuTabModel(title: "Profile", imageName: "person"),MenuTabModel( title: "Settings", imageName: "gear")]
@State var selectedTab:MenuTabModel = MenuTabModel(title: "Home", imageName: "house")
@State var backColor = Color.white
var body: some View {
ZStack {
SideMenuView(
isMenuOpen: $isMenuOpen,
tabs: tabs, // add your [MenuTabModel]
selectedTab: $selectedTab, //initial selectedTab
backColor: $backColor, //acces view placeholder background
backImage: "airplane", //add your background image! Default value is airplane
selectionColor: .purple,
blurRadius: 32, // add blur radius for image default value is 32
enable3D: true //enable/disable 3D effect
) {
if selectedTab.title == "Home" {
TabOne(isMenuOpen: $isMenuOpen, backColor: $backColor)
}else if selectedTab.title == "Profile" {
TabTwo(isMenuOpen: $isMenuOpen, backColor: $backColor)
}else if selectedTab.title == "Settings" {
TabThree(isMenuOpen: $isMenuOpen, backColor: $backColor)
}
}
}
}
}
struct HomeView_Previews: PreviewProvider {
static var previews: some View {
HomeView()
}
}
struct TabOne: View {
@Binding var isMenuOpen:Bool
@Binding var backColor:Color
var body: some View {
ZStack {//Your content is here
backColor.ignoresSafeArea().cornerRadius(isMenuOpen ? 12:0)
VStack(alignment:.leading) {
Button(action: { isMenuOpen.toggle() }) {
Image(systemName: "line.3.horizontal").font(.title).foregroundColor(.white)
}.padding(.top, 12).padding(.leading, 12).frame(maxWidth: .infinity,alignment: .leading)
Spacer()
}
Spacer()
Text("Tab 1").foregroundColor(.white).font(.title2).onTapGesture {
print("something")
}
}.onAppear{
backColor = .pink
}
}
}
struct TabTwo: View {
@Binding var isMenuOpen:Bool
@Binding var backColor:Color
var body: some View {
ZStack {//Your content is here
backColor.ignoresSafeArea().cornerRadius(isMenuOpen ? 12:0)
VStack(alignment:.leading) {
Button(action: { isMenuOpen.toggle() }) {
Image(systemName: "line.3.horizontal").font(.title).foregroundColor(.white)
}.padding(.top, 12).padding(.leading, 12).frame(maxWidth: .infinity,alignment: .leading)
Spacer()
}
Spacer()
Text("Tab 2").foregroundColor(.white).font(.title2).onTapGesture {
print("something")
}
}.onAppear {
backColor = .green
}
}
}
struct TabThree: View {
@Binding var isMenuOpen:Bool
@Binding var backColor:Color
var body: some View {
ZStack {//Your content is here
backColor.ignoresSafeArea().cornerRadius(isMenuOpen ? 12:0)
VStack(alignment:.leading) {
Button(action: { isMenuOpen.toggle() }) {
Image(systemName: "line.3.horizontal").font(.title).foregroundColor(.white)
}.padding(.top, 12).padding(.leading, 12).frame(maxWidth: .infinity,alignment: .leading)
Spacer()
}
Spacer()
Text("Tab 3").foregroundColor(.white).font(.title2).onTapGesture {
print("something")
}
}.onAppear {
backColor = .purple
}
}
}