Код: Выделить всё
struct SideMenuView: View {
@Binding var isShowing: Bool
@State private var isOn = false
// @State private var selectedDestination: MenuDestination?
// @Environment(\.dismiss) private var dismiss
let profile = UserProfile(
name: "Mr. Henry Edward",
earningPoints: 556,
profileImage: "person.circle.fill"
)
let menuItems = [
SideMenuItem(title: "Edit your info", icon: "edit-profile", destination: .profile),
SideMenuItem(title: "Order History", icon: "order-history", destination: .orderHistory),
SideMenuItem(title: "Reviews", icon: "ranking", destination: .reviews),
SideMenuItem(title: "Setting", icon: "settings", destination: .settings),
SideMenuItem(title: "Change Password", icon: "cart", destination: .changePassword),
SideMenuItem(title: "Franchise Locations", icon: "maps-location", destination: .franchiseLocations),
SideMenuItem(title: "Terms & Conditions", icon: "terms", destination: .termsConditions)
]
var body: some View {
ZStack {
// Dimmed Background
if isShowing {
Color.black
.opacity(0.5)
.ignoresSafeArea()
.onTapGesture {
withAnimation(.spring()) {
isShowing.toggle()
}
}
}
//MARK: - Menu Content
HStack {
VStack(spacing: 0) {
// Profile Header
HStack{
Image(.back)
.onTapGesture {
isShowing = false
}
Spacer()
Toggle(isOn: $isOn) {
}
}
.padding()
.padding(.top,70)
ZStack {
Rectangle()
.fill(Color(.tabBackground))
.frame(width: 290, height: 112)
.cornerRadius(10)
.padding()
HStack(spacing: 16) {
Image(.person)
.resizable()
.aspectRatio(contentMode: .fill)
.frame(width: 40, height: 40)
.clipShape(Circle())
.overlay(Circle().stroke(Color.white, lineWidth: 2))
VStack {
Text(profile.name)
.font(Font.custom("Poppins-Medium", size: 12))
.foregroundStyle(.colorYellow)
Text("**EARNING POINTS** | \(profile.earningPoints)")
.font(Font.custom("Poppins-Medium", size: 11))
.frame(width: 150, height: 22)
.foregroundColor(.black)
.background(Color.white)
.cornerRadius(5)
}
Image(.qrScan)
.applyTapAnimation()
.onTapGesture {
}
}
.padding(.top, 20)
}
ScrollView {
VStack(spacing: 0) {
ForEach(menuItems) { item in
NavigationLink(destination: destinationView(for: item.destination)) {
ProfileMenuItem(item: item)
}
}
Spacer()
AuthButton(title: "Logout", icon: Image(.logout), backgroundColor: .clear, action: {})
.padding()
.foregroundColor(.tabBackground)
}
.background(Color(UIColor.systemBackground))
}
}
.frame(width: UIScreen.main.bounds.width * 0.8)
.background(Color(UIColor.systemBackground))
.cornerRadius(20, corners: [.topRight,.bottomRight])
.offset(x: isShowing ? 0 : -UIScreen.main.bounds.width)
.animation(.spring(), value: isShowing)
Spacer()
}
.ignoresSafeArea()
}
}
}
#Preview {
SideMenuView(isShowing: .constant(true))
}
struct ProfileMenuItem: View {
let item: SideMenuItem
var body: some View {
Button(action: {}) {
HStack(spacing:16) {
Image(item.icon)
.frame(width: 24, height: 24)
.foregroundStyle(.colorBlack)
Text(item.title)
.foregroundColor(.black)
.font(Font.custom("Poppins-Medium", size: 14))
Spacer()
Image(systemName: "chevron.right")
.foregroundColor(.black)
}
.padding()
.background(Color.card)
.cornerRadius(20)
.padding(.horizontal, 26)
.padding(.vertical, 5)
}
}
}
@ViewBuilder
private func destinationView(for destination: MenuDestination) -> some View {
switch destination {
case .profile:
ProfileView()
case .orderHistory:
OrderHistoryView()
case .reviews:
ReviewsView()
case .settings:
SettingsView()
case .changePassword:
ChangePasswordView()
case .franchiseLocations:
FranchiseLocationsView()
case .termsConditions:
TermsConditionsView()
}
}
Подробнее здесь: https://stackoverflow.com/questions/792 ... in-swiftui