-
Hello, I recently upgraded to version 1.4.0 of this library, and I am receiving warnings about deprecations of some overloaded navigation methods, e.g.: Warning
.sheet(
unwrapping: $viewModel.route,
case: /SomeViewModel.Route.contactSupport
) { _ in
FeedbackView(source: .someView)
} Previously to v1.4.0, I wasn't using @CasePathable
enum Route {
case alert(AlertState<AlertAction>)
case register
case serviceError(ServiceError)
case contactSupport
case dismiss
} Updating navigation view modifiers to use the new overloads leads to a problem if the enum case doesn't have any associated value: Caution
.sheet(
item: $viewModel.route.contactSupport
) { _ in
FeedbackView(source: .someView)
} That can be fixed by adding an argument Caution
.sheet(
item: $viewModel.route.contactSupport, id: \.self
) { _ in
FeedbackView(source: .someView)
} And, yeah, that's where I am now. Am I doing something wrong here, or am I missing something obvious? I tried adding custom overloads of I tried looking through all the sample code and case studies, but I couldn't find any place where navigation is done using an enum case without an associated value. Should I not be doing it this way, perhaps? 🤔 Any pointers or feedback is greatly appreciated. Viktor PS. I'm a subscriber of Point-Free and have been for years, love the work you guys do! ❤️ |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 8 replies
-
Alright, so, after talking a walk and clearing my head for a bit, I came up with the following solution/workaround: .sheet(
isPresented: Binding(
get: { viewModel.route.is(\.contactSupport) },
set: { _ in viewModel.route = nil }
)
) {
FeedbackView(source: .someView)
} I suppose this could be made prettier by adding an extension method on Edit: I think an extension looking like this might be the way to go: extension View {
func sheet(
item: Binding<Void?>,
content: @escaping () -> some View
) -> some View {
sheet(
isPresented: Binding(
get: { item.wrappedValue != nil },
set: { _ in item.wrappedValue = nil }
),
content: content
)
}
} It can be used like this: .sheet(item: $viewModel.route.contactSupport) {
FeedbackView(source: .someView)
} |
Beta Was this translation helpful? Give feedback.
Hi @vrutberg, there is a simpler solution to your problem. You can use the
isPresented
variant ofsheet
, along with theBinding
initializer that turns aBinding<T?>
into aBinding<Bool>
:Can you try that out?