Skip to content

Modals and Popovers #52

Answered by frzi
Arneoldenhave asked this question in Q&A
Mar 7, 2022 · 1 comments · 1 reply
Discussion options

You must be logged in to vote

Hello 👋

You can use .sheet() et al with SwiftUI Router. Though it does require a bit of code. There are multiple ways to tackle this. Here's a very crude example:

struct ContentView: View {
	@EnvironmentObject private var navigator: Navigator
	@State private var showModal = false

	var body: some View {
		VStack {
			NavLink(to: "/modal") {
				Text("Go to `/modal`")
			}
			NavLink(to: "/modal/some/deeper/path") {
				Text("Go to a deeper screen in the modal")
			}
		}
		.onChange(of: navigator.path) { newPath in
			showModal = newPath.starts(with: "/modal")
		}
		.onChange(of: showModal) { newShowModal in
			if !newShowModal {
				navigator.navigate("/")
			}
		}
		.sheet(isPresented: $…

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@Arneoldenhave
Comment options

Answer selected by Arneoldenhave
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants