Replies: 1 comment 4 replies
-
Hi @cheif, the reason the binding tools are tuned for optional state is because that gives us a natural way to dismiss a feature: you just write In your situation you want to present a sheet based off the It seems like a better way is to ditch the class ViewModel: ObservableObject {
@Published var state: State?
@CasePathable
enum State {
case list(ListViewModel)
case detail(DetailViewModel)
}
} And then the .sheet(item: $model.state.list) { model in
ListView(model: model)
} |
Beta Was this translation helpful? Give feedback.
4 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hey!
We're almost extensively using
swiftui-navigation
for handling navigation in our app, but recently we've come up with a use case where the tooling isn't 100% there yet, so I'd be interested to hear your opinions on:The model
In our app we're using the familiar pattern from Maps, using a
Map
with an overlayed list, which will switch to a detail view once something is selected. Previously we've used customUIKit
implementations for most things, but with the arrival ofpresentationDetents
we've made the jump to 100% SwiftUI.Our model looks something like this:
And similarly the view looks something like:
The thing that sticks out here is the manual creation of a
Binding
needed for the.sheet
, this is due to there's (currently) no support in the library for deriving bindings from non-optional state. (Unless I've completely missed it)Adding such a conformance is pretty simple:
and I imagine it could be written even cleaner if it was part of the library.
Question
So back to my questions, do you think the modeling above makes sense, or would there be a better way to solve it?
If the modeling makes sense, do you think this is something that would fit nicely in the scope of the library?
Beta Was this translation helpful? Give feedback.
All reactions