stleamist / BetterSafariView

A better way to present a SFSafariViewController or start a ASWebAuthenticationSession in SwiftUI.
MIT License
581 stars 57 forks source link

How to dismiss programatically? #14

Open OrkhanAlikhanov opened 3 years ago

OrkhanAlikhanov commented 3 years ago

How can I dismiss the view controller programmatically? Following minimal example does not work:

struct MyView: View {
  @State var showView = false

  var body: some View {
    let _ = print("current value: \(showView)")

    Button("Show it") {
      print("showing it")
      showView = true
      DispatchQueue.main.asyncAfter(deadline: .now() + 2) {
        print("hiding it")
        showView = false
      }
    }
      .safariView(isPresented: $showView) {
        SafariView(url: URL(string: "https://www.google.com")!)
      }
  }
}

Log:

current value: false
showing it
current value: true
hiding it
current value: false

According to my debugging, view modifier does not detect that the value of the binding changed, this might be related: https://stackoverflow.com/questions/59299260/swiftui-binding-update-doesnt-refresh-view

RuiAAPeres commented 3 years ago

I am having the same issue. Were you able to find a solution?

OrkhanAlikhanov commented 3 years ago

I resorted to presenting SFSafariController and managing it myself for this particular case