@capgo/capacitor-inappbrowser 8.6.16 → 8.6.17
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.
|
@@ -63,7 +63,7 @@ import org.json.JSONObject;
|
|
|
63
63
|
)
|
|
64
64
|
public class InAppBrowserPlugin extends Plugin implements WebViewDialog.PermissionHandler {
|
|
65
65
|
|
|
66
|
-
private final String pluginVersion = "8.6.
|
|
66
|
+
private final String pluginVersion = "8.6.17";
|
|
67
67
|
|
|
68
68
|
public static final String CUSTOM_TAB_PACKAGE_NAME = "com.android.chrome"; // Change when in stable
|
|
69
69
|
private CustomTabsClient customTabsClient;
|
|
@@ -77,7 +77,7 @@ public class InAppBrowserPlugin: CAPPlugin, CAPBridgedPlugin {
|
|
|
77
77
|
case aware = "AWARE"
|
|
78
78
|
case fakeVisible = "FAKE_VISIBLE"
|
|
79
79
|
}
|
|
80
|
-
private let pluginVersion: String = "8.6.
|
|
80
|
+
private let pluginVersion: String = "8.6.17"
|
|
81
81
|
public let identifier = "InAppBrowserPlugin"
|
|
82
82
|
public let jsName = "InAppBrowser"
|
|
83
83
|
public let pluginMethods: [CAPPluginMethod] = [
|
|
@@ -342,12 +342,18 @@ public class InAppBrowserPlugin: CAPPlugin, CAPBridgedPlugin {
|
|
|
342
342
|
return
|
|
343
343
|
}
|
|
344
344
|
|
|
345
|
+
dismissActiveKeyboard()
|
|
345
346
|
let presenter = self.bridge?.viewController?.presentedViewController ?? self.bridge?.viewController
|
|
346
347
|
presenter?.present(navigationController, animated: isAnimated, completion: {
|
|
347
348
|
self.currentPluginCall?.resolve()
|
|
348
349
|
})
|
|
349
350
|
}
|
|
350
351
|
|
|
352
|
+
private func dismissActiveKeyboard() {
|
|
353
|
+
self.bridge?.webView?.endEditing(true)
|
|
354
|
+
UIApplication.shared.sendAction(#selector(UIResponder.resignFirstResponder), to: nil, from: nil, for: nil)
|
|
355
|
+
}
|
|
356
|
+
|
|
351
357
|
private func activeWindow() -> UIWindow? {
|
|
352
358
|
return UIApplication.shared.connectedScenes
|
|
353
359
|
.compactMap { $0 as? UIWindowScene }
|
|
@@ -226,6 +226,16 @@ enum ConsoleMessageSupport {
|
|
|
226
226
|
}
|
|
227
227
|
}
|
|
228
228
|
|
|
229
|
+
enum WebViewViewportLayoutSupport {
|
|
230
|
+
static func shouldRefreshViewport(previousSize: CGSize?, currentSize: CGSize, force: Bool = false) -> Bool {
|
|
231
|
+
guard currentSize.width > 0, currentSize.height > 0 else {
|
|
232
|
+
return false
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
return force || previousSize != currentSize
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
|
|
229
239
|
open class WKWebViewController: UIViewController, WKScriptMessageHandler {
|
|
230
240
|
|
|
231
241
|
public init() {
|
|
@@ -343,9 +353,6 @@ open class WKWebViewController: UIViewController, WKScriptMessageHandler {
|
|
|
343
353
|
var shareDisclaimer: [String: Any]?
|
|
344
354
|
var shareSubject: String?
|
|
345
355
|
var didpageInit = false
|
|
346
|
-
var viewHeightLandscape: CGFloat?
|
|
347
|
-
var viewHeightPortrait: CGFloat?
|
|
348
|
-
var currentViewHeight: CGFloat?
|
|
349
356
|
open var closeModal = false
|
|
350
357
|
open var closeModalTitle = ""
|
|
351
358
|
open var closeModalDescription = ""
|
|
@@ -386,6 +393,8 @@ open class WKWebViewController: UIViewController, WKScriptMessageHandler {
|
|
|
386
393
|
internal var preShowSemaphore: DispatchSemaphore?
|
|
387
394
|
internal var preShowError: String?
|
|
388
395
|
private var isWebViewInitialized = false
|
|
396
|
+
private var isObservingKeyboardViewportChanges = false
|
|
397
|
+
private var lastViewportRefreshSize: CGSize?
|
|
389
398
|
private var downloadStates: [ObjectIdentifier: WKDownloadState] = [:]
|
|
390
399
|
private var previewItemURL: URL?
|
|
391
400
|
|
|
@@ -432,10 +441,10 @@ open class WKWebViewController: UIViewController, WKScriptMessageHandler {
|
|
|
432
441
|
|
|
433
442
|
private func attachmentDispositionType(_ response: URLResponse) -> String? {
|
|
434
443
|
guard let disposition = attachmentDisposition(response)?
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
444
|
+
.split(separator: ";", maxSplits: 1)
|
|
445
|
+
.first?
|
|
446
|
+
.trimmingCharacters(in: .whitespacesAndNewlines)
|
|
447
|
+
.lowercased(),
|
|
439
448
|
!disposition.isEmpty else {
|
|
440
449
|
return nil
|
|
441
450
|
}
|
|
@@ -527,7 +536,7 @@ open class WKWebViewController: UIViewController, WKScriptMessageHandler {
|
|
|
527
536
|
"application/download",
|
|
528
537
|
"application/x-download",
|
|
529
538
|
"application/binary",
|
|
530
|
-
"application/x-binary"
|
|
539
|
+
"application/x-binary"
|
|
531
540
|
]
|
|
532
541
|
|
|
533
542
|
if let candidate, !candidate.isEmpty, !genericMimeTypes.contains(candidate) {
|
|
@@ -590,7 +599,7 @@ open class WKWebViewController: UIViewController, WKScriptMessageHandler {
|
|
|
590
599
|
"fileName": fileURL.lastPathComponent,
|
|
591
600
|
"path": fileURL.path,
|
|
592
601
|
"localUrl": fileURL.absoluteString,
|
|
593
|
-
"handledBy": handledBy
|
|
602
|
+
"handledBy": handledBy
|
|
594
603
|
]
|
|
595
604
|
if let sourceURL {
|
|
596
605
|
data["sourceUrl"] = sourceURL
|
|
@@ -842,6 +851,7 @@ open class WKWebViewController: UIViewController, WKScriptMessageHandler {
|
|
|
842
851
|
}
|
|
843
852
|
|
|
844
853
|
deinit {
|
|
854
|
+
NotificationCenter.default.removeObserver(self)
|
|
845
855
|
webView?.removeObserver(self, forKeyPath: estimatedProgressKeyPath)
|
|
846
856
|
if websiteTitleInNavigationBar {
|
|
847
857
|
webView?.removeObserver(self, forKeyPath: titleKeyPath)
|
|
@@ -886,6 +896,11 @@ open class WKWebViewController: UIViewController, WKScriptMessageHandler {
|
|
|
886
896
|
}
|
|
887
897
|
}
|
|
888
898
|
|
|
899
|
+
override open func viewDidLayoutSubviews() {
|
|
900
|
+
super.viewDidLayoutSubviews()
|
|
901
|
+
refreshWebViewViewportIfNeeded()
|
|
902
|
+
}
|
|
903
|
+
|
|
889
904
|
func updateButtonTintColors() {
|
|
890
905
|
// Ensure all button items use the navigation bar's tint color
|
|
891
906
|
if let tintColor = navigationController?.navigationBar.tintColor {
|
|
@@ -986,6 +1001,63 @@ open class WKWebViewController: UIViewController, WKScriptMessageHandler {
|
|
|
986
1001
|
capBrowserPlugin?.notifyListeners(eventName, data: payload(with: data))
|
|
987
1002
|
}
|
|
988
1003
|
|
|
1004
|
+
private func startObservingKeyboardViewportChanges() {
|
|
1005
|
+
guard !isObservingKeyboardViewportChanges else {
|
|
1006
|
+
return
|
|
1007
|
+
}
|
|
1008
|
+
|
|
1009
|
+
isObservingKeyboardViewportChanges = true
|
|
1010
|
+
let center = NotificationCenter.default
|
|
1011
|
+
center.addObserver(self, selector: #selector(keyboardViewportDidChange(_:)), name: UIResponder.keyboardWillHideNotification, object: nil)
|
|
1012
|
+
center.addObserver(self, selector: #selector(keyboardViewportDidChange(_:)), name: UIResponder.keyboardDidHideNotification, object: nil)
|
|
1013
|
+
center.addObserver(self, selector: #selector(keyboardViewportDidChange(_:)), name: UIResponder.keyboardDidChangeFrameNotification, object: nil)
|
|
1014
|
+
}
|
|
1015
|
+
|
|
1016
|
+
@objc private func keyboardViewportDidChange(_ notification: Notification) {
|
|
1017
|
+
scheduleWebViewViewportRefresh(force: true, delay: viewportRefreshDelay(from: notification))
|
|
1018
|
+
}
|
|
1019
|
+
|
|
1020
|
+
private func viewportRefreshDelay(from notification: Notification) -> TimeInterval {
|
|
1021
|
+
guard let duration = notification.userInfo?[UIResponder.keyboardAnimationDurationUserInfoKey] as? NSNumber else {
|
|
1022
|
+
return 0.05
|
|
1023
|
+
}
|
|
1024
|
+
|
|
1025
|
+
return max(0.05, duration.doubleValue)
|
|
1026
|
+
}
|
|
1027
|
+
|
|
1028
|
+
private func scheduleWebViewViewportRefresh(force: Bool = false, delay: TimeInterval = 0.05) {
|
|
1029
|
+
DispatchQueue.main.asyncAfter(deadline: .now() + delay) { [weak self] in
|
|
1030
|
+
self?.refreshWebViewViewportIfNeeded(force: force)
|
|
1031
|
+
}
|
|
1032
|
+
}
|
|
1033
|
+
|
|
1034
|
+
private func refreshWebViewViewportIfNeeded(force: Bool = false) {
|
|
1035
|
+
guard let webView = self.webView, webView.superview != nil else {
|
|
1036
|
+
return
|
|
1037
|
+
}
|
|
1038
|
+
|
|
1039
|
+
if force {
|
|
1040
|
+
self.view.setNeedsLayout()
|
|
1041
|
+
self.view.layoutIfNeeded()
|
|
1042
|
+
}
|
|
1043
|
+
|
|
1044
|
+
let currentSize = webView.bounds.size
|
|
1045
|
+
guard WebViewViewportLayoutSupport.shouldRefreshViewport(
|
|
1046
|
+
previousSize: lastViewportRefreshSize,
|
|
1047
|
+
currentSize: currentSize,
|
|
1048
|
+
force: force
|
|
1049
|
+
) else {
|
|
1050
|
+
return
|
|
1051
|
+
}
|
|
1052
|
+
|
|
1053
|
+
lastViewportRefreshSize = currentSize
|
|
1054
|
+
webView.setNeedsLayout()
|
|
1055
|
+
webView.layoutIfNeeded()
|
|
1056
|
+
webView.scrollView.setNeedsLayout()
|
|
1057
|
+
webView.scrollView.layoutIfNeeded()
|
|
1058
|
+
webView.evaluateJavaScript("window.dispatchEvent(new Event('resize'));", completionHandler: nil)
|
|
1059
|
+
}
|
|
1060
|
+
|
|
989
1061
|
private func jsonString(from object: Any) -> String? {
|
|
990
1062
|
guard JSONSerialization.isValidJSONObject(object),
|
|
991
1063
|
let data = try? JSONSerialization.data(withJSONObject: object),
|
|
@@ -1251,6 +1323,7 @@ open class WKWebViewController: UIViewController, WKScriptMessageHandler {
|
|
|
1251
1323
|
return
|
|
1252
1324
|
}
|
|
1253
1325
|
self.isWebViewInitialized = true
|
|
1326
|
+
self.startObservingKeyboardViewportChanges()
|
|
1254
1327
|
self.view.backgroundColor = UIColor.white
|
|
1255
1328
|
|
|
1256
1329
|
self.extendedLayoutIncludesOpaqueBars = true
|
|
@@ -1540,47 +1613,6 @@ open class WKWebViewController: UIViewController, WKScriptMessageHandler {
|
|
|
1540
1613
|
return self.capableWebView
|
|
1541
1614
|
}
|
|
1542
1615
|
|
|
1543
|
-
@objc func restateViewHeight() {
|
|
1544
|
-
var bottomPadding = CGFloat(0.0)
|
|
1545
|
-
var topPadding = CGFloat(0.0)
|
|
1546
|
-
let window = UIApplication.shared.windows.first(where: { $0.isKeyWindow })
|
|
1547
|
-
bottomPadding = window?.safeAreaInsets.bottom ?? 0.0
|
|
1548
|
-
topPadding = window?.safeAreaInsets.top ?? 0.0
|
|
1549
|
-
if UIDevice.current.orientation.isPortrait {
|
|
1550
|
-
// Don't force toolbar visibility
|
|
1551
|
-
if self.viewHeightPortrait == nil {
|
|
1552
|
-
self.viewHeightPortrait = self.view.safeAreaLayoutGuide.layoutFrame.size.height
|
|
1553
|
-
self.viewHeightPortrait! += bottomPadding
|
|
1554
|
-
if self.navigationController?.navigationBar.isHidden == true {
|
|
1555
|
-
self.viewHeightPortrait! += topPadding
|
|
1556
|
-
}
|
|
1557
|
-
}
|
|
1558
|
-
self.currentViewHeight = self.viewHeightPortrait
|
|
1559
|
-
} else if UIDevice.current.orientation.isLandscape {
|
|
1560
|
-
// Don't force toolbar visibility
|
|
1561
|
-
if self.viewHeightLandscape == nil {
|
|
1562
|
-
self.viewHeightLandscape = self.view.safeAreaLayoutGuide.layoutFrame.size.height
|
|
1563
|
-
self.viewHeightLandscape! += bottomPadding
|
|
1564
|
-
if self.navigationController?.navigationBar.isHidden == true {
|
|
1565
|
-
self.viewHeightLandscape! += topPadding
|
|
1566
|
-
}
|
|
1567
|
-
}
|
|
1568
|
-
self.currentViewHeight = self.viewHeightLandscape
|
|
1569
|
-
}
|
|
1570
|
-
}
|
|
1571
|
-
|
|
1572
|
-
override open func viewWillTransition(to size: CGSize, with coordinator: UIViewControllerTransitionCoordinator) {
|
|
1573
|
-
// self.view.frame.size.height = self.currentViewHeight!
|
|
1574
|
-
}
|
|
1575
|
-
|
|
1576
|
-
override open func viewWillLayoutSubviews() {
|
|
1577
|
-
restateViewHeight()
|
|
1578
|
-
// Don't override frame height when enabledSafeBottomMargin is true, as it would override our constraints
|
|
1579
|
-
if self.currentViewHeight != nil && !self.enabledSafeBottomMargin {
|
|
1580
|
-
self.view.frame.size.height = self.currentViewHeight!
|
|
1581
|
-
}
|
|
1582
|
-
}
|
|
1583
|
-
|
|
1584
1616
|
override open func viewWillAppear(_ animated: Bool) {
|
|
1585
1617
|
super.viewWillAppear(animated)
|
|
1586
1618
|
if !self.viewWasPresented {
|
|
@@ -1620,6 +1652,8 @@ open class WKWebViewController: UIViewController, WKScriptMessageHandler {
|
|
|
1620
1652
|
|
|
1621
1653
|
override open func viewDidAppear(_ animated: Bool) {
|
|
1622
1654
|
super.viewDidAppear(animated)
|
|
1655
|
+
refreshWebViewViewportIfNeeded(force: true)
|
|
1656
|
+
scheduleWebViewViewportRefresh(force: true, delay: 0.25)
|
|
1623
1657
|
|
|
1624
1658
|
// Force add buttonNearDone if it's not visible yet
|
|
1625
1659
|
if buttonNearDoneIcon != nil {
|
|
@@ -2907,6 +2941,7 @@ extension WKWebViewController: WKNavigationDelegate {
|
|
|
2907
2941
|
webView.topAnchor.constraint(equalTo: topAnchor)
|
|
2908
2942
|
])
|
|
2909
2943
|
self.view.layoutIfNeeded()
|
|
2944
|
+
refreshWebViewViewportIfNeeded(force: true)
|
|
2910
2945
|
}
|
|
2911
2946
|
|
|
2912
2947
|
open func updateSafeBottomMargin(_ enabled: Bool) {
|
|
@@ -2927,6 +2962,7 @@ extension WKWebViewController: WKNavigationDelegate {
|
|
|
2927
2962
|
webView.bottomAnchor.constraint(equalTo: bottomAnchor)
|
|
2928
2963
|
])
|
|
2929
2964
|
self.view.layoutIfNeeded()
|
|
2965
|
+
refreshWebViewViewportIfNeeded(force: true)
|
|
2930
2966
|
}
|
|
2931
2967
|
}
|
|
2932
2968
|
|