In some points of the code, I need to use this:
NavigationLink(
destination: LoginViewScreen(),
isActive: $navToLogin
) { EmptyView() }
... because my navigation is not using a button, I use only the property as trigger to navigate.
I'm receiving this warning:
use NavigationLink(value:label:) inside a List within a NavigationStack or NavigationSplitView
The problem is that minimum iOS target is 14.0 and I'm not able to use NavigationStack because it is for iOS 16.0.
I would like something like that, where I can use the both ways. But I am not being able, because the property NavigationPath needs to be a @State, and the states need to be a property of the class, and if the property is iOS > 16, all the class is > 16 and a cannot instanciate it in my application
@State var navToLogin: Bool = false
@EnvironmentObject var navigationViewModel: NavigatorViewModel
var body: some View {
NavigationView {
VStack {
ExampleView()
.onAppear() {
Task {
try? await Task.sleep(nanoseconds: 5000000000)
navigateToLogin()
}
}
navigationToLogin
}
}
}
var navigationToLogin: some View {
NavigationLink(
destination: LoginViewScreen(),
isActive: $navToLogin
) { EmptyView() }
}
private func navigateToLogin() {
if #available(iOS 16, *) {
navigationViewModel.navigateTo(.loginScreen)
} else {
navToLogin.toggle()
}
}
Does anyone know how to work well with it ?
Or is there any other way ?
I don't have a direct answer to your question but I can offer you a different approach. Maybe this will suit you?
We use a timer instead of sleep to avoid blocking the thread and the display is only conditioned on the value of navToLogin.
Happy coding!