Last active
February 19, 2020 22:01
-
-
Save nixzhu/92a2eea9a2bb44233f3137960659474f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()) |
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
I found it's a beta bug when I learn https://designcode.io/swiftui-modal-presentation