@capgo/inappbrowser 6.9.38 → 6.10.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -7,5 +7,6 @@
7
7
  <data android:scheme="http" />
8
8
  </intent>
9
9
  </queries>
10
+ <uses-permission android:name="android.permission.READ_MEDIA_IMAGES"/>
10
11
  <uses-permission android:name="android.permission.CAMERA"/>
11
12
  </manifest>
@@ -38,6 +38,7 @@ import android.widget.TextView;
38
38
  import android.widget.Toast;
39
39
  import android.widget.Toolbar;
40
40
  import androidx.annotation.RequiresApi;
41
+ import androidx.core.view.WindowInsetsControllerCompat;
41
42
  import com.caverock.androidsvg.SVG;
42
43
  import com.caverock.androidsvg.SVGParseException;
43
44
  import com.getcapacitor.JSObject;
@@ -132,6 +133,21 @@ public class WebViewDialog extends Dialog {
132
133
  // Handle message from JavaScript
133
134
  _options.getCallbacks().javascriptCallback(message);
134
135
  }
136
+
137
+ @JavascriptInterface
138
+ public void close() {
139
+ // close webview
140
+ activity.runOnUiThread(
141
+ new Runnable() {
142
+ @Override
143
+ public void run() {
144
+ dismiss();
145
+ _options.getCallbacks().closeEvent(_webView.getUrl());
146
+ _webView.destroy();
147
+ }
148
+ }
149
+ );
150
+ }
135
151
  }
136
152
 
