johnpatrickmorgan / FlowStacks

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

The closed issue (No way to know when a sheet is dismissed #14) resurfaced #78

Closed DeanFs closed 4 months ago

DeanFs commented 4 months ago

The issue No way to know when a sheet is dismissed resurfaced after the this commit: Rewrites FlowStacks APIs.

This issue is not fixed in the latest version. Will the onDismiss closure be supported again in a future release. Or is there any other way to achieve the same effect. Thank you so much for providing such an excellent library!

johnpatrickmorgan commented 4 months ago

Hi @DeanFs , thanks for raising this issue. It's possible to detect dismissals by adding an onChange modifier, e.g.:

.onChange(of: routes) { [oldRoutes = routes] newRoutes in
  let dismissedRoutes = oldRoutes.suffix(from: min(oldRoutes.endIndex, newRoutes.endIndex))
  guard !dismissedRoutes.isEmpty else { return }
  print("dismissed:", dismissedRoutes.map { $0.screen })
}

This has the advantage of working for all forms of navigation, e.g. push/pop navigation too. Does that work for your use case?