Cap-go / capacitor-inappbrowser

Capacitor plugin in app browser with urlChangeEvent
MIT License
66 stars 48 forks source link

Show a confirmation message before closing the browser #71

Closed valyefimov closed 10 months ago

valyefimov commented 1 year ago

Thank you for all the work you've done.

Could you expand the configuration and add the ability to show a confirmation message before closing the browser?

Something like

    @objc func doneDidClick(sender: AnyObject) {
        let alert = UIAlertController(title: "Confirm Close", message: "Are you sure you want to close web browser?", preferredStyle: .alert)
        alert.addAction(UIAlertAction(title: "No", style: .cancel, handler: nil))
        alert.addAction(UIAlertAction(title: "Yes", style: .default, handler: { _ in
            var canDismiss = true

            if let url = self.source?.url {
                canDismiss = self.delegate?.webViewController?(self, canDismiss: url) ?? true
            }

            if canDismiss {
                self.capBrowserPlugin?.notifyListeners("closeEvent", data: ["url": self.webView?.url?.absoluteString ?? ""])
                self.dismiss(animated: true, completion: nil)
            }
        }))

        self.present(alert, animated: true, completion: nil)
    }

Thanks in advance

riderx commented 1 year ago

This should work for both Android and IOS. As optional for method openWebView. The title, description and button text should be given in params from JS