Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Proper replacement for introspectNavigationController #386

Answered by davdroman
AndreiBehel asked this question in Q&A
Discussion options

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
}
You must be logged in to vote

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

Comment options

You must be logged in to vote
0 replies
Comment options

@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?

You must be logged in to vote
2 replies
Comment options

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
}
Answer selected by AndreiBehel
Comment options

Thank you, it works)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet

AltStyle によって変換されたページ (->オリジナル) /