Skip to content

Commit 16f9257

Browse files
author
Mithun
committed
Menu Animation and Binding
1 parent cec37c3 commit 16f9257

File tree

1 file changed

+33
-12
lines changed

1 file changed

+33
-12
lines changed

DesignCode/Home.swift

+33-12
Original file line numberDiff line numberDiff line change
@@ -10,22 +10,15 @@ import SwiftUI
1010

1111
struct Home: View {
1212

13-
var menu = menuData
13+
@State var show = false
1414

1515
var body: some View {
16-
VStack(alignment: .leading) {
17-
ForEach(menu) { item in
18-
MenuRow(image: item.icon, text: item.title)
16+
ZStack {
17+
Button(action: { self.show.toggle() }) {
18+
Text("Open Menu")
1919
}
20-
Spacer()
20+
MenuView(show: $show)
2121
}
22-
.padding(.top, 20)
23-
.padding(30)
24-
.frame(minWidth: 0, maxWidth: .infinity)
25-
.background(Color.white)
26-
.cornerRadius(30)
27-
.padding(.trailing, 60)
28-
.shadow(radius: 20)
2922
}
3023
}
3124

@@ -69,3 +62,31 @@ let menuData = [
6962
Menu(title: "Team", icon: "person.and.person"),
7063
Menu(title: "Sign out", icon: "arrow.uturn.down")
7164
]
65+
66+
struct MenuView: View {
67+
68+
var menu = menuData
69+
@Binding var show: Bool
70+
71+
var body: some View {
72+
return VStack(alignment: .leading) {
73+
ForEach(menu) { item in
74+
MenuRow(image: item.icon, text: item.title)
75+
}
76+
Spacer()
77+
}
78+
.padding(.top, 20)
79+
.padding(30)
80+
.frame(minWidth: 0, maxWidth: .infinity)
81+
.background(Color.white)
82+
.cornerRadius(30)
83+
.padding(.trailing, 60)
84+
.shadow(radius: 20)
85+
.rotation3DEffect(Angle(degrees: show ? 0 : 60), axis: (x: 0, y: 10.0, z: 0))
86+
.animation(.basic())
87+
.offset(x: show ? 0 : -UIScreen.main.bounds.width)
88+
.tapAction {
89+
self.show.toggle()
90+
}
91+
}
92+
}

0 commit comments

Comments
 (0)