Skip to content

Instantly share code, notes, and snippets.

@nixzhu
Last active February 19, 2020 22:01
Show Gist options
  • Save nixzhu/92a2eea9a2bb44233f3137960659474f to your computer and use it in GitHub Desktop.
Save nixzhu/92a2eea9a2bb44233f3137960659474f to your computer and use it in GitHub Desktop.
import PlaygroundSupport
import SwiftUI
struct DetailView: View {
@Environment(\.isPresented) var isPresented: Binding<Bool>?
@State var count = 0
var body: some View {
VStack(spacing: 20) {
Text("Count: \(count)")
Button(action: add) {
Text("Add")
}
if isPresented != nil {
Button(action: dismiss) {
Text("Dismiss")
}
}
}
}
func add() {
count += 1
}
func dismiss() {
isPresented?.value = false
}
}
struct ContentView: View {
var body: some View {
NavigationView {
VStack(spacing: 20) {
NavigationLink(destination: DetailView()) {
Text("Push")
}
PresentationLink(destination: DetailView()) {
Text("Present")
}
}
}
}
}
PlaygroundPage.current.liveView = UIHostingController(rootView: ContentView())
@nixzhu
Copy link
Author

nixzhu commented Jul 9, 2019

@Laszlo75 I have no idea.

@maundytime
Copy link

I found it's a beta bug when I learn https://designcode.io/swiftui-modal-presentation

Second Tap Issue
In the beta, when clicked a second time, it won't present the modal again.

@famictech2000
Copy link

Does this code still work!?

getting issue with:

@Environment(.isPresented) var isPresented: Binding?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment