today I'm trying to navigate between 2 different views but I want to use the same view cleaning the info from the previous view. I created a MotherView to invoke 2 different view. Here's my code
import SwiftUI
struct MotherView: View {
@ObservedObject var viewRouter: ViewRouter
var body: some View {
VStack {
if viewRouter.currentPage == "splash" {
SplashView()
} else{
ContentView()
}
}
}
}
struct MotherView_Previews : PreviewProvider {
static var previews: some View {
MotherView(viewRouter: ViewRouter())
}
}
This is my SplashScreen:
struct SplashView: View {
@State private var isAnimated = true
@EnvironmentObject var pageSettings: PageSettings
var body: some View {
VStack{
LottieView(filename:"Logo")
pageSettings.currentPage = "content"
}
}
}
NOTE SplashView() is a view with an animation using Lottie and ContentView() is a view with my login. I want to start my app using my SplashView() and then clean the VStack and run the ContentView().
Is That possible? Thank you!
This is the last update from this code (I got this error: "Argument type '()' does not conform to expected type 'View'")
struct SplashView: View {
@State private var animated = false
@EnvironmentObject var pageSettings: PageSettings
var body: some View {
VStack{
if self.animated{
pageSettings.currentPage = "content"
}else{
LottieView()
}
}
}
}