Replies: 4 comments 3 replies
-
|
@mstfy That's coming from SwiftUI and not our library. I believe that prints whenever there is more than one navigation link attempting to be active at once. Here's an example without our library: struct SampleView: View {
@State var isActive = false
var body: some View {
NavigationView {
VStack {
Button("tap me to see the bug") {
self.isActive = true
}
ForEach(0..<10, id: \.self) { number in
NavigationLink(
isActive: $isActive,
destination: {
Text("\(number) detail")
},
label: {
Text("\(number) row")
}
)
}
}
}
}
}Each navigation link should be unique, so you'll want each row to link to a different case. This, for example: enum Route {
case a
case b
case c
}
struct SampleView: View {
@State var route: Route?
var body: some View {
NavigationView {
VStack {
NavigationLink(
unwrapping: $route,
case: /Route.a,
destination: { _ in Text("A detail") },
onNavigate: { route = $0 ? .a : nil }
) { Text("A row") }
NavigationLink(
unwrapping: $route,
case: /Route.b,
destination: { _ in Text("B detail") },
onNavigate: { route = $0 ? .b : nil }
) { Text("B row") }
NavigationLink(
unwrapping: $route,
case: /Route.c,
destination: { _ in Text("C detail") },
onNavigate: { route = $0 ? .c : nil }
) { Text("C row") }
}
}
}
}I'm going to convert this to a discussion, since it doesn't appear to be a bug in SwiftUI Navigation. Thanks for starting the convo! |
Beta Was this translation helpful? Give feedback.
-
|
I have been facing the same issue and here is mentioned too. enum Route {
case detail(Int)
}
struct SampleView: View {
@State var route: Route?
var body: some View {
NavigationView {
VStack {
ForEach(0..<10, id: \.self) { number in
Button(action: { route = .detail(number) }) {
Text("\(number) row")
}
}
}
.background(
NavigationLink(
unwrapping: $route,
case: /Route.detail,
destination: { number in
Text("\(number) detail")
},
onNavigate: {
if $0 == false {
route = nil
}
},
label: { EmptyView() }
)
)
}
}
}I think this is similar to the sheet API so we can cook a helper to do this. |
Beta Was this translation helpful? Give feedback.
-
|
This is currently a limitation of SwiftUI but can be overcome by changing how you model the navigation domain. Instead of the list having a single detail route, you can think of each row in the list as it’s own “child domain”, each with its own detail route. Take a look at how this case study works and note that the edit route is part of the row view model, not the parent list. https://github.com/pointfreeco/swiftui-navigation/pull/6/files To maintain the connection with the parent view, you’ll probably want to have a “child” route in the parent. Some work is needed to keep the two domains in sync. This is exactly how the item list in the Pointfree episodes on this work. https://github.com/pointfreeco/episode-code-samples/tree/main/0168-navigation-pt9/SwiftUINavigation/SwiftUINavigation |
Beta Was this translation helpful? Give feedback.
-
|
The workaround above effectively does this by adding another layer, but obfuscates the code somewhat. I would have thought that the value passed to isActive should be based on matching case path AND any associated value, so needs more specificity. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Describe the bug
When using NavigationLink inside Foreach this log message prints to console. The navigation works but it seems this can cause problems future swiftui versions?
To Reproduce
Environment
Beta Was this translation helpful? Give feedback.
All reactions