137
153
  public class PreShowScriptInterface {
@@ -163,6 +179,17 @@ public class WebViewDialog extends Dialog {
163
179
  WindowManager.LayoutParams.FLAG_FULLSCREEN
164
180
  );
165
181
  setContentView(R.layout.activity_browser);
182
+ getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
183
+
184
+ WindowInsetsControllerCompat insetsController =
185
+ new WindowInsetsControllerCompat(getWindow(), getWindow().getDecorView());
186
+ insetsController.setAppearanceLightStatusBars(false);
187
+ getWindow()
188
+ .getDecorView()
189
+ .post(() -> {
190
+ getWindow().setStatusBarColor(Color.BLACK);
191
+ });
192
+
166
193
  getWindow()
167
194
  .setLayout(
168
195
  WindowManager.LayoutParams.MATCH_PARENT,
@@ -318,6 +345,9 @@ public class WebViewDialog extends Dialog {
318
345
  " if (window.AndroidInterface) { " +
319
346
  " window.AndroidInterface.postMessage(JSON.stringify(message)); " +
320
347
  " } " +
348
+ " }, " +
349
+ " close: function() { " +
350
+ " window.AndroidInterface.close(); " +
321
351
  " } " +
322
352
  " }; " +
323
353
  "}";
@@ -487,7 +517,7 @@ public class WebViewDialog extends Dialog {
487
517
  }
488
518
  );
489
519
 
490
- View closeButton = _toolbar.findViewById(R.id.closeButton);
520
+ ImageButton closeButton = _toolbar.findViewById(R.id.closeButton);
491
521
  closeButton.setOnClickListener(
492
522
  new View.OnClickListener() {
493
523
  @Override
@@ -520,7 +550,7 @@ public class WebViewDialog extends Dialog {
520
550
  );
521
551
 
522
552
  if (_options.showArrow()) {
523
- closeButton.setBackgroundResource(R.drawable.arrow_forward_enabled);
553
+ closeButton.setImageResource(R.drawable.arrow_back_enabled);
524
554
  }
525
555
 
526
556
  if (_options.getShowReloadButton()) {
@@ -1031,6 +1061,8 @@ public class WebViewDialog extends Dialog {
1031
1061
  ) {
1032
1062
  _webView.goBack();
1033
1063
  } else if (!_options.getDisableGoBackOnNativeApplication()) {
1064
+ _options.getCallbacks().closeEvent(_webView.getUrl());
1065
+ _webView.destroy();
1034
1066
  super.onBackPressed();
1035
1067
  }
1036
1068
  }
@@ -23,7 +23,23 @@ extension UIColor {
23
23
  * here: https://capacitorjs.com/docs/plugins/ios
24
24
  */
25
25
  @objc(InAppBrowserPlugin)
26
- public class InAppBrowserPlugin: CAPPlugin {
26
+ public class InAppBrowserPlugin: CAPPlugin, CAPBridgedPlugin {
27
+ public let identifier = "InAppBrowserPlugin"
28
+ public let jsName = "InAppBrowser"
29
+ public let pluginMethods: [CAPPluginMethod] = [
30
+ CAPPluginMethod(name: "open", returnType: CAPPluginReturnPromise),
31
+ CAPPluginMethod(name: "openWebView", returnType: CAPPluginReturnPromise),
32
+ CAPPluginMethod(name: "clearCookies", returnType: CAPPluginReturnPromise),
33
+ CAPPluginMethod(name: "getCookies", returnType: CAPPluginReturnPromise),
34
+ CAPPluginMethod(name: "clearAllCookies", returnType: CAPPluginReturnPromise),
35
+ CAPPluginMethod(name: "clearCache", returnType: CAPPluginReturnPromise),
36
+ CAPPluginMethod(name: "reload", returnType: CAPPluginReturnPromise),
37
+ CAPPluginMethod(name: "setUrl", returnType: CAPPluginReturnPromise),
38
+ CAPPluginMethod(name: "show", returnType: CAPPluginReturnPromise),
39
+ CAPPluginMethod(name: "close", returnType: CAPPluginReturnPromise),
40
+ CAPPluginMethod(name: "executeScript", returnType: CAPPluginReturnPromise),
41
+ CAPPluginMethod(name: "postMessage", returnType: CAPPluginReturnPromise)
42
+ ]
27
43
  var navigationWebViewController: UINavigationController?
28
44
  private var privacyScreen: UIImageView?
29
45
  private var isSetupDone = false
@@ -196,9 +212,8 @@ public class InAppBrowserPlugin: CAPPlugin {
196
212
 
197
213
  DispatchQueue.main.async {
198
214
  let url = URL(string: urlString)
199
-
200
215
  if self.isPresentAfterPageLoad {
201
- self.webViewController = WKWebViewController.init(url: url!, headers: headers, isInspectable: isInspectable, credentials: credentials, preventDeeplink: preventDeeplink)
216
+ self.webViewController = WKWebViewController.init(url: url!, headers: headers, isInspectable: isInspectable, credentials: credentials, preventDeeplink: preventDeeplink, blankNavigationTab: toolbarType == "blank")
202
217
  } else {
203
218
  self.webViewController = WKWebViewController.init()
204
219
  self.webViewController?.setHeaders(headers: headers)
@@ -241,6 +256,7 @@ public class InAppBrowserPlugin: CAPPlugin {
241
256
  self.navigationWebViewController?.modalPresentationStyle = .fullScreen
242
257
  if toolbarType == "blank" {
243
258
  self.navigationWebViewController?.navigationBar.isHidden = true
259
+ self.webViewController?.blankNavigationTab = true
244
260
  }
245
261
  if showReloadButton {
246
262
  let toolbarItems = self.getToolbarItems(toolbarType: toolbarType)
@@ -289,8 +305,10 @@ public class InAppBrowserPlugin: CAPPlugin {
289
305
  call.reject("Cannot get script to execute")
290
306
  return
291
307
  }
292
- self.webViewController?.executeScript(script: script)
293
- call.resolve()
308
+ DispatchQueue.main.async {
309
+ self.webViewController?.executeScript(script: script)
310
+ call.resolve()
311
+ }
294
312
  }
295
313
 
296
314
  @objc func postMessage(_ call: CAPPluginCall) {
@@ -302,7 +320,9 @@ public class InAppBrowserPlugin: CAPPlugin {
302
320
  }
303
321
  print("Event data: \(eventData)")
304
322
 
305
- self.webViewController?.postMessageToJS(message: eventData)
323
+ DispatchQueue.main.async {
324
+ self.webViewController?.postMessageToJS(message: eventData)
325
+ }
306
326
  call.resolve()
307
327
  }
308
328
 
@@ -75,6 +75,16 @@ open class WKWebViewController: UIViewController, WKScriptMessageHandler {
75
75
  self.setPreventDeeplink(preventDeeplink: preventDeeplink)
76
76
  self.initWebview(isInspectable: isInspectable)
77
77
  }
78
+
79
+ public init(url: URL, headers: [String: String], isInspectable: Bool, credentials: WKWebViewCredentials? = nil, preventDeeplink: Bool, blankNavigationTab: Bool) {
80
+ super.init(nibName: nil, bundle: nil)
81
+ self.blankNavigationTab = blankNavigationTab
82
+ self.source = .remote(url)
83
+ self.credentials = credentials
84
+ self.setHeaders(headers: headers)
85
+ self.setPreventDeeplink(preventDeeplink: preventDeeplink)
86
+ self.initWebview(isInspectable: isInspectable)
87
+ }
78
88
 
79
89
  open var hasDynamicTitle = false
80
90
  open var source: WKWebSource?
@@ -101,6 +111,7 @@ open class WKWebViewController: UIViewController, WKScriptMessageHandler {
101
111
  open var ignoreUntrustedSSLError = false
102
112
  var viewWasPresented = false
103
113
  var preventDeeplink: Bool = false
114
+ var blankNavigationTab: Bool = false;
104
115
 
105
116
  internal var preShowSemaphore: DispatchSemaphore?
106
117
  internal var preShowError: String?
@@ -239,7 +250,9 @@ open class WKWebViewController: UIViewController, WKScriptMessageHandler {
239
250
  if let jsonData = try? JSONSerialization.data(withJSONObject: message, options: []),
240
251
  let jsonString = String(data: jsonData, encoding: .utf8) {
241
252
  let script = "window.dispatchEvent(new CustomEvent('messageFromNative', { detail: \(jsonString) }));"
242
- webView?.evaluateJavaScript(script, completionHandler: nil)
253
+ DispatchQueue.main.async {
254
+ self.webView?.evaluateJavaScript(script, completionHandler: nil)
255
+ }
243
256
  }
244
257
  }
245
258
 
@@ -267,6 +280,8 @@ open class WKWebViewController: UIViewController, WKScriptMessageHandler {
267
280
  }
268
281
  print("[InAppBrowser - preShowScriptError]: Error!!!!")
269
282
  semaphore.signal()
283
+ } else if message.name == "close" {
284
+ closeView()
270
285
  }
271
286
  }
272
287
 
@@ -278,6 +293,9 @@ open class WKWebViewController: UIViewController, WKScriptMessageHandler {
278
293
  if (window.webkit && window.webkit.messageHandlers && window.webkit.messageHandlers.messageHandler) {
279
294
  window.webkit.messageHandlers.messageHandler.postMessage(message);
280
295
  }
296
+ },
297
+ close: function() {
298
+ window.webkit.messageHandlers.close.postMessage(null);
281
299
  }
282
300
  };
283
301
  }
@@ -288,7 +306,6 @@ open class WKWebViewController: UIViewController, WKScriptMessageHandler {
288
306
  }
289
307
 
290
308
  open func initWebview(isInspectable: Bool = true) {
291
-
292
309
  self.view.backgroundColor = UIColor.white
293
310
 
294
311
  self.extendedLayoutIncludesOpaqueBars = true
@@ -299,8 +316,9 @@ open class WKWebViewController: UIViewController, WKScriptMessageHandler {
299
316
  userContentController.add(self, name: "messageHandler")
300
317
  userContentController.add(self, name: "preShowScriptError")
301
318
  userContentController.add(self, name: "preShowScriptSuccess")
302
- webConfiguration.userContentController = userContentController
319
+ userContentController.add(self, name: "close")
303
320
  webConfiguration.allowsInlineMediaPlayback = true
321
+ webConfiguration.userContentController = userContentController
304
322
  let webView = WKWebView(frame: .zero, configuration: webConfiguration)
305
323
 
306
324
  if webView.responds(to: Selector(("setInspectable:"))) {
@@ -308,6 +326,20 @@ open class WKWebViewController: UIViewController, WKScriptMessageHandler {
308
326
  webView.perform(Selector(("setInspectable:")), with: isInspectable)
309
327
  }
310
328
 
329
+ if (self.blankNavigationTab) {
330
+ // First add the webView to view hierarchy
331
+ self.view.addSubview(webView)
332
+
333
+ // Then set up constraints
334
+ webView.translatesAutoresizingMaskIntoConstraints = false
335
+ NSLayoutConstraint.activate([
336
+ webView.topAnchor.constraint(equalTo: self.view.safeAreaLayoutGuide.topAnchor),
337
+ webView.leadingAnchor.constraint(equalTo: self.view.leadingAnchor),
338
+ webView.trailingAnchor.constraint(equalTo: self.view.trailingAnchor),
339
+ webView.bottomAnchor.constraint(equalTo: self.view.bottomAnchor)
340
+ ])
341
+ }
342
+
311
343
  webView.uiDelegate = self
312
344
  webView.navigationDelegate = self
313
345
 
@@ -319,9 +351,10 @@ open class WKWebViewController: UIViewController, WKScriptMessageHandler {
319
351
  webView.addObserver(self, forKeyPath: titleKeyPath, options: .new, context: nil)
320
352
  }
321
353
  webView.addObserver(self, forKeyPath: #keyPath(WKWebView.url), options: .new, context: nil)
322
- // NotificationCenter.default.addObserver(self, selector: #selector(restateViewHeight), name: UIDevice.orientationDidChangeNotification, object: nil)
323
354
 
324
- self.view = webView
355
+ if (!self.blankNavigationTab) {
356
+ self.view = webView
357
+ }
325
358
  self.webView = webView
326
359
 
327
360
  self.webView?.customUserAgent = self.customUserAgent ?? self.userAgent ?? self.originalUserAgent
@@ -796,7 +829,6 @@ fileprivate extension WKWebViewController {
796
829
  self.present(alert, animated: true, completion: nil)
797
830
  } else {
798
831
  let activityViewController = UIActivityViewController(activityItems: items, applicationActivities: nil)
799
- #imageLiteral(resourceName: "simulator_screenshot_B8B44B8D-EB30-425C-9BF4-1F37697A8459.png")
800
832
  activityViewController.setValue(self.shareSubject ?? self.title, forKey: "subject")
801
833
  activityViewController.popoverPresentationController?.barButtonItem = (sender as! UIBarButtonItem)
802
834
  self.present(activityViewController, animated: true, completion: nil)
@@ -839,7 +871,16 @@ fileprivate extension WKWebViewController {
839
871
 
840
872
  // MARK: - WKUIDelegate
841
873
  extension WKWebViewController: WKUIDelegate {
842
-
874
+ public func webView(_ webView: WKWebView, runJavaScriptAlertPanelWithMessage message: String, initiatedByFrame frame: WKFrameInfo, completionHandler: @escaping () -> Void) {
875
+ // Ensure UI updates are on the main thread
876
+ DispatchQueue.main.async {
877
+ let alertController = UIAlertController(title: nil, message: message, preferredStyle: .alert)
878
+ alertController.addAction(UIAlertAction(title: "OK", style: .default, handler: { _ in
879
+ completionHandler()
880
+ }))
881
+ self.present(alertController, animated: true, completion: nil)
882
+ }
883
+ }
843
884
  }
844
885
 
845
886
  // MARK: - WKNavigationDelegate
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@capgo/inappbrowser",
3
- "version": "6.9.38",
3
+ "version": "6.10.0",
4
4
  "description": "Capacitor plugin in app browser",
5
5
  "main": "dist/plugin.cjs.js",
6
6
  "module": "dist/esm/index.js",
@@ -1,10 +0,0 @@
1
- #import <UIKit/UIKit.h>
2
-
3
- //! Project version number for Plugin.
4
- FOUNDATION_EXPORT double PluginVersionNumber;
5
-
6
- //! Project version string for Plugin.
7
- FOUNDATION_EXPORT const unsigned char PluginVersionString[];
8
-
9
- // In this header, you should import all the public headers of your framework using statements like #import <Plugin/PublicHeader.h>
10
-
@@ -1,21 +0,0 @@
1
- #import <Foundation/Foundation.h>
2
- #import <Capacitor/Capacitor.h>
3
-
4
- // Define the plugin using the CAP_PLUGIN Macro, and
5
- // each method the plugin supports using the CAP_PLUGIN_METHOD macro.
6
- CAP_PLUGIN(InAppBrowserPlugin, "InAppBrowser",
7
- CAP_PLUGIN_METHOD(openWebView, CAPPluginReturnPromise);
8
- CAP_PLUGIN_METHOD(clearCookies, CAPPluginReturnPromise);
9
- CAP_PLUGIN_METHOD(getCookies, CAPPluginReturnPromise);
10
- CAP_PLUGIN_METHOD(clearAllCookies, CAPPluginReturnPromise);
11
- CAP_PLUGIN_METHOD(clearCache, CAPPluginReturnPromise);
12
- CAP_PLUGIN_METHOD(reload, CAPPluginReturnPromise);
13
- CAP_PLUGIN_METHOD(open, CAPPluginReturnPromise);
14
- CAP_PLUGIN_METHOD(setUrl, CAPPluginReturnPromise);
15
- CAP_PLUGIN_METHOD(show, CAPPluginReturnPromise);
16
- CAP_PLUGIN_METHOD(close, CAPPluginReturnPromise);
17
- CAP_PLUGIN_METHOD(hide, CAPPluginReturnPromise);
18
- CAP_PLUGIN_METHOD(executeScript, CAPPluginReturnPromise);
19
- CAP_PLUGIN_METHOD(postMessage, CAPPluginReturnPromise);
20
- CAP_PLUGIN_METHOD(insertCSS, CAPPluginReturnPromise);
21
- )