-
Notifications
You must be signed in to change notification settings - Fork 389
Proper replacement for introspectNavigationController #386
-
I'am working on rafactoring of the module and updated to swiftui-introspect 1.1.1 from 0.1.1. What is proper migration for introspectNavigationController in a such case:
@State private var navigationController: UINavigationController?
ZStack {
contentView
}
.introspectNavigationController { navC in
navigationController = navC
}
Beta Was this translation helpful? Give feedback.
All reactions
Is your navigation view inside content
? If not, then your view is inside the navigation view instead. If that's the case, then you need to override the lookup scope to introspect outwardly to find ancestors like this:
.introspect(.navigationView(style: .stack), on: .iOS(.v14, .v15, .v16, .v17), scope: .ancestor) { navC in navigationController = navC // breakpoint here }
Replies: 2 comments 2 replies
-
Also note, storing it in @State
will cause a memory leak. Use @Weak
instead — see https://github.com/siteline/swiftui-introspect?tab=readme-ov-file#keep-instances-outside-the-customize-closure.
Beta Was this translation helpful? Give feedback.
All reactions
-
@davdroman I saw this, but unfortunately it not working in my case( I've refactored this part as follows:
@_spi(Advanced) import SwiftUIIntrospect
...
@Weak private var navigationController: UINavigationController?
var body: some View {
ZStack {
content
}
.introspect(.navigationView(style: .stack), on: .iOS(.v14, .v15, .v16, .v17)) { navC in
navigationController = navC // breakpoint here
}
...
}
And breakpoin shows that it's not called. So navigationController is nil and that is way it brokes part of the app's functionality. Maybe I've missed something?
Beta Was this translation helpful? Give feedback.
All reactions
-
Is your navigation view inside content
? If not, then your view is inside the navigation view instead. If that's the case, then you need to override the lookup scope to introspect outwardly to find ancestors like this:
.introspect(.navigationView(style: .stack), on: .iOS(.v14, .v15, .v16, .v17), scope: .ancestor) { navC in navigationController = navC // breakpoint here }
Beta Was this translation helpful? Give feedback.
All reactions
-
🎉 1
-
Thank you, it works)
Beta Was this translation helpful? Give feedback.
All reactions
-
👍 1