-
In my little app, I am trying to show an edit screen. The model of the screen that hosts to button to drill down to that view has a .navigationDestination(
unwrapping: $model.destination,
case: /VocabularySetDetailViewModel.Destination.edit
) { $editModel in
VocabularyAddEditView(model: editModel)
.navigationBarBackButtonHidden(true)
.toolbar {
ToolbarItem(placement: .confirmationAction) {
Button {
model.destination = nil
} label: {
Text("Confirm")
}
}
ToolbarItem(placement: .cancellationAction) {
Button {
model.destination = nil
} label: {
Text("Cancel")
}
}
}
} For now, I am just setting destination to nil in both cancellation and confirmation button, expecting to get back to the host screen. When I now drill down to an item again that I want to edit, neither the cancellation nor the confirmation button work. I can see that destination is set to nil when tapping either button by observing it in I know the above code is really only a small part of the app, but I hope that this might be a common/known thing that someone recognises... Anyways, you can see what's happening in below animated gif. |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments
-
This is a bug in SwiftUI and something we discussed in episode 217 (at 23:39). If you simply In order to make use of the hack workaround I think you need to wrap |
Beta Was this translation helpful? Give feedback.
-
Also I don't think this is an issue with the library, but rather an existing Apple bug. We've filed a bunch of Feedbacks for these bugs, and we encourage you to do the same. So, I'm going to convert this to a discussion and we can continue the conversation over there. |
Beta Was this translation helpful? Give feedback.
-
Awesome, thanks a lot! I was pretty confident that I am overlooking something, I have to admitted I have not taken the time to watch the whole series beginning to end. Started to catch up with that by restarting with episode 214. Thanks for your concise and fast reply! Also, I didn't know about discussions–thanks for moving it here. Will take a look at the discussions first next time I should have an issue. |
Beta Was this translation helpful? Give feedback.
This is a bug in SwiftUI and something we discussed in episode 217 (at 23:39). If you simply
nil
out state driving anavigationDestination
it will not pop the screen off the stack. Typically you can work around by adding@Environment(\.dismiss)
to the child view, but that won't work directly for you since you are doing this directly in thenavigationDestination
content closure.In order to make use of the hack workaround I think you need to wrap
VocabularyAddEditView
+toolbars in a little view so that you get access to@Environment(\.dismiss)
for just that child view, and then invokedismiss()
when you writenil
to the state.