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

feat: close webview from within #257

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,21 @@ public void postMessage(String message) {
// Handle message from JavaScript
_options.getCallbacks().javascriptCallback(message);
}

@JavascriptInterface
public void close() {
// close webview
activity.runOnUiThread(
new Runnable() {
@Override
public void run() {
dismiss();
_options.getCallbacks().closeEvent(_webView.getUrl());
_webView.destroy();
}
}
);
}
}

public class PreShowScriptInterface {
Expand Down
3 changes: 3 additions & 0 deletions ios/Plugin/WKWebViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,8 @@ open class WKWebViewController: UIViewController, WKScriptMessageHandler {
}
print("[InAppBrowser - preShowScriptError]: Error!!!!")
semaphore.signal()
} else if message.name == "close" {
closeView()
}
}

Expand Down Expand Up @@ -299,6 +301,7 @@ open class WKWebViewController: UIViewController, WKScriptMessageHandler {
userContentController.add(self, name: "messageHandler")
userContentController.add(self, name: "preShowScriptError")
userContentController.add(self, name: "preShowScriptSuccess")
userContentController.add(self, name: "close")
webConfiguration.userContentController = userContentController
let webView = WKWebView(frame: .zero, configuration: webConfiguration)

Expand Down