A Pure SwiftUI NavigationPath to pop to any View.
SwiftUI is continuously improving, and with SwiftUI supporting iOS 16.0 and later, it offers NavigationPath
which makes it easier for us to manage navigation and pop
or push
views.
Although it has addressed some limitations of older versions, there are still some issues with popping back to a specific view and identifying the items currently inside the NavigationStack
.
I have extended it in a way that is purely SwiftUI, using only what is available and writing it in the most basic way possible.
Now we can pop to any View
in the NavigationStack
based on the Codable
objects we have appended
to the NavigationPath
.
Check out the demo video below and use it if it can help you in your project.
When debugging, I saw that we can completely view the items in NavigationPath
, but I don’t understand why Apple doesn’t let us use it.
They only allow us to use these methods:
// The number of elements in this path.
public var count: Int { get }
/// A Boolean that indicates whether this path is empty.
public var isEmpty: Bool { get }
/// A value that describes the contents of this path in a serializable format.
public var codable: NavigationPath.CodableRepresentation? { get }
/// Appends a new codable value to the end of…