In Xcode beta 4 using PresentationLink gives the following warning: "'PresentationLink' is deprecated: Use .sheet modifier instead."
I'm assuming they mean some form of
func sheet<Content>(isPresented: Binding<Bool>, onDismiss: (() -> Void)? = nil, content: @escaping () -> Content) -> some View where Content : View
but I'm not to sure how to switch to this - in particular, the isPresented
argument is confusing me. I know there's an Environment variable called isPresented, but isn't that for the current View, not the View that's going to be presented?
I'm mostly interested in this because I'm hoping this will fix the issue with PresentationLinks only working once (see swiftUI PresentaionLink does not work second time)
Can anyone supply a simple example of how to present a view now that PresentationLink is deprecated? E.g., convert the following to use the .sheet modifier:
NavigationView {
List {
PresentationLink(destination: Text("Destination View")) {
Text("Source View")
}
}
}
Below is an example that's as close as I could come to your example.
import SwiftUI
struct Testing : View {
@State var isPresented = false
var body: some View {
NavigationView {
List {
Button(action: { self.isPresented.toggle() })
{ Text("Source View") }
}
}.sheet(isPresented: $isPresented, content: { Text("Destination View") })
}
}
This does indeed seem to resolve the bug you referenced about PresentationLinks not working the second time
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With