Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import SwiftUI
- struct ContentView: View {
- @State private var isMenuOpen = false
- @State private var scale: CGFloat = 1.05
- @State private var isViewInitialized = false
- var body: some View {
- NavigationView{
- ZStack(alignment: .leading) {
- // Fondo de degradado
- LinearGradient(gradient: Gradient(colors: [Color.purple, Color.blue]), startPoint: .top, endPoint: .bottom)
- .edgesIgnoringSafeArea(.all)
- .onTapGesture {
- // Minimiza el menú si se toca fuera de él
- withAnimation {
- isMenuOpen = false
- }
- }
- VStack(spacing: 50) {
- // Encabezado con animación sutil
- Text("Grocery&Go")
- .font(.largeTitle)
- .fontWeight(.bold)
- .foregroundColor(.white)
- .shadow(color: .black.opacity(0.3), radius: 5)
- .scaleEffect(scale)
- .animation(.easeInOut(duration: 1.2).repeatForever(autoreverses: true), value: scale)
- .offset(y: -30)
- .onAppear {
- Timer.scheduledTimer(withTimeInterval: 1.2, repeats: true) { _ in
- withAnimation(Animation.easeInOut(duration: 1.2).repeatForever(autoreverses: true)) {
- self.scale = self.scale == 1.05 ? 1.15 : 1.05
- }
- }
- }
- navigationButton(icon: "mail.and.text.magnifyingglass", destination: BusquedaProductoView(), description: "Búsqueda de Productos")
- navigationButton(icon: "cart.badge.plus", destination: NuevoProductoView(), description: "Nuevo Producto")
- navigationButton(icon: "bag.badge.questionmark", destination: SupermercadosView(), description: "Supermercados")
- }
- .padding(.top, -30)
- .blur(radius: isMenuOpen ? 4 : 0)
- .frame(maxWidth: .infinity, maxHeight: .infinity)
- .navigationBarItems(leading: Button(action: {
- withAnimation {
- isMenuOpen.toggle()
- }
- }) {
- Image(systemName: "rectangle.split.3x1")
- .resizable()
- .frame(width: 30, height: 20)
- .foregroundColor(.white)
- })
- // Menu desplegable
- if isMenuOpen {
- SideMenuView(isMenuOpen: $isMenuOpen)
- .frame(width: UIScreen.main.bounds.width * 0.65)
- .transition(.move(edge: .leading))
- .zIndex(2)
- }
- }
- .onAppear {
- DispatchQueue.main.asyncAfter(deadline: .now() + 0.1) {
- isViewInitialized = true
- }
- }
- }
- }
- func navigationButton<Destination: View>(icon: String, destination: Destination, description: String) -> some View {
- NavigationLink(destination: destination) {
- VStack(spacing: 10) {
- ZStack {
- Circle()
- .fill(RadialGradient(gradient: Gradient(colors: [Color.blue, Color.purple]), center: .center, startRadius: 20, endRadius: 110))
- .frame(width: 120, height: 120)
- .shadow(radius: 10)
- Image(systemName: icon)
- .resizable()
- .scaledToFit()
- .frame(width: 60, height: 60)
- .foregroundColor(.white)
- }
- Text(description)
- .foregroundColor(.white)
- .font(.headline)
- }
- }
- .buttonStyle(SpringButtonStyle())
- }
- }
- struct SpringButtonStyle: ButtonStyle {
- func makeBody(configuration: Configuration) -> some View {
- configuration.label
- .scaleEffect(configuration.isPressed ? 0.95 : 1.0)
- .rotationEffect(Angle(degrees: configuration.isPressed ? 5 : 0))
- .animation(.spring(response: 0.4, dampingFraction: 0.6, blendDuration: 0.5), value: configuration.isPressed)
- }
- }
- struct ContentView_Previews: PreviewProvider {
- static var previews: some View {
- ContentView()
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment