johnpatrickmorgan / FlowStacks

FlowStacks allows you to hoist SwiftUI navigation and presentation state into a Coordinator
MIT License
854 stars 66 forks source link

withDelaysIfUnsupported from viewModel #17

Closed kgrigsby-codesmith closed 2 years ago

kgrigsby-codesmith commented 2 years ago

Is it possible to use withDelaysIfUnsupported within a view model? I have "@Published var routes: Routes = []" defined in my view model. $routes gives me back a publisher and so withDelaysIfUnsupported is not found.

johnpatrickmorgan commented 2 years ago

Hi, thanks for raising this. I hadn't considered that use case. It's possible to access withDelaysIfUnsupported if you create a Binding from the variable, e.g.:

Binding(get: { self.routes }, set: { self.routes = $0 })
  .withDelaysIfUnsupported { ... }

But it seems like there should be a less awkward way of achieving this.

kgrigsby-codesmith commented 2 years ago

Thanks, I did use that Binding trick. Then I ran into the other issue of calculateSteps returning empty when the screens were only different by their associated values.

johnpatrickmorgan commented 2 years ago

I've added a slightly friendlier way of achieving this in a view model in v0.1.6:

RouteSteps.withDelaysIfUnsupported(self, \.routes) {
  $0.push(...)
  $0.push(...)
  $0.presentSheet(...)
}

Thanks for bringing attention to this.