Untitled

 avatar
unknown
plain_text
3 years ago
2.7 kB
11
Indexable
//
//  ContentView.swift
//
//

import SwiftUI

struct ContentView: View {
    
    @State var centerVertically = false
    @State var centerHorizontally = false
    @State var showBigView = false
    @State var showNextScreen = false
    
    @Namespace var namespace
    
    var body: some View {
        
        ZStack(alignment: Alignment(horizontal: .center, vertical: .bottom)) {
            
            Color.black
            
            if !showBigView {
            
            HStack {
                
                Spacer()
                
                Button(action: {
                    
                    withAnimation {
                        centerVertically = true
                    }
                    
                    withAnimation(.linear(duration: 0.3)) {
                        centerHorizontally = true
                    }
                    
                    Timer.scheduledTimer(withTimeInterval: 0.7, repeats: false, block: { timer in
                        
                        withAnimation {
                            showBigView = true
                        }
                    })
                    
                    Timer.scheduledTimer(withTimeInterval: 1, repeats: false, block: { timer in
                        
                        withAnimation {
                            showNextScreen = true
                        }
                    })
                    
                }) {
                    Color.white
                        .frame(width: 30, height: 30)
                }
                .padding(EdgeInsets(top: 0,
                                    leading: 30,
                                    bottom: centerVertically ? 300 : 30,
                                    trailing: 30))
                .matchedGeometryEffect(id: "test", in: namespace)
                
                if centerHorizontally {
                    Spacer()
                }
                
            }
                
            } else {
                
                Color.white
                    .matchedGeometryEffect(id: "test", in: namespace)
                    .frame(width: UIScreen.main.bounds.width,
                           height: 330)
                
            }
            
            if showNextScreen {
                
                Text("Next screen")
                    .foregroundColor(.black)
                    .transition(.opacity)
                
            }
            
        }
    }
    
}

struct ContentView_Previews: PreviewProvider {
    static var previews: some View {
        ContentView()
    }
}
Editor is loading...