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())
@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