Guest User

SideMenuView.swift

a guest
Aug 19th, 2023
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Swift 2.60 KB | None | 0 0
  1. import SwiftUI
  2.  
  3. struct SideMenuView: View {
  4.     @Binding var isMenuOpen: Bool
  5.    
  6.     var appVersion: String {
  7.         if let version = Bundle.main.infoDictionary?["CFBundleShortVersionString"] as? String {
  8.             return version
  9.         }
  10.         return "Desconocido"
  11.     }
  12.    
  13.     var body: some View {
  14.         NavigationView {
  15.             VStack(alignment: .leading, spacing: 25) {
  16.                 Spacer().frame(height: 120)
  17.                
  18.                 MenuItem(icon: "house.fill", label: "Home", color: .blue, destination: RegisterView())
  19.                 MenuItem(icon: "person.fill", label: "Mi cuenta", color: .green, destination: Text("Página de mi cuenta"))
  20.                 MenuItem(icon: "info.circle.fill", label: "Ayuda", color: .orange, destination: Text("Página de ayuda"))
  21.  
  22.                 Spacer()
  23.                
  24.                 Text("Versión \(appVersion)")
  25.                     .font(.headline)
  26.                     .foregroundColor(.white)
  27.                     .frame(maxWidth: .infinity, alignment: .center)
  28.                     .padding(.bottom, 20)
  29.             }
  30.             .padding(.leading, 25)
  31.             .frame(maxWidth: UIScreen.main.bounds.width * 0.65)
  32.             .background(Color.black.opacity(0.5).blur(radius: 8))
  33.             .overlay(LinearGradient(gradient: Gradient(colors: [Color.blue.opacity(0.3), Color.purple.opacity(0.3)]), startPoint: .top, endPoint: .bottom))
  34.             .zIndex(1)
  35.             .offset(x: isMenuOpen ? 0 : -(UIScreen.main.bounds.width * 0.65))
  36.             .animation(.spring(response: 0.7, dampingFraction: 1.2, blendDuration: 0.5), value: isMenuOpen)
  37.             .edgesIgnoringSafeArea(.all)
  38.         }
  39.     }
  40.    
  41.     struct MenuItem<Destination: View>: View {
  42.         var icon: String
  43.         var label: String
  44.         var color: Color
  45.         var destination: Destination
  46.  
  47.         var body: some View {
  48.             NavigationLink(destination: destination) {
  49.                 HStack(spacing: 25) {
  50.                     Image(systemName: icon)
  51.                         .font(.largeTitle)
  52.                         .foregroundColor(color)
  53.                     Text(label)
  54.                         .font(.title)
  55.                         .fontWeight(.semibold)
  56.                         .foregroundColor(.white)
  57.                 }
  58.             }
  59.             .padding(.horizontal, 20)
  60.             .background(RoundedRectangle(cornerRadius: 10).fill(Color.black.opacity(0.2)))
  61.         }
  62.     }
  63. }
  64.  
  65. struct SideMenuView_Previews: PreviewProvider {
  66.     static var previews: some View {
  67.         SideMenuView(isMenuOpen: .constant(true))
  68.     }
  69. }
  70.  
Advertisement
Add Comment
Please, Sign In to add comment