@@ -7,7 +7,6 @@ public struct NBNavigationStack<Root: View, Data: Hashable>: View {
7
7
@Binding var externalTypedPath : [ Data ]
8
8
@State var internalTypedPath : [ Data ] = [ ]
9
9
@StateObject var path : NavigationPathHolder
10
- @StateObject var pathAppender = PathAppender ( )
11
10
@StateObject var destinationBuilder = DestinationBuilderHolder ( )
12
11
@Environment ( \. useNavigationStack) var useNavigationStack
13
12
var root : Root
@@ -21,33 +20,28 @@ public struct NBNavigationStack<Root: View, Data: Hashable>: View {
21
20
}
22
21
}
23
22
23
+ @ViewBuilder
24
24
var content : some View {
25
- pathAppender. append = { [ weak path] newElement in
26
- path? . path. append ( newElement)
27
- }
28
25
if #available( iOS 16 . 0 , * , macOS 13 . 0 , * , watchOS 9 . 0 , * , tvOS 16 . 0 , * ) , useNavigationStack == . whenAvailable {
29
- return AnyView (
30
- NavigationStack ( path: $path. path) {
31
- root
32
- . navigationDestination ( for: AnyHashable . self, destination: { destinationBuilder. build ( $0) } )
33
- . navigationDestination ( for: LocalDestinationID . self, destination: { destinationBuilder. build ( $0) } )
34
- }
35
- . environment ( \. isWithinNavigationStack, true )
36
- )
37
- }
38
- return AnyView (
26
+ NavigationStack ( path: $path. path) {
27
+ root
28
+ . navigationDestination ( for: AnyHashable . self, destination: { destinationBuilder. build ( $0) } )
29
+ . navigationDestination ( for: LocalDestinationID . self, destination: { destinationBuilder. build ( $0) } )
30
+ }
31
+ . environment ( \. isWithinNavigationStack, true )
32
+ } else {
39
33
NavigationView {
40
34
Router ( rootView: root, screens: $path. path)
41
35
}
42
36
. navigationViewStyle ( supportedNavigationViewStyle)
43
37
. environment ( \. isWithinNavigationStack, false )
44
- )
38
+ }
45
39
}
46
40
47
41
public var body : some View {
48
42
content
49
43
. environmentObject ( path)
50
- . environmentObject ( pathAppender )
44
+ . environmentObject ( Unobserved ( object : path ) )
51
45
. environmentObject ( destinationBuilder)
52
46
. environmentObject ( Navigator ( useInternalTypedPath ? $internalTypedPath : $externalTypedPath) )
53
47
. onFirstAppear {
0 commit comments