2

I want to animate transitions between child views with slide effect but the way I do it doesn't work. How to do it right?

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()
        })  
    }
}

1 Answer 1

3

You need animatable container for that. Try to use ZStack instead of 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()
    })  
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.