Skip to content

Instantly share code, notes, and snippets.

@laevandus
Created March 5, 2022 00:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save laevandus/2307c0f99063ca20d7ecd2330e7c4e1e to your computer and use it in GitHub Desktop.
Save laevandus/2307c0f99063ca20d7ecd2330e7c4e1e to your computer and use it in GitHub Desktop.
final class FlowCoordinator: ObservableObject {
// …
func showDetailView() {
let detailView = DetailView()
.environmentObject(self)
let viewController = UIHostingController(rootView: detailView)
window.rootViewController?.present(viewController, animated: true, completion: nil)
}
func closeDetailView() {
// Needs to be more sophisticated later when there are more views
window.rootViewController?.presentedViewController?.dismiss(animated: true, completion: nil)
}
}
struct DetailView: View {
@EnvironmentObject var flowController: FlowCoordinator
var body: some View {
VStack(spacing: 8) {
Text("Detail view content")
Button("Dismiss", action: flowController.closeDetailView)
}.frame(maxWidth: .infinity, maxHeight: .infinity)
.background(.orange)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment