Saya ingin menganimasikan transisi antara tampilan anak dengan efek slide tetapi cara saya tidak berhasil. Bagaimana melakukannya dengan benar?

ContentView.swift:

struct ContentView: View {
    @EnvironmentObject var session: SessionStore
    
    var body: some View {
        Group {
            if(self.session.session != nil && (Auth.auth().currentUser?.isEmailVerified)!){
                VStack{
                Text("Welcome to the app")
                Button(action: {session.signOut()}){
                    Text("Sign Out")
                }
                }.transition(.move(edge: .trailing))
                //also I tried .transition(.slide))
            }
            
            if(self.session.session != nil && !(Auth.auth().currentUser?.isEmailVerified)!){
                EmailVerificationView()
                    .transition(.move(edge: .trailing))
            }
            
            if(self.session.session == nil){
                SignInView()
                    .transition(.move(edge: .trailing))
            }
        }.onAppear(perform: {
            session.listen()
        })  
    }
}
2
Heimdallr 19 November 2020, 16:55

1 menjawab

Jawaban Terbaik

Anda membutuhkan wadah yang dapat digerakkan untuk itu. Coba gunakan ZStack daripada Group

var body: some View {
    ZStack {
        if(self.session.session != nil && (Auth.auth().currentUser?.isEmailVerified)!){
            VStack{
            Text("Welcome to the app")
            Button(action: {session.signOut()}){
                Text("Sign Out")
            }
            }.transition(.move(edge: .trailing))
            //also I tried .transition(.slide))
        }
        
        if(self.session.session != nil && !(Auth.auth().currentUser?.isEmailVerified)!){
            EmailVerificationView()
                .transition(.move(edge: .trailing))
        }
        
        if(self.session.session == nil){
            SignInView()
                .transition(.move(edge: .trailing))
        }
    }
    .animation(.default)
    .onAppear(perform: {
        session.listen()
    })  
}
1
Asperi 19 November 2020, 14:12