@@ -10,7 +10,7 @@ struct LazyNavigationLink<Destination: View, Label: View>: View {
1010
1111 /// Set it to `true` to proceed with the desired navigation. Set it to `false` to remove the view from the navigation context.
1212 ///
13- @ Binding var isActive : Bool
13+ var isActive : Binding < Bool > ?
1414
1515 /// `NavigationLink` label
1616 ///
@@ -19,15 +19,19 @@ struct LazyNavigationLink<Destination: View, Label: View>: View {
1919 /// Creates a navigation link that creates and presents the destination view when active.
2020 /// - Parameters:
2121 /// - destination: A view for the navigation link to present.
22- /// - isActive: A binding to a Boolean value that indicates whether `destination` is currently presented.
22+ /// - isActive: An optional binding to a Boolean value that indicates whether `destination` is currently presented.
2323 /// - label: A view builder to produce a label describing the `destination` to present.
24- init ( destination: @autoclosure @escaping ( ) -> Destination , isActive: Binding < Bool > , label: @escaping ( ) -> Label ) {
24+ init ( destination: @autoclosure @escaping ( ) -> Destination , isActive: Binding < Bool > ? = nil , label: @escaping ( ) -> Label ) {
2525 self . destination = destination
26- self . _isActive = isActive
26+ self . isActive = isActive
2727 self . label = label
2828 }
2929
3030 var body : some View {
31- NavigationLink ( destination: LazyView ( destination) , isActive: $isActive, label: label)
31+ if let isActive = isActive {
32+ NavigationLink ( destination: LazyView ( destination) , isActive: isActive, label: label)
33+ } else {
34+ NavigationLink ( destination: LazyView ( destination) , label: label)
35+ }
3236 }
3337}
0 commit comments