Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Replacement for Deprecated PresentationLink? (Xcode 11 beta 4)

Tags:

swiftui

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")
            }
        }
    }
like image 991
KRH Avatar asked Feb 03 '23 18:02

KRH


1 Answers

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

like image 94
Zain Avatar answered Feb 24 '23 16:02

Zain