Skip to content

feat: add isInspectable and isAnimated properties to OpenWebViewOptions #97

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

Merged
merged 2 commits into from
Dec 31, 2023
Merged
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
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,8 @@ Reload the current web page.
| **`title`** | <code>string</code> | Title of the browser | <code>'New Window'</code> | 0.1.0 |
| **`backgroundColor`** | <code><a href="#backgroundcolor">BackgroundColor</a></code> | Background color of the browser, only on IOS | <code>BackgroundColor.BLACK</code> | 0.1.0 |
| **`isPresentAfterPageLoad`** | <code>boolean</code> | Open url in a new window fullscreen isPresentAfterPageLoad: if true, the browser will be presented after the page is loaded, if false, the browser will be presented immediately. | <code>false</code> | 0.1.0 |
| **`isInspectable`** | <code>boolean</code> | Whether the website in the webview is inspectable or not, ios only | <code>false</code> | |
| **`isAnimated`** | <code>boolean</code> | Whether the webview opening is animated or not, ios only | <code>true</code> | |
| **`showReloadButton`** | <code>boolean</code> | Shows a reload button that reloads the web page | <code>false</code> | 1.0.15 |
| **`closeModal`** | <code>boolean</code> | CloseModal: if true a confirm will be displayed when user clicks on close button, if false the browser will be closed immediately. | <code>false</code> | 1.1.0 |
| **`closeModalTitle`** | <code>string</code> | CloseModalTitle: title of the confirm when user clicks on close button, only on IOS | <code>'Close'</code> | 1.1.0 |
Expand Down
14 changes: 9 additions & 5 deletions ios/Plugin/InAppBrowserPlugin.swift
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ public class InAppBrowserPlugin: CAPPlugin {
#endif
}

func presentView() {
self.bridge?.viewController?.present(self.navigationWebViewController!, animated: true, completion: {
func presentView(isAnimated: Bool = true) {
self.bridge?.viewController?.present(self.navigationWebViewController!, animated: isAnimated, completion: {
self.currentPluginCall?.resolve()
})
}
Expand Down Expand Up @@ -76,6 +76,8 @@ public class InAppBrowserPlugin: CAPPlugin {
let closeModalDescription = call.getString("closeModalDescription", "Are you sure you want to close this window?")
let closeModalOk = call.getString("closeModalOk", "OK")
let closeModalCancel = call.getString("closeModalCancel", "Cancel")
let isInspectable = call.getBool("isInspectable", false)
let isAnimated = call.getBool("isAnimated", true)

var disclaimerContent = call.getObject("shareDisclaimer")
let toolbarType = call.getString("toolbarType", "")
Expand All @@ -91,7 +93,7 @@ public class InAppBrowserPlugin: CAPPlugin {
let url = URL(string: urlString)

if self.isPresentAfterPageLoad {
self.webViewController = WKWebViewController.init(url: url!, headers: headers)
self.webViewController = WKWebViewController.init(url: url!, headers: headers, isInspectable: isInspectable)
} else {
self.webViewController = WKWebViewController.init()
self.webViewController?.setHeaders(headers: headers)
Expand Down Expand Up @@ -132,7 +134,7 @@ public class InAppBrowserPlugin: CAPPlugin {
self.webViewController?.leftNavigaionBarItemTypes = toolbarItems + [.reload]
}
if !self.isPresentAfterPageLoad {
self.presentView()
self.presentView(isAnimated: isAnimated)
}
}
}
Expand Down Expand Up @@ -183,6 +185,8 @@ public class InAppBrowserPlugin: CAPPlugin {
self.setup()
}

let isInspectable = call.getBool("isInspectable", false)

self.currentPluginCall = call

guard let urlString = call.getString("url") else {
Expand All @@ -203,7 +207,7 @@ public class InAppBrowserPlugin: CAPPlugin {
let url = URL(string: urlString)

if self.isPresentAfterPageLoad {
self.webViewController = WKWebViewController.init(url: url!, headers: headers)
self.webViewController = WKWebViewController.init(url: url!, headers: headers, isInspectable: isInspectable)
} else {
self.webViewController = WKWebViewController.init()
self.webViewController?.setHeaders(headers: headers)
Expand Down
10 changes: 7 additions & 3 deletions ios/Plugin/WKWebViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,11 @@ open class WKWebViewController: UIViewController {
self.initWebview()
}

public init(url: URL, headers: [String: String]) {
public init(url: URL, headers: [String: String], isInspectable: Bool) {
super.init(nibName: nil, bundle: nil)
self.source = .remote(url)
self.setHeaders(headers: headers)
self.initWebview()
self.initWebview(isInspectable: isInspectable)
}

open var hasDynamicTitle = false
Expand Down Expand Up @@ -206,7 +206,7 @@ open class WKWebViewController: UIViewController {
}
}

open func initWebview() {
open func initWebview(isInspectable: Bool = true) {

self.view.backgroundColor = UIColor.white

Expand All @@ -216,6 +216,10 @@ open class WKWebViewController: UIViewController {
let webConfiguration = WKWebViewConfiguration()
let webView = WKWebView(frame: .zero, configuration: webConfiguration)

if #available(iOS 16.4, *) {
webView.isInspectable = isInspectable
}

webView.uiDelegate = self
webView.navigationDelegate = self

Expand Down
14 changes: 13 additions & 1 deletion src/definitions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ export interface OpenWebViewOptions {
* @since 0.1.0
* @default 'New Window'
*/
title: string;
title?: string;
/**
* Background color of the browser, only on IOS
* @since 0.1.0
Expand All @@ -108,6 +108,18 @@ export interface OpenWebViewOptions {
* @default false
*/
isPresentAfterPageLoad?: boolean;
/**
* Whether the website in the webview is inspectable or not, ios only
*
* @default false
*/
isInspectable?: boolean;
/**
* Whether the webview opening is animated or not, ios only
*
* @default true
*/
isAnimated?: boolean;
/**
* Shows a reload button that reloads the web page
* @since 1.0.15
Expand Down