BetterSafariView icon indicating copy to clipboard operation
BetterSafariView copied to clipboard

How to dismiss programatically?

Open OrkhanAlikhanov opened this issue 3 years ago • 2 comments

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

OrkhanAlikhanov avatar Feb 08 '21 12:02 OrkhanAlikhanov

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

RuiAAPeres avatar Mar 29 '21 17:03 RuiAAPeres

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

OrkhanAlikhanov avatar Mar 29 '21 20:03 OrkhanAlikhanov