@capgo/capacitor-inappbrowser 8.6.31 → 8.6.32
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.
|
@@ -98,7 +98,7 @@ public class CapgoInAppBrowserPlugin: CAPPlugin, CAPBridgedPlugin {
|
|
|
98
98
|
case aware = "AWARE"
|
|
99
99
|
case fakeVisible = "FAKE_VISIBLE"
|
|
100
100
|
}
|
|
101
|
-
private let pluginVersion: String = "8.6.
|
|
101
|
+
private let pluginVersion: String = "8.6.32"
|
|
102
102
|
public let identifier = "CapgoInAppBrowserPlugin"
|
|
103
103
|
public let jsName = "CapgoInAppBrowser"
|
|
104
104
|
public let pluginMethods: [CAPPluginMethod] = [
|
|
@@ -236,6 +236,49 @@ enum WebViewViewportLayoutSupport {
|
|
|
236
236
|
}
|
|
237
237
|
}
|
|
238
238
|
|
|
239
|
+
enum WebViewSafeAreaLayoutSupport {
|
|
240
|
+
static func contentInsetAdjustmentBehavior(enabledSafeBottomMargin: Bool) -> UIScrollView.ContentInsetAdjustmentBehavior {
|
|
241
|
+
enabledSafeBottomMargin ? .automatic : .never
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
static func shouldInsetLayoutMarginsFromSafeArea(enabledSafeBottomMargin: Bool) -> Bool {
|
|
245
|
+
enabledSafeBottomMargin
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
static func rawSystemBottomInset(effectiveBottomInset: CGFloat, additionalBottomInset: CGFloat) -> CGFloat {
|
|
249
|
+
max(0, effectiveBottomInset - additionalBottomInset)
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
static func additionalBottomSafeAreaOffset(enabledSafeBottomMargin: Bool, safeAreaBottomInset: CGFloat) -> CGFloat {
|
|
253
|
+
guard !enabledSafeBottomMargin, safeAreaBottomInset > 0 else {
|
|
254
|
+
return 0
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
return -safeAreaBottomInset
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
static func cssBottomInset(enabledSafeBottomMargin: Bool, safeAreaBottomInset: CGFloat) -> CGFloat {
|
|
261
|
+
enabledSafeBottomMargin ? safeAreaBottomInset : 0
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
static func cssTopInset(enabledSafeTopMargin: Bool, safeAreaTopInset: CGFloat) -> CGFloat {
|
|
265
|
+
enabledSafeTopMargin ? safeAreaTopInset : 0
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
static func safeAreaCssVariablesScript(top: CGFloat, bottom: CGFloat, left: CGFloat, right: CGFloat) -> String {
|
|
269
|
+
let topValue = Int(top.rounded())
|
|
270
|
+
let bottomValue = Int(bottom.rounded())
|
|
271
|
+
let leftValue = Int(left.rounded())
|
|
272
|
+
let rightValue = Int(right.rounded())
|
|
273
|
+
|
|
274
|
+
return "(function(){var root=document.documentElement;" +
|
|
275
|
+
"root.style.setProperty('--safe-area-inset-top','\(topValue)px');" +
|
|
276
|
+
"root.style.setProperty('--safe-area-inset-bottom','\(bottomValue)px');" +
|
|
277
|
+
"root.style.setProperty('--safe-area-inset-left','\(leftValue)px');" +
|
|
278
|
+
"root.style.setProperty('--safe-area-inset-right','\(rightValue)px');})();"
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
|
|
239
282
|
open class WKWebViewController: UIViewController, WKScriptMessageHandler {
|
|
240
283
|
|
|
241
284
|
public init() {
|
|
@@ -395,6 +438,14 @@ open class WKWebViewController: UIViewController, WKScriptMessageHandler {
|
|
|
395
438
|
private var isWebViewInitialized = false
|
|
396
439
|
private var isObservingKeyboardViewportChanges = false
|
|
397
440
|
private var lastViewportRefreshSize: CGSize?
|
|
441
|
+
private struct InjectedSafeAreaInsets: Equatable {
|
|
442
|
+
let top: Int
|
|
443
|
+
let bottom: Int
|
|
444
|
+
let left: Int
|
|
445
|
+
let right: Int
|
|
446
|
+
}
|
|
447
|
+
|
|
448
|
+
private var lastInjectedSafeAreaInsets: InjectedSafeAreaInsets?
|
|
398
449
|
private var downloadStates: [ObjectIdentifier: WKDownloadState] = [:]
|
|
399
450
|
private var previewItemURL: URL?
|
|
400
451
|
|
|
@@ -904,9 +955,15 @@ open class WKWebViewController: UIViewController, WKScriptMessageHandler {
|
|
|
904
955
|
|
|
905
956
|
override open func viewDidLayoutSubviews() {
|
|
906
957
|
super.viewDidLayoutSubviews()
|
|
958
|
+
syncWebViewSafeAreaLayout()
|
|
907
959
|
refreshWebViewViewportIfNeeded()
|
|
908
960
|
}
|
|
909
961
|
|
|
962
|
+
override open func viewSafeAreaInsetsDidChange() {
|
|
963
|
+
super.viewSafeAreaInsetsDidChange()
|
|
964
|
+
syncWebViewSafeAreaLayout()
|
|
965
|
+
}
|
|
966
|
+
|
|
910
967
|
func updateButtonTintColors() {
|
|
911
968
|
// Ensure all button items use the navigation bar's tint color
|
|
912
969
|
if let tintColor = navigationController?.navigationBar.tintColor {
|
|
@@ -1064,6 +1121,72 @@ open class WKWebViewController: UIViewController, WKScriptMessageHandler {
|
|
|
1064
1121
|
webView.evaluateJavaScript("window.dispatchEvent(new Event('resize'));", completionHandler: nil)
|
|
1065
1122
|
}
|
|
1066
1123
|
|
|
1124
|
+
private func configureWebViewScrollViewSafeArea(_ webView: WKWebView) {
|
|
1125
|
+
if #available(iOS 11.0, *) {
|
|
1126
|
+
webView.scrollView.contentInsetAdjustmentBehavior = WebViewSafeAreaLayoutSupport
|
|
1127
|
+
.contentInsetAdjustmentBehavior(enabledSafeBottomMargin: enabledSafeBottomMargin)
|
|
1128
|
+
}
|
|
1129
|
+
|
|
1130
|
+
webView.insetsLayoutMarginsFromSafeArea = WebViewSafeAreaLayoutSupport
|
|
1131
|
+
.shouldInsetLayoutMarginsFromSafeArea(enabledSafeBottomMargin: enabledSafeBottomMargin)
|
|
1132
|
+
|
|
1133
|
+
if !enabledSafeBottomMargin {
|
|
1134
|
+
webView.scrollView.contentInset = .zero
|
|
1135
|
+
webView.scrollView.scrollIndicatorInsets = .zero
|
|
1136
|
+
}
|
|
1137
|
+
}
|
|
1138
|
+
|
|
1139
|
+
private func syncWebViewSafeAreaLayout() {
|
|
1140
|
+
guard let webView = self.webView, webView.superview != nil else {
|
|
1141
|
+
return
|
|
1142
|
+
}
|
|
1143
|
+
|
|
1144
|
+
let rawSafeAreaBottomInset = WebViewSafeAreaLayoutSupport.rawSystemBottomInset(
|
|
1145
|
+
effectiveBottomInset: view.safeAreaInsets.bottom,
|
|
1146
|
+
additionalBottomInset: additionalSafeAreaInsets.bottom
|
|
1147
|
+
)
|
|
1148
|
+
|
|
1149
|
+
let bottomOffset = WebViewSafeAreaLayoutSupport.additionalBottomSafeAreaOffset(
|
|
1150
|
+
enabledSafeBottomMargin: enabledSafeBottomMargin,
|
|
1151
|
+
safeAreaBottomInset: rawSafeAreaBottomInset
|
|
1152
|
+
)
|
|
1153
|
+
if additionalSafeAreaInsets.bottom != bottomOffset {
|
|
1154
|
+
additionalSafeAreaInsets.bottom = bottomOffset
|
|
1155
|
+
}
|
|
1156
|
+
|
|
1157
|
+
configureWebViewScrollViewSafeArea(webView)
|
|
1158
|
+
|
|
1159
|
+
let topInset = WebViewSafeAreaLayoutSupport.cssTopInset(
|
|
1160
|
+
enabledSafeTopMargin: enabledSafeTopMargin,
|
|
1161
|
+
safeAreaTopInset: view.safeAreaInsets.top
|
|
1162
|
+
)
|
|
1163
|
+
let bottomInset = WebViewSafeAreaLayoutSupport.cssBottomInset(
|
|
1164
|
+
enabledSafeBottomMargin: enabledSafeBottomMargin,
|
|
1165
|
+
safeAreaBottomInset: rawSafeAreaBottomInset
|
|
1166
|
+
)
|
|
1167
|
+
let leftInset = view.safeAreaInsets.left
|
|
1168
|
+
let rightInset = view.safeAreaInsets.right
|
|
1169
|
+
|
|
1170
|
+
let roundedInsets = InjectedSafeAreaInsets(
|
|
1171
|
+
top: Int(topInset.rounded()),
|
|
1172
|
+
bottom: Int(bottomInset.rounded()),
|
|
1173
|
+
left: Int(leftInset.rounded()),
|
|
1174
|
+
right: Int(rightInset.rounded())
|
|
1175
|
+
)
|
|
1176
|
+
if lastInjectedSafeAreaInsets == roundedInsets {
|
|
1177
|
+
return
|
|
1178
|
+
}
|
|
1179
|
+
lastInjectedSafeAreaInsets = roundedInsets
|
|
1180
|
+
|
|
1181
|
+
let script = WebViewSafeAreaLayoutSupport.safeAreaCssVariablesScript(
|
|
1182
|
+
top: topInset,
|
|
1183
|
+
bottom: bottomInset,
|
|
1184
|
+
left: leftInset,
|
|
1185
|
+
right: rightInset
|
|
1186
|
+
)
|
|
1187
|
+
webView.evaluateJavaScript(script, completionHandler: nil)
|
|
1188
|
+
}
|
|
1189
|
+
|
|
1067
1190
|
private func jsonString(from object: Any) -> String? {
|
|
1068
1191
|
guard JSONSerialization.isValidJSONObject(object),
|
|
1069
1192
|
let data = try? JSONSerialization.data(withJSONObject: object),
|
|
@@ -1504,6 +1627,7 @@ open class WKWebViewController: UIViewController, WKScriptMessageHandler {
|
|
|
1504
1627
|
|
|
1505
1628
|
// Disable bounce effect by setting scrollView.bounces to false when disableOverscroll is true
|
|
1506
1629
|
webView.scrollView.bounces = !self.disableOverscroll
|
|
1630
|
+
configureWebViewScrollViewSafeArea(webView)
|
|
1507
1631
|
|
|
1508
1632
|
webView.addObserver(self, forKeyPath: estimatedProgressKeyPath, options: .new, context: nil)
|
|
1509
1633
|
if websiteTitleInNavigationBar {
|
|
@@ -2075,10 +2199,10 @@ fileprivate extension WKWebViewController {
|
|
|
2075
2199
|
}
|
|
2076
2200
|
|
|
2077
2201
|
func setUpState() {
|
|
2078
|
-
navigationController?.setNavigationBarHidden(
|
|
2202
|
+
navigationController?.setNavigationBarHidden(blankNavigationTab, animated: false)
|
|
2079
2203
|
|
|
2080
2204
|
// Always hide toolbar since we never want it
|
|
2081
|
-
navigationController?.setToolbarHidden(true, animated:
|
|
2205
|
+
navigationController?.setToolbarHidden(true, animated: false)
|
|
2082
2206
|
|
|
2083
2207
|
// Set tint colors but don't override specific colors
|
|
2084
2208
|
if tintColor == nil {
|
|
@@ -2730,6 +2854,8 @@ extension WKWebViewController: WKNavigationDelegate {
|
|
|
2730
2854
|
delegate?.webViewController?(self, didFinish: url)
|
|
2731
2855
|
}
|
|
2732
2856
|
self.injectJavaScriptInterface()
|
|
2857
|
+
lastInjectedSafeAreaInsets = nil
|
|
2858
|
+
syncWebViewSafeAreaLayout()
|
|
2733
2859
|
emit("browserPageLoaded")
|
|
2734
2860
|
}
|
|
2735
2861
|
|
|
@@ -2944,6 +3070,7 @@ extension WKWebViewController: WKNavigationDelegate {
|
|
|
2944
3070
|
webView.topAnchor.constraint(equalTo: topAnchor)
|
|
2945
3071
|
])
|
|
2946
3072
|
self.view.layoutIfNeeded()
|
|
3073
|
+
syncWebViewSafeAreaLayout()
|
|
2947
3074
|
refreshWebViewViewportIfNeeded(force: true)
|
|
2948
3075
|
}
|
|
2949
3076
|
|
|
@@ -2965,6 +3092,7 @@ extension WKWebViewController: WKNavigationDelegate {
|
|
|
2965
3092
|
webView.bottomAnchor.constraint(equalTo: bottomAnchor)
|
|
2966
3093
|
])
|
|
2967
3094
|
self.view.layoutIfNeeded()
|
|
3095
|
+
syncWebViewSafeAreaLayout()
|
|
2968
3096
|
refreshWebViewViewportIfNeeded(force: true)
|
|
2969
3097
|
}
|
|
2970
3098
|
}
|