Skip to content

Instantly share code, notes, and snippets.

@phillipcaudell
Created September 5, 2023 17:28
Show Gist options
  • Save phillipcaudell/6201a448310bcc7830eea8be3b7bd24e to your computer and use it in GitHub Desktop.
Save phillipcaudell/6201a448310bcc7830eea8be3b7bd24e to your computer and use it in GitHub Desktop.
struct InternalNavigationStack<Data, Root>: View where Data: Hashable, Root: View {
@Binding var path: [Data]
let root: () -> Root
init(
path: Binding<[Data]>,
@ViewBuilder root: @escaping () -> Root
) {
self._path = path
self.root = root
}
@State private var internalPath = [Data]()
var body: some View {
NavigationStack(path: $internalPath, root: root)
.task {
internalPath = path
}
.onChange(of: internalPath) { newValue in
path = newValue
}
.onChange(of: path) { newValue in
internalPath = newValue
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment