Skip to content

Commit 05c53cd

Browse files
committed
fixed NavigationLinkItem for iOS 14.5
1 parent 8a10c54 commit 05c53cd

File tree

2 files changed

+12
-34
lines changed

2 files changed

+12
-34
lines changed

Sources/SwiftUI-Kit/Extensions/NavigationLink.swift

-27
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,6 @@
77

88
import SwiftUI
99

10-
public extension View {
11-
func navigation<I: Identifiable, D: View>(item: Binding<I?>, @ViewBuilder destination: @escaping (I) -> D) -> some View {
12-
background(NavigationLink(item: item, destination: destination))
13-
}
14-
}
15-
1610
public extension NavigationLink where Label == EmptyView {
1711
init(destination: Destination, isActive: Binding<Bool>) {
1812
self.init(destination: destination, isActive: isActive) { EmptyView() }
@@ -21,25 +15,4 @@ public extension NavigationLink where Label == EmptyView {
2115
init(isActive: Binding<Bool>, @ViewBuilder destination: @escaping () -> Destination) {
2216
self.init(destination: destination(), isActive: isActive) { EmptyView() }
2317
}
24-
25-
init?<I: Identifiable>(item: Binding<I?>, @ViewBuilder destination: @escaping (I) -> Destination) {
26-
guard let value = item.wrappedValue else {
27-
return nil
28-
}
29-
30-
let isActive: Binding<Bool> = Binding(
31-
get: { item.wrappedValue != nil },
32-
set: { value in
33-
if !value {
34-
item.wrappedValue = nil
35-
}
36-
}
37-
)
38-
39-
self.init(
40-
destination: destination(value),
41-
isActive: isActive,
42-
label: { EmptyView() }
43-
)
44-
}
4518
}

Sources/SwiftUI-Kit/Views/NavigationLinkItem.swift

+12-7
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ public struct NavigationLinkItem<I: Identifiable, D: View, L: View>: View {
1212
public var destination: (I) -> D
1313
public var label: () -> L
1414

15-
public init(item: Binding<I?>, @ViewBuilder destination: @escaping (I) -> D, @ViewBuilder label: @escaping () -> L) {
15+
init(item: Binding<I?>, @ViewBuilder destination: @escaping (I) -> D, @ViewBuilder label: @escaping () -> L) {
1616
self.item = item
1717
self.destination = destination
1818
self.label = label
@@ -30,14 +30,19 @@ public struct NavigationLinkItem<I: Identifiable, D: View, L: View>: View {
3030
}
3131

3232
public var body: some View {
33+
NavigationLink(
34+
destination: destinationView(),
35+
isActive: isActive,
36+
label: label
37+
)
38+
}
39+
40+
@ViewBuilder
41+
private func destinationView() -> some View {
3342
if let value = item.wrappedValue {
34-
NavigationLink(
35-
destination: destination(value),
36-
isActive: isActive,
37-
label: label
38-
)
43+
destination(value)
3944
} else {
40-
label()
45+
EmptyView()
4146
}
4247
}
4348
}

0 commit comments

Comments
 (0)