Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to dismiss programatically? #14

Open
OrkhanAlikhanov opened this issue Feb 8, 2021 · 2 comments
Open

How to dismiss programatically? #14

OrkhanAlikhanov opened this issue Feb 8, 2021 · 2 comments

Comments

@OrkhanAlikhanov
Copy link

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
Copy link

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

@OrkhanAlikhanov
Copy link
Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants