-
Notifications
You must be signed in to change notification settings - Fork 67
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix iOS 16 NavigationLink console warning #47
Fix iOS 16 NavigationLink console warning #47
Conversation
Thanks a lot for looking into this @DavidKmn ! Unfortunately, this change would break pushing more than 2 screens in a navigation stack. |
Nice catch I see. Yes I missed that, so it seems like what we actually want is to check whether the view is in a navigation stack (ie its either the first one via |
Just pushed this check |
Thanks very much for the changes @DavidKmn. Unfortunately, even with this change, the warning is still logged when popping back more than one view (you can test in the example app). Also, people might be manually adding their own I think this is a SwiftUI bug to be honest, and I'm not sure this library can do anything to mitigate it. Your investigations helped me understand what seems to trigger the warning. E.g. I can trigger it with the following vanilla SwiftUI code: import SwiftUI
@main
struct NavigationWarningLogDemoApp: App {
var body: some Scene {
WindowGroup {
NavigationView {
Content1View()
}.navigationViewStyle(.stack)
}
}
}
struct Content1View: View {
@State var pushing = false
var body: some View {
VStack {
NavigationLink(destination: Content2View(popToRoot: { pushing = false }), isActive: $pushing, label: { Text("Go")})
}
.navigationTitle("1")
}
}
struct Content2View: View {
@State var pushing = false
let popToRoot: () -> Void
var body: some View {
VStack {
NavigationLink(destination: Content3View(popToRoot: popToRoot), isActive: $pushing, label: { Text("Go")})
Button(action: popToRoot, label: { Text("Pop to root")})
}
.navigationTitle("2")
}
}
struct Content3View: View {
@State var pushing = false
let popToRoot: () -> Void
var body: some View {
VStack {
// The warning does not appear if you remove this NavigationLink.
NavigationLink(destination: Text("4"), isActive: $pushing, label: { Text("Go")})
// Tapping this button triggers a warning to be logged:
//
// NavigationLink presenting a value must appear inside a NavigationContent-based NavigationView. Link will be disabled.
Button(action: popToRoot, label: { Text("Pop to root")})
}
.navigationTitle("3")
}
} I'll file a radar with this example code. |
Filed feedback |
Nice! |
Any update on this? |
Also experiencing this issue. Any updates? |
No update so far on the feedback I'm afraid (FB11490806). I'll close this PR as it doesn't solve the issue sadly. |
This fixes the iOS 16 NavigationLink warning printed in the console as noted by #34
Tested using Xcode Beta 6.