Guest User

ContentView.swift

a guest
Aug 19th, 2023
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Swift 4.68 KB | None | 0 0
  1. import SwiftUI
  2.  
  3. struct ContentView: View {
  4.     @State private var isMenuOpen = false
  5.     @State private var scale: CGFloat = 1.05
  6.     @State private var isViewInitialized = false
  7.    
  8.    
  9.     var body: some View {
  10.         NavigationView{
  11.             ZStack(alignment: .leading) {
  12.                 // Fondo de degradado
  13.                 LinearGradient(gradient: Gradient(colors: [Color.purple, Color.blue]), startPoint: .top, endPoint: .bottom)
  14.                     .edgesIgnoringSafeArea(.all)
  15.                     .onTapGesture {
  16.                         // Minimiza el menú si se toca fuera de él
  17.                         withAnimation {
  18.                             isMenuOpen = false
  19.                         }
  20.                     }
  21.                 VStack(spacing: 50) {
  22.                     // Encabezado con animación sutil
  23.                     Text("Grocery&Go")
  24.                         .font(.largeTitle)
  25.                         .fontWeight(.bold)
  26.                         .foregroundColor(.white)
  27.                         .shadow(color: .black.opacity(0.3), radius: 5)
  28.                         .scaleEffect(scale)
  29.                         .animation(.easeInOut(duration: 1.2).repeatForever(autoreverses: true), value: scale)
  30.                         .offset(y: -30)
  31.                         .onAppear {
  32.                             Timer.scheduledTimer(withTimeInterval: 1.2, repeats: true) { _ in
  33.                                 withAnimation(Animation.easeInOut(duration: 1.2).repeatForever(autoreverses: true)) {
  34.                                     self.scale = self.scale == 1.05 ? 1.15 : 1.05
  35.                                 }
  36.                             }
  37.                         }
  38.                     navigationButton(icon: "mail.and.text.magnifyingglass", destination: BusquedaProductoView(), description: "Búsqueda de Productos")
  39.                     navigationButton(icon: "cart.badge.plus", destination: NuevoProductoView(), description: "Nuevo Producto")
  40.                     navigationButton(icon: "bag.badge.questionmark", destination: SupermercadosView(), description: "Supermercados")
  41.                 }
  42.                 .padding(.top, -30)
  43.                 .blur(radius: isMenuOpen ? 4 : 0)
  44.                 .frame(maxWidth: .infinity, maxHeight: .infinity)
  45.                 .navigationBarItems(leading: Button(action: {
  46.                     withAnimation {
  47.                         isMenuOpen.toggle()
  48.                     }
  49.                 }) {
  50.                     Image(systemName: "rectangle.split.3x1")
  51.                         .resizable()
  52.                         .frame(width: 30, height: 20)
  53.                         .foregroundColor(.white)
  54.                 })
  55.                
  56.                 // Menu desplegable
  57.                 if isMenuOpen {
  58.                     SideMenuView(isMenuOpen: $isMenuOpen)
  59.                         .frame(width: UIScreen.main.bounds.width * 0.65)
  60.                         .transition(.move(edge: .leading))
  61.                         .zIndex(2)
  62.                 }
  63.             }
  64.             .onAppear {
  65.                 DispatchQueue.main.asyncAfter(deadline: .now() + 0.1) {
  66.                     isViewInitialized = true
  67.                 }
  68.             }
  69.         }
  70.     }
  71.    
  72.     func navigationButton<Destination: View>(icon: String, destination: Destination, description: String) -> some View {
  73.         NavigationLink(destination: destination) {
  74.             VStack(spacing: 10) {
  75.                 ZStack {
  76.                     Circle()
  77.                         .fill(RadialGradient(gradient: Gradient(colors: [Color.blue, Color.purple]), center: .center, startRadius: 20, endRadius: 110))
  78.                         .frame(width: 120, height: 120)
  79.                         .shadow(radius: 10)
  80.                     Image(systemName: icon)
  81.                         .resizable()
  82.                         .scaledToFit()
  83.                         .frame(width: 60, height: 60)
  84.                         .foregroundColor(.white)
  85.                 }
  86.                
  87.                 Text(description)
  88.                     .foregroundColor(.white)
  89.                     .font(.headline)
  90.             }
  91.         }
  92.         .buttonStyle(SpringButtonStyle())
  93.     }
  94. }
  95.  
  96. struct SpringButtonStyle: ButtonStyle {
  97.     func makeBody(configuration: Configuration) -> some View {
  98.         configuration.label
  99.             .scaleEffect(configuration.isPressed ? 0.95 : 1.0)
  100.             .rotationEffect(Angle(degrees: configuration.isPressed ? 5 : 0))
  101.             .animation(.spring(response: 0.4, dampingFraction: 0.6, blendDuration: 0.5), value: configuration.isPressed)
  102.     }
  103. }
  104.  
  105. struct ContentView_Previews: PreviewProvider {
  106.     static var previews: some View {
  107.         ContentView()
  108.     }
  109. }
  110.  
Advertisement
Add Comment
Please, Sign In to add comment