@capacitor-plus/ios 8.0.0-beta.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.
- package/Capacitor/Capacitor/AppUUID.swift +51 -0
- package/Capacitor/Capacitor/Array+Capacitor.swift +31 -0
- package/Capacitor/Capacitor/CAPApplicationDelegateProxy.swift +32 -0
- package/Capacitor/Capacitor/CAPBridge.swift +25 -0
- package/Capacitor/Capacitor/CAPBridgeDelegate.swift +6 -0
- package/Capacitor/Capacitor/CAPBridgeProtocol.swift +148 -0
- package/Capacitor/Capacitor/CAPBridgeViewController+CDVScreenOrientationDelegate.h +6 -0
- package/Capacitor/Capacitor/CAPBridgeViewController+CDVScreenOrientationDelegate.m +5 -0
- package/Capacitor/Capacitor/CAPBridgeViewController.swift +384 -0
- package/Capacitor/Capacitor/CAPBridgedJSTypes.h +18 -0
- package/Capacitor/Capacitor/CAPBridgedJSTypes.m +43 -0
- package/Capacitor/Capacitor/CAPBridgedPlugin+getMethod.swift +13 -0
- package/Capacitor/Capacitor/CAPBridgedPlugin.h +41 -0
- package/Capacitor/Capacitor/CAPFile.swift +14 -0
- package/Capacitor/Capacitor/CAPInstanceConfiguration.h +38 -0
- package/Capacitor/Capacitor/CAPInstanceConfiguration.m +93 -0
- package/Capacitor/Capacitor/CAPInstanceConfiguration.swift +78 -0
- package/Capacitor/Capacitor/CAPInstanceDescriptor.h +167 -0
- package/Capacitor/Capacitor/CAPInstanceDescriptor.m +56 -0
- package/Capacitor/Capacitor/CAPInstanceDescriptor.swift +198 -0
- package/Capacitor/Capacitor/CAPInstancePlugin.swift +10 -0
- package/Capacitor/Capacitor/CAPLog.swift +11 -0
- package/Capacitor/Capacitor/CAPNotifications.swift +69 -0
- package/Capacitor/Capacitor/CAPPlugin+LoadInstance.swift +20 -0
- package/Capacitor/Capacitor/CAPPlugin.h +60 -0
- package/Capacitor/Capacitor/CAPPlugin.m +180 -0
- package/Capacitor/Capacitor/CAPPluginCall.h +25 -0
- package/Capacitor/Capacitor/CAPPluginCall.m +36 -0
- package/Capacitor/Capacitor/CAPPluginCall.swift +97 -0
- package/Capacitor/Capacitor/CAPPluginMethod.h +36 -0
- package/Capacitor/Capacitor/CAPPluginMethod.m +44 -0
- package/Capacitor/Capacitor/CAPPluginMethod.swift +17 -0
- package/Capacitor/Capacitor/Capacitor.h +15 -0
- package/Capacitor/Capacitor/Capacitor.modulemap +8 -0
- package/Capacitor/Capacitor/CapacitorBridge.swift +768 -0
- package/Capacitor/Capacitor/CapacitorExtension.swift +24 -0
- package/Capacitor/Capacitor/Codable/JSValueDecoder.swift +479 -0
- package/Capacitor/Capacitor/Codable/JSValueEncoder.swift +671 -0
- package/Capacitor/Capacitor/Data+Capacitor.swift +22 -0
- package/Capacitor/Capacitor/DocLinks.swift +8 -0
- package/Capacitor/Capacitor/Info.plist +24 -0
- package/Capacitor/Capacitor/JS.swift +122 -0
- package/Capacitor/Capacitor/JSExport.swift +218 -0
- package/Capacitor/Capacitor/JSTypes.swift +254 -0
- package/Capacitor/Capacitor/KeyPath.swift +60 -0
- package/Capacitor/Capacitor/KeyValueStore.swift +303 -0
- package/Capacitor/Capacitor/NotificationHandlerProtocol.swift +6 -0
- package/Capacitor/Capacitor/NotificationRouter.swift +60 -0
- package/Capacitor/Capacitor/PluginCallResult.swift +106 -0
- package/Capacitor/Capacitor/PluginConfig.swift +56 -0
- package/Capacitor/Capacitor/Plugins/CapacitorCookieManager.swift +141 -0
- package/Capacitor/Capacitor/Plugins/CapacitorCookies.swift +57 -0
- package/Capacitor/Capacitor/Plugins/CapacitorHttp.swift +57 -0
- package/Capacitor/Capacitor/Plugins/CapacitorUrlRequest.swift +225 -0
- package/Capacitor/Capacitor/Plugins/Console.swift +16 -0
- package/Capacitor/Capacitor/Plugins/HttpRequestHandler.swift +236 -0
- package/Capacitor/Capacitor/Plugins/SystemBars.swift +133 -0
- package/Capacitor/Capacitor/Plugins/WebView.swift +44 -0
- package/Capacitor/Capacitor/PrivacyInfo.xcprivacy +14 -0
- package/Capacitor/Capacitor/Router.swift +29 -0
- package/Capacitor/Capacitor/TmpViewController.swift +8 -0
- package/Capacitor/Capacitor/UIColor.swift +55 -0
- package/Capacitor/Capacitor/UIStatusBarManager+CAPHandleTapAction.m +37 -0
- package/Capacitor/Capacitor/WKWebView+Capacitor.m +15 -0
- package/Capacitor/Capacitor/WKWebView+Capacitor.swift +80 -0
- package/Capacitor/Capacitor/WebViewAssetHandler.swift +550 -0
- package/Capacitor/Capacitor/WebViewDelegationHandler.swift +361 -0
- package/Capacitor/Capacitor/assets/native-bridge.js +1029 -0
- package/Capacitor.podspec +23 -0
- package/CapacitorCordova/CapacitorCordova/CapacitorCordova.h +25 -0
- package/CapacitorCordova/CapacitorCordova/CapacitorCordova.modulemap +6 -0
- package/CapacitorCordova/CapacitorCordova/Classes/Public/AppDelegate.h +8 -0
- package/CapacitorCordova/CapacitorCordova/Classes/Public/AppDelegate.m +5 -0
- package/CapacitorCordova/CapacitorCordova/Classes/Public/CDV.h +28 -0
- package/CapacitorCordova/CapacitorCordova/Classes/Public/CDVAvailability.h +109 -0
- package/CapacitorCordova/CapacitorCordova/Classes/Public/CDVAvailabilityDeprecated.h +21 -0
- package/CapacitorCordova/CapacitorCordova/Classes/Public/CDVCommandDelegate.h +49 -0
- package/CapacitorCordova/CapacitorCordova/Classes/Public/CDVCommandDelegateImpl.h +39 -0
- package/CapacitorCordova/CapacitorCordova/Classes/Public/CDVCommandDelegateImpl.m +149 -0
- package/CapacitorCordova/CapacitorCordova/Classes/Public/CDVConfigParser.h +31 -0
- package/CapacitorCordova/CapacitorCordova/Classes/Public/CDVConfigParser.m +81 -0
- package/CapacitorCordova/CapacitorCordova/Classes/Public/CDVInvokedUrlCommand.h +52 -0
- package/CapacitorCordova/CapacitorCordova/Classes/Public/CDVInvokedUrlCommand.m +116 -0
- package/CapacitorCordova/CapacitorCordova/Classes/Public/CDVPlugin+Resources.h +39 -0
- package/CapacitorCordova/CapacitorCordova/Classes/Public/CDVPlugin+Resources.m +38 -0
- package/CapacitorCordova/CapacitorCordova/Classes/Public/CDVPlugin.h +76 -0
- package/CapacitorCordova/CapacitorCordova/Classes/Public/CDVPlugin.m +136 -0
- package/CapacitorCordova/CapacitorCordova/Classes/Public/CDVPluginManager.h +25 -0
- package/CapacitorCordova/CapacitorCordova/Classes/Public/CDVPluginManager.m +77 -0
- package/CapacitorCordova/CapacitorCordova/Classes/Public/CDVPluginResult.h +82 -0
- package/CapacitorCordova/CapacitorCordova/Classes/Public/CDVPluginResult.m +216 -0
- package/CapacitorCordova/CapacitorCordova/Classes/Public/CDVScreenOrientationDelegate.h +33 -0
- package/CapacitorCordova/CapacitorCordova/Classes/Public/CDVURLProtocol.h +27 -0
- package/CapacitorCordova/CapacitorCordova/Classes/Public/CDVURLProtocol.m +74 -0
- package/CapacitorCordova/CapacitorCordova/Classes/Public/CDVViewController.h +30 -0
- package/CapacitorCordova/CapacitorCordova/Classes/Public/CDVViewController.m +37 -0
- package/CapacitorCordova/CapacitorCordova/Classes/Public/CDVWebViewProcessPoolFactory.h +34 -0
- package/CapacitorCordova/CapacitorCordova/Classes/Public/CDVWebViewProcessPoolFactory.m +55 -0
- package/CapacitorCordova/CapacitorCordova/Classes/Public/NSDictionary+CordovaPreferences.h +35 -0
- package/CapacitorCordova/CapacitorCordova/Classes/Public/NSDictionary+CordovaPreferences.m +63 -0
- package/CapacitorCordova/CapacitorCordova/Info.plist +26 -0
- package/CapacitorCordova/CapacitorCordova/PrivacyInfo.xcprivacy +14 -0
- package/CapacitorCordova.podspec +26 -0
- package/LICENSE +21 -0
- package/package.json +33 -0
- package/scripts/pods_helpers.rb +12 -0
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
import Foundation
|
|
2
|
+
|
|
3
|
+
@objc(CAPSystemBarsPlugin)
|
|
4
|
+
public class CAPSystemBarsPlugin: CAPPlugin, CAPBridgedPlugin {
|
|
5
|
+
public let identifier = "CAPSystemBarsPlugin"
|
|
6
|
+
public let jsName = "SystemBars"
|
|
7
|
+
public let pluginMethods: [CAPPluginMethod] = [
|
|
8
|
+
CAPPluginMethod(name: "setStyle", returnType: CAPPluginReturnPromise),
|
|
9
|
+
CAPPluginMethod(name: "setAnimation", returnType: CAPPluginReturnPromise),
|
|
10
|
+
CAPPluginMethod(name: "show", returnType: CAPPluginReturnPromise),
|
|
11
|
+
CAPPluginMethod(name: "hide", returnType: CAPPluginReturnPromise)
|
|
12
|
+
]
|
|
13
|
+
|
|
14
|
+
public private(set) var hideHomeIndicator: Bool = false
|
|
15
|
+
|
|
16
|
+
enum Style: String {
|
|
17
|
+
case dark = "DARK"
|
|
18
|
+
case light = "LIGHT"
|
|
19
|
+
case defaultStyle = "DEFAULT"
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
@objc override public func load() {
|
|
23
|
+
let hidden = getConfig().getBoolean("hidden", false)
|
|
24
|
+
|
|
25
|
+
if let style = getConfig().getString("style", "DEFAULT") {
|
|
26
|
+
setStyle(style: style)
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
if let animation = getConfig().getString("animation") {
|
|
30
|
+
setAnimation(animation: animation)
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
setHidden(hidden: hidden)
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
@objc func setStyle(_ call: CAPPluginCall) {
|
|
37
|
+
setStyle(style: call.getString("style") ?? Style.defaultStyle.rawValue)
|
|
38
|
+
call.resolve()
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
@objc func show(_ call: CAPPluginCall) {
|
|
42
|
+
let bar = call.getString("bar")
|
|
43
|
+
|
|
44
|
+
if let animation = call.getString("animation") {
|
|
45
|
+
setAnimation(animation: animation)
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
DispatchQueue.main.async {
|
|
49
|
+
self.setHidden(hidden: false, bar: bar)
|
|
50
|
+
call.resolve()
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
@objc func hide(_ call: CAPPluginCall) {
|
|
55
|
+
let bar = call.getString("bar")
|
|
56
|
+
|
|
57
|
+
if let animation = call.getString("animation") {
|
|
58
|
+
setAnimation(animation: animation)
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
DispatchQueue.main.async {
|
|
62
|
+
self.setHidden(hidden: true, bar: bar)
|
|
63
|
+
call.resolve()
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
@objc func setAnimation(_ call: CAPPluginCall) {
|
|
68
|
+
let animation = call.getString("animation", "FADE")
|
|
69
|
+
setAnimation(animation: animation)
|
|
70
|
+
|
|
71
|
+
call.resolve()
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
func setStyle(style: String) {
|
|
75
|
+
var newStyle: UIStatusBarStyle = .default
|
|
76
|
+
|
|
77
|
+
if let style = Style(rawValue: style.uppercased()) {
|
|
78
|
+
switch style {
|
|
79
|
+
case .dark:
|
|
80
|
+
newStyle = .lightContent
|
|
81
|
+
case .light:
|
|
82
|
+
newStyle = .darkContent
|
|
83
|
+
case .defaultStyle:
|
|
84
|
+
newStyle = .default
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
bridge?.statusBarStyle = newStyle
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
func setHidden(hidden: Bool, bar: String? = nil) {
|
|
92
|
+
if hidden {
|
|
93
|
+
if bar == nil || bar?.isEmpty ?? true || bar == "StatusBar" {
|
|
94
|
+
bridge?.statusBarVisible = false
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
if bar == nil || bar?.isEmpty ?? true || bar == "NavigationBar" {
|
|
98
|
+
hideHomeIndicator = true
|
|
99
|
+
bridge?.viewController?.setNeedsUpdateOfHomeIndicatorAutoHidden()
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
return
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
if bar == nil || bar?.isEmpty ?? true || bar == "StatusBar" {
|
|
106
|
+
bridge?.statusBarVisible = true
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
if bar == nil || bar?.isEmpty ?? true || bar == "NavigationBar" {
|
|
110
|
+
hideHomeIndicator = false
|
|
111
|
+
bridge?.viewController?.setNeedsUpdateOfHomeIndicatorAutoHidden()
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
func setAnimation(animation: String) {
|
|
117
|
+
if animation.uppercased() == "NONE" {
|
|
118
|
+
bridge?.statusBarAnimation = .none
|
|
119
|
+
} else {
|
|
120
|
+
bridge?.statusBarAnimation = .fade
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
extension CAPBridgeViewController {
|
|
126
|
+
override public var prefersHomeIndicatorAutoHidden: Bool {
|
|
127
|
+
if let systemBarPlugin = self.bridge?.plugin(withName: "SystemBars") as? CAPSystemBarsPlugin {
|
|
128
|
+
return systemBarPlugin.hideHomeIndicator
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
return false
|
|
132
|
+
}
|
|
133
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import Foundation
|
|
2
|
+
|
|
3
|
+
@objc(CAPWebViewPlugin)
|
|
4
|
+
public class CAPWebViewPlugin: CAPPlugin, CAPBridgedPlugin {
|
|
5
|
+
public let identifier = "CAPWebViewPlugin"
|
|
6
|
+
public let jsName = "WebView"
|
|
7
|
+
public let pluginMethods: [CAPPluginMethod] = [
|
|
8
|
+
CAPPluginMethod(name: "setServerAssetPath", returnType: CAPPluginReturnPromise),
|
|
9
|
+
CAPPluginMethod(name: "setServerBasePath", returnType: CAPPluginReturnPromise),
|
|
10
|
+
CAPPluginMethod(name: "getServerBasePath", returnType: CAPPluginReturnPromise),
|
|
11
|
+
CAPPluginMethod(name: "persistServerBasePath", returnType: CAPPluginReturnPromise)
|
|
12
|
+
]
|
|
13
|
+
|
|
14
|
+
@objc func setServerAssetPath(_ call: CAPPluginCall) {
|
|
15
|
+
if let path = call.getString("path"), let viewController = bridge?.viewController as? CAPBridgeViewController {
|
|
16
|
+
viewController.setServerBasePath(path: Bundle.main.url(forResource: path, withExtension: nil)?.path ?? path)
|
|
17
|
+
call.resolve()
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
@objc func setServerBasePath(_ call: CAPPluginCall) {
|
|
22
|
+
if let path = call.getString("path"), let viewController = bridge?.viewController as? CAPBridgeViewController {
|
|
23
|
+
viewController.setServerBasePath(path: path)
|
|
24
|
+
call.resolve()
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
@objc func getServerBasePath(_ call: CAPPluginCall) {
|
|
29
|
+
if let viewController = bridge?.viewController as? CAPBridgeViewController {
|
|
30
|
+
let path = viewController.getServerBasePath()
|
|
31
|
+
call.resolve([
|
|
32
|
+
"path": path
|
|
33
|
+
])
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
@objc func persistServerBasePath(_ call: CAPPluginCall) {
|
|
38
|
+
if let viewController = bridge?.viewController as? CAPBridgeViewController {
|
|
39
|
+
let path = viewController.getServerBasePath()
|
|
40
|
+
KeyValueStore.standard["serverBasePath"] = path
|
|
41
|
+
call.resolve()
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
|
2
|
+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
|
3
|
+
<plist version="1.0">
|
|
4
|
+
<dict>
|
|
5
|
+
<key>NSPrivacyAccessedAPITypes</key>
|
|
6
|
+
<array/>
|
|
7
|
+
<key>NSPrivacyCollectedDataTypes</key>
|
|
8
|
+
<array/>
|
|
9
|
+
<key>NSPrivacyTrackingDomains</key>
|
|
10
|
+
<array/>
|
|
11
|
+
<key>NSPrivacyTracking</key>
|
|
12
|
+
<false/>
|
|
13
|
+
</dict>
|
|
14
|
+
</plist>
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Router.swift
|
|
3
|
+
// Capacitor
|
|
4
|
+
//
|
|
5
|
+
// Created by Steven Sherry on 3/29/22.
|
|
6
|
+
// Copyright © 2022 Drifty Co. All rights reserved.
|
|
7
|
+
//
|
|
8
|
+
|
|
9
|
+
import Foundation
|
|
10
|
+
|
|
11
|
+
public protocol Router {
|
|
12
|
+
func route(for path: String) -> String
|
|
13
|
+
var basePath: String { get set }
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
public struct CapacitorRouter: Router {
|
|
17
|
+
public init() {}
|
|
18
|
+
public var basePath: String = ""
|
|
19
|
+
public func route(for path: String) -> String {
|
|
20
|
+
let pathUrl = URL(fileURLWithPath: path)
|
|
21
|
+
|
|
22
|
+
// If there's no path extension it also means the path is empty or a SPA route
|
|
23
|
+
if pathUrl.pathExtension.isEmpty {
|
|
24
|
+
return basePath + "/index.html"
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
return basePath + path
|
|
28
|
+
}
|
|
29
|
+
}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
extension UIColor: CapacitorExtension {}
|
|
2
|
+
public extension CapacitorExtensionTypeWrapper where T: UIColor {
|
|
3
|
+
// disable linting for the short variable names, since that's the point of the method
|
|
4
|
+
// swiftlint:disable:next identifier_name
|
|
5
|
+
static func color(r: Int, g: Int, b: Int, a: Int = 0xFF) -> UIColor {
|
|
6
|
+
return T(
|
|
7
|
+
red: CGFloat(r) / 255.0,
|
|
8
|
+
green: CGFloat(g) / 255.0,
|
|
9
|
+
blue: CGFloat(b) / 255.0,
|
|
10
|
+
alpha: CGFloat(a) / 255.0
|
|
11
|
+
)
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
static func color(argb: UInt32) -> UIColor {
|
|
15
|
+
return T(
|
|
16
|
+
red: CGFloat((argb >> 16) & 0xFF),
|
|
17
|
+
green: CGFloat((argb >> 8) & 0xFF),
|
|
18
|
+
blue: CGFloat(argb & 0xFF),
|
|
19
|
+
alpha: CGFloat((argb >> 24) & 0xFF)
|
|
20
|
+
)
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
static func color(fromHex: String) -> UIColor? {
|
|
24
|
+
let hexString = fromHex.trimmingCharacters(in: .whitespacesAndNewlines).replacingOccurrences(
|
|
25
|
+
of: "#",
|
|
26
|
+
with: ""
|
|
27
|
+
)
|
|
28
|
+
|
|
29
|
+
var argb: UInt64 = 0
|
|
30
|
+
|
|
31
|
+
var red: CGFloat = 0.0
|
|
32
|
+
var green: CGFloat = 0.0
|
|
33
|
+
var blue: CGFloat = 0.0
|
|
34
|
+
var alpha: CGFloat = 1.0
|
|
35
|
+
|
|
36
|
+
guard Scanner(string: hexString).scanHexInt64(&argb) else { return nil }
|
|
37
|
+
|
|
38
|
+
if hexString.count == 6 {
|
|
39
|
+
red = CGFloat((argb & 0xFF0000) >> 16) / 255.0
|
|
40
|
+
green = CGFloat((argb & 0x00FF00) >> 8) / 255.0
|
|
41
|
+
blue = CGFloat(argb & 0x0000FF) / 255.0
|
|
42
|
+
|
|
43
|
+
} else if hexString.count == 8 {
|
|
44
|
+
red = CGFloat((argb & 0xFF00_0000) >> 24) / 255.0
|
|
45
|
+
green = CGFloat((argb & 0x00FF0000) >> 16) / 255.0
|
|
46
|
+
blue = CGFloat((argb & 0x0000FF00) >> 8) / 255.0
|
|
47
|
+
alpha = CGFloat(argb & 0x000000FF) / 255.0
|
|
48
|
+
|
|
49
|
+
} else {
|
|
50
|
+
return nil
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
return T(red: red, green: green, blue: blue, alpha: alpha)
|
|
54
|
+
}
|
|
55
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
#import <Capacitor/Capacitor-Swift.h>
|
|
2
|
+
#import <objc/message.h>
|
|
3
|
+
#import <objc/runtime.h>
|
|
4
|
+
|
|
5
|
+
@implementation UIStatusBarManager (CAPHandleTapAction)
|
|
6
|
+
|
|
7
|
+
+ (void)load {
|
|
8
|
+
static dispatch_once_t onceToken;
|
|
9
|
+
dispatch_once(&onceToken, ^{
|
|
10
|
+
Class class = [self class];
|
|
11
|
+
SEL originalSelector = NSSelectorFromString(@"handleTapAction:");
|
|
12
|
+
SEL swizzledSelector = @selector(nofity_handleTapAction:);
|
|
13
|
+
|
|
14
|
+
Method originalMethod = class_getInstanceMethod(class, originalSelector);
|
|
15
|
+
Method swizzledMethod = class_getInstanceMethod(class, swizzledSelector);
|
|
16
|
+
|
|
17
|
+
BOOL didAddMethod = class_addMethod(class,
|
|
18
|
+
originalSelector,
|
|
19
|
+
method_getImplementation(swizzledMethod),
|
|
20
|
+
method_getTypeEncoding(swizzledMethod));
|
|
21
|
+
if (didAddMethod) {
|
|
22
|
+
class_replaceMethod(class,
|
|
23
|
+
swizzledSelector,
|
|
24
|
+
method_getImplementation(originalMethod),
|
|
25
|
+
method_getTypeEncoding(originalMethod));
|
|
26
|
+
} else {
|
|
27
|
+
method_exchangeImplementations(originalMethod, swizzledMethod);
|
|
28
|
+
}
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
-(void)nofity_handleTapAction:(id)arg1 {
|
|
33
|
+
[[NSNotificationCenter defaultCenter] postNotification:[NSNotification notificationWithName:NSNotification.capacitorStatusBarTapped object:nil]];
|
|
34
|
+
[self nofity_handleTapAction:arg1];
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
@end
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
#import <objc/runtime.h>
|
|
2
|
+
#import <Capacitor/Capacitor-Swift.h>
|
|
3
|
+
|
|
4
|
+
// Swift extensions marked as @objc and internal are available to the runtime but won't be found at compile time
|
|
5
|
+
// so we need this declaration to avoid compiler complaints.
|
|
6
|
+
@interface WKWebView (InternalSwiftExtension)
|
|
7
|
+
+ (void)_swizzleKeyboardMethods;
|
|
8
|
+
@end
|
|
9
|
+
|
|
10
|
+
// +load is the safest place to swizzle methods but that won't work from a swift extension so we need this wrapper.
|
|
11
|
+
@implementation WKWebView (CapacitorAutoFocus)
|
|
12
|
+
+ (void)load {
|
|
13
|
+
[self _swizzleKeyboardMethods];
|
|
14
|
+
}
|
|
15
|
+
@end
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import Foundation
|
|
2
|
+
import WebKit
|
|
3
|
+
|
|
4
|
+
extension WKWebView: CapacitorExtension {}
|
|
5
|
+
public extension CapacitorExtensionTypeWrapper where T == WKWebView {
|
|
6
|
+
var keyboardShouldRequireUserInteraction: Bool? {
|
|
7
|
+
return (self.baseType.associatedKeyboardFlagValue as? NSNumber)?.boolValue
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
// the readonly nature of the wrapper extension means we can't use a computed property with a setter
|
|
11
|
+
func setKeyboardShouldRequireUserInteraction(_ flag: Bool? = nil) {
|
|
12
|
+
if let flag = flag {
|
|
13
|
+
self.baseType.associatedKeyboardFlagValue = NSNumber(value: flag)
|
|
14
|
+
} else {
|
|
15
|
+
self.baseType.associatedKeyboardFlagValue = nil
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
private var associatedKeyboardFlagHandle: UInt8 = 0
|
|
21
|
+
|
|
22
|
+
internal extension WKWebView {
|
|
23
|
+
// Our lazy property can't be represented in Obj-C so we need this simple wrapper.
|
|
24
|
+
// swiftlint:disable identifier_name
|
|
25
|
+
@objc static func _swizzleKeyboardMethods() {
|
|
26
|
+
_ = oneTimeOnlySwizzle
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
typealias FiveArgClosureType = @convention(c) (Any, Selector, UnsafeRawPointer, Bool, Bool, Bool, Any?) -> Void
|
|
30
|
+
|
|
31
|
+
// dispatch_once isn't available in Swift, but lazy properties use the same mechanism under the hood so
|
|
32
|
+
// we can safely assume that this block of code will only execute once.
|
|
33
|
+
static let oneTimeOnlySwizzle: () = {
|
|
34
|
+
let frameworkName = "WK"
|
|
35
|
+
let className = "ContentView"
|
|
36
|
+
guard let targetClass = NSClassFromString(frameworkName + className) else {
|
|
37
|
+
return
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
let containingWebView = { (object: Any?) -> WKWebView? in
|
|
41
|
+
var view = object as? UIView
|
|
42
|
+
while view != nil {
|
|
43
|
+
if let webview = view as? WKWebView {
|
|
44
|
+
return webview
|
|
45
|
+
}
|
|
46
|
+
view = view?.superview
|
|
47
|
+
}
|
|
48
|
+
return nil
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
let swizzleFiveArgClosure = { (method: Method, selector: Selector) in
|
|
52
|
+
let originalImp: IMP = method_getImplementation(method)
|
|
53
|
+
let original: FiveArgClosureType = unsafeBitCast(originalImp, to: FiveArgClosureType.self)
|
|
54
|
+
let block: @convention(block) (Any, UnsafeRawPointer, Bool, Bool, Bool, Any?) -> Void = { (me, arg0, arg1, arg2, arg3, arg4) in
|
|
55
|
+
if let webview = containingWebView(me), let flag = webview.capacitor.keyboardShouldRequireUserInteraction {
|
|
56
|
+
original(me, selector, arg0, !flag, arg2, arg3, arg4)
|
|
57
|
+
} else {
|
|
58
|
+
original(me, selector, arg0, arg1, arg2, arg3, arg4)
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
let imp: IMP = imp_implementationWithBlock(block)
|
|
62
|
+
method_setImplementation(method, imp)
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
let selectorMkIV: Selector = sel_getUid("_elementDidFocus:userIsInteracting:blurPreviousNode:activityStateChanges:userObject:")
|
|
66
|
+
|
|
67
|
+
if let method = class_getInstanceMethod(targetClass, selectorMkIV) {
|
|
68
|
+
swizzleFiveArgClosure(method, selectorMkIV)
|
|
69
|
+
}
|
|
70
|
+
}()
|
|
71
|
+
|
|
72
|
+
var associatedKeyboardFlagValue: Any? {
|
|
73
|
+
get {
|
|
74
|
+
return objc_getAssociatedObject(self, &associatedKeyboardFlagHandle)
|
|
75
|
+
}
|
|
76
|
+
set {
|
|
77
|
+
objc_setAssociatedObject(self, &associatedKeyboardFlagHandle, newValue, .OBJC_ASSOCIATION_RETAIN_NONATOMIC)
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
}
|