Replies: 2 comments 4 replies
-
To come from another angle (code taken from sample project 🔼), This version has the correct animation: struct ItemRowView: View {
@ObservedObject var viewModel: ItemRowViewModel
init(viewModel: ItemRowViewModel) {
self.viewModel = viewModel
}
var body: some View {
NavigationLink(value: viewModel.item) {
Text(viewModel.item.title)
}
.navigationDestination(for: Item.self) { item in
EditItemView(viewModel: .init(item: item))
.navigationTitle("Navigation Title")
}
}
} but this one (using the custom struct ItemRowView: View {
@ObservedObject var viewModel: ItemRowViewModel
init(viewModel: ItemRowViewModel) {
self.viewModel = viewModel
}
var body: some View {
Button {
viewModel.userTappedRow()
} label: {
Text(viewModel.item.title)
}
.buttonStyle(.borderless)
.navigationDestination(
unwrapping: $viewModel.route,
case: /ItemRowViewModel.Route.edit,
destination: { $editDayViewModel in
EditItemView(viewModel: editDayViewModel)
.navigationTitle("Navigation Title")
}
)
}
} All comments appreciated :) |
Beta Was this translation helpful? Give feedback.
-
Hi @iandundas! Unfortunately this looks like another Apple bug. Our Button {
viewModel.userTappedRow()
} label: {
Text(viewModel.item.title)
}
.buttonStyle(.borderless)
.navigationDestination(
isPresented: Binding(
get: {
guard case .edit = self.viewModel.route else { return false }
return true
},
set: { isPresented in
if !isPresented {
self.viewModel.route = nil
}
}
)
) {
if case let .edit(editDayViewModel) = self.viewModel.route {
EditItemView(viewModel: editDayViewModel)
.navigationTitle("Navigation Title")
}
} If you file a feedback, we'd be happy to duplicate and catalog it alongside the many other feedbacks we've filed for SwiftUI navigation issues: https://gist.github.com/mbrandonw/f8b94957031160336cac6898a919cbb7 |
Beta Was this translation helpful? Give feedback.
-
I'm having an issue with the navigation title animation using (I think and hope) the most basic but faithful SwiftUINavigation setup from the videos (though diverting from the videos by adopting
.navigationDestination(unwrapping:case:)
instead of the deprecatedNavigationLink(unwrapping:case:onNavigate:destination)
)Worth noting that this issue occurred for me only after switching from the deprecated
NavigationLink(unwrapping:case:onNavigate:destination)
, which didn't seem to have the issue.Here's the issue with slow-mo enabled:
Vanilla SwiftUI - the title animates in
CleanShot.2023-02-06.at.12.34.24.mp4
SwiftUINavigation - the title appears after animation completion
CleanShot.2023-02-06.at.12.27.00.mp4
There's a sample project to clone, but it's really just one file.
There are two
@main
, one is commented out, you can toggle them to see the effect:.navigationDestination(unwrapping:case:destination)
, but is visually the same.Both are a list with a row, where you navigate to a detail view.
One thought: Obviously the animation in the Standups demo app is not broken, but I can see that in StandupsList, there is no intermediate
StandupRowView
type (compared with the analogousItemRowView
from the previous navigation series that used NavigationLink, where the row itself is extracted and has its own ViewModel), so the.navigationDestination(unwrapping:case:)
was placed directly intoStandupsList
, further up the view hierarchy. Maybe that makes the difference.It's very likely my own mistake, but I cannot see it.
Thanks for your eyes,
Ian
Beta Was this translation helpful? Give feedback.
All reactions