3

Is it possible to disable the pull down dismissal gesture of SFSafariViewController?

It seems like the SFSafariViewController runs in its own window, hence, setting isModalInPresentation or even setting the presentationControllerShouldDismiss(_:) doesn't seem to do anything.

The SFSafariViewController docs don't seem to specify anything here either.

MWE:

import SafariServices
import UIKit

class ViewController: UIViewController, UIAdaptivePresentationControllerDelegate {
    override func viewDidLoad() {
        super.viewDidLoad()

        DispatchQueue.main.asyncAfter(deadline: .now() + 0.5) {
           let vc = SFSafariViewController(url: URL(string: "https://stackoverflow.com")!)
            vc.modalPresentationStyle = .pageSheet
            // `presentationControllerShouldDismiss` will be ignored, if isModalInPresentation is set to `true`
            // vc.isModalInPresentation = true
            vc.presentationController?.delegate = self

            self.present(vc, animated: true)
        }
    }

    func presentationControllerShouldDismiss(_ presentationController: UIPresentationController) -> Bool {
        return false
    }

    func presentationControllerDidDismiss(_ presentationController: UIPresentationController) {
        NSLog("Did dismiss")
    }
}
Martin Dinh
  • 213
  • 1
  • 8
  • have you tried `vc.isModalInPresentation = true` – Jawad Ali Aug 10 '20 at 15:03
  • @jawadAli Yes. It’s commented in the MWE. – Martin Dinh Aug 10 '20 at 15:21
  • There is a difference, if the `UIViewController` is embedded in the `UINavigationCController`: https://contagious.dev/blog/modal-uinavigationcontroller-ios-13-dismiss-detection-uiadaptivepresentationcontrollerdelegate/. However, this is not the case for `SFSafariViewController`. – Martin Dinh Aug 11 '20 at 11:38

0 Answers0