Home > front end >  How to change transition in fullScreenCover in SwiftUI?
How to change transition in fullScreenCover in SwiftUI?

Time:11-01

I am trying to make a transition from leading.

.fullScreenCover(isPresented: $isLoginSuccess) {
    HomeView()
}

It's using the default transition, from bottom. Unable to change the transition with .transition(.move(edge: .leading))

CodePudding user response:

fullScreenCover is using the system animation when presenting (also because it plays under the hoods with UIKit, if I'm not mistaken), while transition modifier affects the appearance of a view when for example you use if or switch statements in the body of a view itself.

In your case you could wrap both login and home views in same body and use an if to show either the login or the home.

struct Root: View {
  @State var isLoginSuccess = false

  var body: some View {
    if isLoginSuccess {
      HomeView()
        .transition(.move(edge: .leading))
    } else {
      LoginView()
        .transition(.move(edge: .trailing))
    }
  }
}

Then, when modifying the state, remember to wrap under withAnimation like:

withAnimation {
  isLoginSuccess = true
}
  • Related