@aigens/aigens-sdk-core 0.0.5 → 0.0.8
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/AigensAigensSdkCore.podspec +1 -1
- package/README.md +38 -6
- package/android/build.gradle +0 -3
- package/android/src/main/AndroidManifest.xml +9 -0
- package/android/src/main/java/com/aigens/sdk/WebContainerActivity.java +170 -7
- package/android/src/main/java/com/aigens/sdk/plugins/CorePlugin.java +80 -91
- package/dist/docs.json +36 -4
- package/dist/esm/definitions.d.ts +9 -1
- package/dist/esm/definitions.js.map +1 -1
- package/dist/esm/web.d.ts +9 -1
- package/dist/esm/web.js +11 -1
- package/dist/esm/web.js.map +1 -1
- package/dist/plugin.cjs.js +11 -1
- package/dist/plugin.cjs.js.map +1 -1
- package/dist/plugin.js +11 -1
- package/dist/plugin.js.map +1 -1
- package/ios/Plugin/CorePlugin.m +3 -1
- package/ios/Plugin/CorePlugin.swift +59 -624
- package/ios/Plugin/WebContainer.swift +83 -0
- package/ios/Plugin/WebContainer.xib +113 -0
- package/ios/Plugin/WebContainerViewController.swift +225 -17
- package/package.json +4 -1
@@ -0,0 +1,83 @@
|
|
1
|
+
//
|
2
|
+
// WebContainer.swift
|
3
|
+
// AigensSdkCore
|
4
|
+
//
|
5
|
+
// Created by 陈培爵 on 2022/6/7.
|
6
|
+
//
|
7
|
+
|
8
|
+
import UIKit
|
9
|
+
|
10
|
+
class WebContainer: UIView {
|
11
|
+
@IBOutlet weak var activity: UIActivityIndicatorView!
|
12
|
+
|
13
|
+
@IBOutlet weak var errorWrapper: UIView!
|
14
|
+
|
15
|
+
@IBOutlet weak var errorTextView: UITextView!
|
16
|
+
|
17
|
+
public weak var vc: WebContainerViewController?
|
18
|
+
|
19
|
+
public func setTheme(_ color: String) {
|
20
|
+
if let color = UIColor.getHex(hex: color) {
|
21
|
+
self.backgroundColor = color
|
22
|
+
}
|
23
|
+
}
|
24
|
+
override func awakeFromNib() {
|
25
|
+
super.awakeFromNib()
|
26
|
+
print("awakeFromNib")
|
27
|
+
}
|
28
|
+
|
29
|
+
private func hiddenSelf() {
|
30
|
+
self.alpha = 1.0
|
31
|
+
UIView.animate(withDuration: 0.5, animations: {
|
32
|
+
self.alpha = 0
|
33
|
+
})
|
34
|
+
}
|
35
|
+
|
36
|
+
public func showLoading(_ show: Bool) {
|
37
|
+
if show {
|
38
|
+
self.alpha = 1.0
|
39
|
+
activity.isHidden = false
|
40
|
+
activity.backgroundColor = .clear
|
41
|
+
activity.color = .darkGray
|
42
|
+
activity.alpha = 1.0
|
43
|
+
}else {
|
44
|
+
hiddenSelf()
|
45
|
+
activity?.isHidden = true
|
46
|
+
}
|
47
|
+
}
|
48
|
+
public func showError(_ show: Bool, _ error: String? = nil) {
|
49
|
+
if let e = error {
|
50
|
+
errorTextView?.text = e
|
51
|
+
}
|
52
|
+
if show {
|
53
|
+
errorWrapper?.isHidden = false
|
54
|
+
self.alpha = 1.0
|
55
|
+
}else {
|
56
|
+
errorWrapper?.isHidden = true
|
57
|
+
self.alpha = 0
|
58
|
+
}
|
59
|
+
|
60
|
+
}
|
61
|
+
|
62
|
+
/*
|
63
|
+
// Only override draw() if you perform custom drawing.
|
64
|
+
// An empty implementation adversely affects performance during animation.
|
65
|
+
override func draw(_ rect: CGRect) {
|
66
|
+
// Drawing code
|
67
|
+
}
|
68
|
+
*/
|
69
|
+
@IBAction func dismiss(_ sender: UIButton) {
|
70
|
+
self.vc?.dismiss(animated: true);
|
71
|
+
}
|
72
|
+
|
73
|
+
@IBAction func reload(_ sender: UIButton) {
|
74
|
+
self.vc?.webView?.reload()
|
75
|
+
}
|
76
|
+
}
|
77
|
+
|
78
|
+
extension WebContainer {
|
79
|
+
class func webContainer() -> WebContainer {
|
80
|
+
let bundle = Bundle(for: WebContainer.self)
|
81
|
+
return bundle.loadNibNamed("WebContainer", owner: self, options: nil)?.first as! WebContainer
|
82
|
+
}
|
83
|
+
}
|
@@ -0,0 +1,113 @@
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
2
|
+
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="19529" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES">
|
3
|
+
<device id="retina6_1" orientation="portrait" appearance="light"/>
|
4
|
+
<dependencies>
|
5
|
+
<deployment identifier="iOS"/>
|
6
|
+
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="19519"/>
|
7
|
+
<capability name="Safe area layout guides" minToolsVersion="9.0"/>
|
8
|
+
<capability name="System colors in document resources" minToolsVersion="11.0"/>
|
9
|
+
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
|
10
|
+
</dependencies>
|
11
|
+
<objects>
|
12
|
+
<placeholder placeholderIdentifier="IBFilesOwner" id="-1" userLabel="File's Owner"/>
|
13
|
+
<placeholder placeholderIdentifier="IBFirstResponder" id="-2" customClass="UIResponder"/>
|
14
|
+
<view contentMode="scaleToFill" id="iN0-l3-epB" customClass="WebContainer" customModule="Plugin" customModuleProvider="target">
|
15
|
+
<rect key="frame" x="0.0" y="0.0" width="414" height="896"/>
|
16
|
+
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
|
17
|
+
<subviews>
|
18
|
+
<activityIndicatorView opaque="NO" contentMode="scaleToFill" horizontalHuggingPriority="750" verticalHuggingPriority="750" animating="YES" style="large" translatesAutoresizingMaskIntoConstraints="NO" id="QRW-cT-ZYH">
|
19
|
+
<rect key="frame" x="188.5" y="119" width="37" height="37"/>
|
20
|
+
<color key="backgroundColor" white="0.0" alpha="0.0" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
|
21
|
+
<color key="color" systemColor="secondaryLabelColor"/>
|
22
|
+
</activityIndicatorView>
|
23
|
+
<view hidden="YES" contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="9XO-W2-mxO" userLabel="errorWrapper">
|
24
|
+
<rect key="frame" x="0.0" y="206" width="414" height="690"/>
|
25
|
+
<subviews>
|
26
|
+
<view hidden="YES" contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="XSc-rN-cN8">
|
27
|
+
<rect key="frame" x="206.5" y="560" width="1" height="100"/>
|
28
|
+
<color key="backgroundColor" systemColor="systemBackgroundColor"/>
|
29
|
+
<constraints>
|
30
|
+
<constraint firstAttribute="width" constant="1" id="JtJ-kb-hPE"/>
|
31
|
+
<constraint firstAttribute="height" constant="100" id="SFb-3i-Gvl"/>
|
32
|
+
</constraints>
|
33
|
+
</view>
|
34
|
+
<button opaque="NO" contentMode="scaleToFill" misplaced="YES" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="system" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="Rie-2B-ejA" userLabel="reload">
|
35
|
+
<rect key="frame" x="237.5" y="579" width="70" height="31"/>
|
36
|
+
<color key="backgroundColor" systemColor="linkColor"/>
|
37
|
+
<state key="normal" title="Button"/>
|
38
|
+
<buttonConfiguration key="configuration" style="filled" title="Reload">
|
39
|
+
<color key="baseForegroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
|
40
|
+
</buttonConfiguration>
|
41
|
+
<connections>
|
42
|
+
<action selector="reload:" destination="iN0-l3-epB" eventType="touchUpInside" id="PwX-vF-t6u"/>
|
43
|
+
</connections>
|
44
|
+
</button>
|
45
|
+
<textView clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="scaleToFill" editable="NO" text="Got some errors, please try again later." textAlignment="center" selectable="NO" translatesAutoresizingMaskIntoConstraints="NO" id="8vI-mF-YrJ">
|
46
|
+
<rect key="frame" x="30" y="30" width="354" height="519"/>
|
47
|
+
<color key="backgroundColor" white="0.0" alpha="0.0" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
|
48
|
+
<color key="textColor" systemColor="systemPinkColor"/>
|
49
|
+
<fontDescription key="fontDescription" type="system" pointSize="17"/>
|
50
|
+
<textInputTraits key="textInputTraits" autocapitalizationType="sentences"/>
|
51
|
+
</textView>
|
52
|
+
<button opaque="NO" contentMode="scaleToFill" misplaced="YES" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="system" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="3jG-Lv-8dD" userLabel="back">
|
53
|
+
<rect key="frame" x="120.5" y="579" width="70" height="31"/>
|
54
|
+
<color key="backgroundColor" systemColor="linkColor"/>
|
55
|
+
<state key="normal" title="Button"/>
|
56
|
+
<buttonConfiguration key="configuration" style="filled" title="Back">
|
57
|
+
<color key="baseForegroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
|
58
|
+
</buttonConfiguration>
|
59
|
+
<connections>
|
60
|
+
<action selector="dismiss:" destination="iN0-l3-epB" eventType="touchUpInside" id="uVj-47-Wse"/>
|
61
|
+
</connections>
|
62
|
+
</button>
|
63
|
+
</subviews>
|
64
|
+
<color key="backgroundColor" white="0.0" alpha="0.0" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
|
65
|
+
<constraints>
|
66
|
+
<constraint firstItem="8vI-mF-YrJ" firstAttribute="leading" secondItem="9XO-W2-mxO" secondAttribute="leading" constant="30" id="AS7-Ga-vyq"/>
|
67
|
+
<constraint firstItem="Rie-2B-ejA" firstAttribute="leading" secondItem="XSc-rN-cN8" secondAttribute="trailing" constant="30" id="CyI-hc-XkI"/>
|
68
|
+
<constraint firstItem="3jG-Lv-8dD" firstAttribute="bottom" secondItem="Rie-2B-ejA" secondAttribute="bottom" id="HAh-cE-mQ6"/>
|
69
|
+
<constraint firstItem="XSc-rN-cN8" firstAttribute="leading" secondItem="3jG-Lv-8dD" secondAttribute="trailing" constant="30" id="PAe-EE-twu"/>
|
70
|
+
<constraint firstAttribute="bottom" secondItem="XSc-rN-cN8" secondAttribute="bottom" constant="30" id="RPJ-VJ-HXw"/>
|
71
|
+
<constraint firstAttribute="bottom" secondItem="3jG-Lv-8dD" secondAttribute="bottom" constant="80" id="Upv-ms-zNA"/>
|
72
|
+
<constraint firstItem="8vI-mF-YrJ" firstAttribute="top" secondItem="9XO-W2-mxO" secondAttribute="top" constant="30" id="YIP-1g-G6E"/>
|
73
|
+
<constraint firstItem="3jG-Lv-8dD" firstAttribute="top" secondItem="8vI-mF-YrJ" secondAttribute="bottom" constant="30" id="aeR-w6-BjA"/>
|
74
|
+
<constraint firstItem="8vI-mF-YrJ" firstAttribute="centerX" secondItem="9XO-W2-mxO" secondAttribute="centerX" id="kmK-Va-dvk"/>
|
75
|
+
<constraint firstAttribute="trailing" secondItem="8vI-mF-YrJ" secondAttribute="trailing" constant="30" id="mUr-wg-3M2"/>
|
76
|
+
<constraint firstItem="XSc-rN-cN8" firstAttribute="centerX" secondItem="9XO-W2-mxO" secondAttribute="centerX" id="pNO-0x-6Wm"/>
|
77
|
+
</constraints>
|
78
|
+
</view>
|
79
|
+
</subviews>
|
80
|
+
<viewLayoutGuide key="safeArea" id="vUN-kp-3ea"/>
|
81
|
+
<color key="backgroundColor" systemColor="systemBackgroundColor"/>
|
82
|
+
<constraints>
|
83
|
+
<constraint firstItem="QRW-cT-ZYH" firstAttribute="top" secondItem="vUN-kp-3ea" secondAttribute="top" constant="75" id="R5H-tF-5z7"/>
|
84
|
+
<constraint firstItem="9XO-W2-mxO" firstAttribute="top" secondItem="QRW-cT-ZYH" secondAttribute="bottom" constant="50" id="X4C-yj-HyP"/>
|
85
|
+
<constraint firstAttribute="bottom" secondItem="9XO-W2-mxO" secondAttribute="bottom" id="cOL-UR-HYb"/>
|
86
|
+
<constraint firstItem="vUN-kp-3ea" firstAttribute="trailing" secondItem="9XO-W2-mxO" secondAttribute="trailing" id="fAe-qZ-xE4"/>
|
87
|
+
<constraint firstItem="9XO-W2-mxO" firstAttribute="leading" secondItem="vUN-kp-3ea" secondAttribute="leading" id="haw-0Q-SQQ"/>
|
88
|
+
<constraint firstItem="QRW-cT-ZYH" firstAttribute="centerX" secondItem="iN0-l3-epB" secondAttribute="centerX" id="lwz-JW-uoD"/>
|
89
|
+
</constraints>
|
90
|
+
<freeformSimulatedSizeMetrics key="simulatedDestinationMetrics"/>
|
91
|
+
<connections>
|
92
|
+
<outlet property="activity" destination="QRW-cT-ZYH" id="fKy-zs-iDE"/>
|
93
|
+
<outlet property="errorTextView" destination="8vI-mF-YrJ" id="4uw-Iq-Axh"/>
|
94
|
+
<outlet property="errorWrapper" destination="9XO-W2-mxO" id="ipj-rF-hT1"/>
|
95
|
+
</connections>
|
96
|
+
<point key="canvasLocation" x="137.68115942028987" y="102.45535714285714"/>
|
97
|
+
</view>
|
98
|
+
</objects>
|
99
|
+
<resources>
|
100
|
+
<systemColor name="linkColor">
|
101
|
+
<color red="0.0" green="0.47843137254901963" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
|
102
|
+
</systemColor>
|
103
|
+
<systemColor name="secondaryLabelColor">
|
104
|
+
<color red="0.23529411764705882" green="0.23529411764705882" blue="0.2627450980392157" alpha="0.59999999999999998" colorSpace="custom" customColorSpace="sRGB"/>
|
105
|
+
</systemColor>
|
106
|
+
<systemColor name="systemBackgroundColor">
|
107
|
+
<color white="1" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
|
108
|
+
</systemColor>
|
109
|
+
<systemColor name="systemPinkColor">
|
110
|
+
<color red="1" green="0.17647058823529413" blue="0.33333333333333331" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
|
111
|
+
</systemColor>
|
112
|
+
</resources>
|
113
|
+
</document>
|
@@ -11,15 +11,99 @@ import Capacitor
|
|
11
11
|
|
12
12
|
@objc open class WebContainerViewController: CAPBridgeViewController {
|
13
13
|
|
14
|
+
// {themeColor: "#xxxxxx"}
|
14
15
|
public var options: Dictionary<String, Any>?
|
15
|
-
|
16
|
+
|
17
|
+
var externalProtocols: [String] = [
|
18
|
+
"octopus://", "alipay://", "alipays://", "alipayhk://", "https://itunes.apple.com", "tel:", "mailto:", "itms-apps://itunes.apple.com", "https://apps.apple.com", "payme://"
|
19
|
+
]
|
20
|
+
let containerView = WebContainer.webContainer()
|
21
|
+
var webContainerView: WebContainer {
|
22
|
+
return containerView
|
23
|
+
}
|
16
24
|
override open func viewDidLoad() {
|
17
25
|
|
18
26
|
print("WebContainerViewController viewDidLoad")
|
19
27
|
|
20
28
|
self.becomeFirstResponder()
|
21
29
|
loadWebViewCustom()
|
22
|
-
|
30
|
+
initView()
|
31
|
+
|
32
|
+
}
|
33
|
+
|
34
|
+
private func initView(){
|
35
|
+
|
36
|
+
print("VC initView")
|
37
|
+
|
38
|
+
//let bundle = Bundle(for: WebContainerViewController.self)
|
39
|
+
//let containerView = WebContainerView()
|
40
|
+
//let containerView = bundle.loadNibNamed("WebContainerView", owner: self, options: nil)?.first as! UIView
|
41
|
+
|
42
|
+
self.view.addSubview(webContainerView)
|
43
|
+
webContainerView.frame = CGRect(x: 0, y: 0, width: UIScreen.main.bounds.size.width, height: UIScreen.main.bounds.size.height)
|
44
|
+
setupOptions(webContainerView)
|
45
|
+
containerView.vc = self
|
46
|
+
|
47
|
+
//
|
48
|
+
//
|
49
|
+
|
50
|
+
|
51
|
+
// let containerView = WebContainerView()
|
52
|
+
// self.view = containerView
|
53
|
+
//
|
54
|
+
// //containerView.frame = self.view!.bounds
|
55
|
+
// containerView.backgroundColor = UIColor.red
|
56
|
+
// containerView.translatesAutoresizingMaskIntoConstraints = false
|
57
|
+
//
|
58
|
+
// let webview = self.webView
|
59
|
+
// webview?.frame = containerView.webArea!.bounds
|
60
|
+
// webview?.frame.size = containerView.webArea.frame.size
|
61
|
+
// containerView.webArea.addSubview(self.webView!)
|
62
|
+
//
|
63
|
+
|
64
|
+
|
65
|
+
}
|
66
|
+
|
67
|
+
open override func viewWillLayoutSubviews() {
|
68
|
+
super.viewWillLayoutSubviews()
|
69
|
+
webContainerView.frame = CGRect(x: 0, y: 0, width: UIScreen.main.bounds.size.width, height: UIScreen.main.bounds.size.height)
|
70
|
+
}
|
71
|
+
|
72
|
+
private func setupOptions(_ view: WebContainer) {
|
73
|
+
if let theme = self.options?["themeColor"] as? String, let color = UIColor.getHex(hex: theme) {
|
74
|
+
self.view.backgroundColor = color
|
75
|
+
self.webView?.backgroundColor = color
|
76
|
+
self.webView?.scrollView.backgroundColor = color
|
77
|
+
view.setTheme(theme)
|
78
|
+
}
|
79
|
+
if let externalProtocols = options?["externalProtocols"] as? [String] {
|
80
|
+
self.externalProtocols.append(contentsOf: externalProtocols)
|
81
|
+
}
|
82
|
+
|
83
|
+
}
|
84
|
+
|
85
|
+
public final func loadWebViewCustom() {
|
86
|
+
|
87
|
+
//let bridge = self.bridge
|
88
|
+
//let plugins = self.bridge["plugins"]
|
89
|
+
|
90
|
+
|
91
|
+
let urlString = self.options?["url"] as? String;
|
92
|
+
|
93
|
+
if(urlString == nil){
|
94
|
+
return;
|
95
|
+
}
|
96
|
+
|
97
|
+
let url = URL(string: urlString!)
|
98
|
+
|
99
|
+
let member = self.options?["member"] as? Dictionary<String, Any>
|
100
|
+
|
101
|
+
CorePlugin.member = member
|
102
|
+
|
103
|
+
//bridge.webViewDelegationHandler.willLoadWebview(webView)
|
104
|
+
_ = webView?.load(URLRequest(url: url!))
|
105
|
+
webView?.navigationDelegate = self
|
106
|
+
|
23
107
|
}
|
24
108
|
|
25
109
|
//this method overwrite parent to return a desc with custom config.json
|
@@ -48,29 +132,153 @@ import Capacitor
|
|
48
132
|
|
49
133
|
return descriptor
|
50
134
|
}
|
135
|
+
|
136
|
+
deinit {
|
137
|
+
print("WebContainerViewController deinit")
|
138
|
+
}
|
51
139
|
|
52
|
-
|
53
|
-
|
54
|
-
//let bridge = self.bridge
|
55
|
-
//let plugins = self.bridge["plugins"]
|
56
|
-
|
140
|
+
|
141
|
+
}
|
57
142
|
|
58
|
-
|
143
|
+
extension WebContainerViewController: WKNavigationDelegate {
|
144
|
+
// The force unwrap is part of the protocol declaration, so we should keep it.
|
145
|
+
// swiftlint:disable:next implicitly_unwrapped_optional
|
146
|
+
public func webView(_ webView: WKWebView, didStartProvisionalNavigation navigation: WKNavigation!) {
|
147
|
+
// Reset the bridge on each navigation
|
148
|
+
// self.bridge?.reset()
|
149
|
+
}
|
150
|
+
|
151
|
+
public func webView(_ webView: WKWebView, didCommit navigation: WKNavigation!) {
|
152
|
+
webContainerView.showError(false)
|
153
|
+
webContainerView.showLoading(true)
|
154
|
+
}
|
155
|
+
|
156
|
+
public func webView(_ webView: WKWebView, decidePolicyFor navigationAction: WKNavigationAction, decisionHandler: @escaping (WKNavigationActionPolicy) -> Void) {
|
157
|
+
// post a notification for any listeners
|
158
|
+
NotificationCenter.default.post(name: .capacitorDecidePolicyForNavigationAction, object: navigationAction)
|
59
159
|
|
60
|
-
|
61
|
-
|
160
|
+
// sanity check, these shouldn't ever be nil in practice
|
161
|
+
guard let bridge = bridge, let navURL = navigationAction.request.url else {
|
162
|
+
decisionHandler(.allow)
|
163
|
+
return
|
62
164
|
}
|
63
|
-
|
64
|
-
let url = URL(string: urlString!)
|
65
|
-
|
66
|
-
let member = self.options?["member"] as? Dictionary<String, Any>
|
67
165
|
|
68
|
-
|
166
|
+
var isCanOpen = false
|
167
|
+
if externalProtocols.count > 0 {
|
168
|
+
externalProtocols.forEach { (url) in
|
169
|
+
if (navURL.absoluteString.starts(with: url)) {
|
170
|
+
isCanOpen = UIApplication.shared.canOpenURL(navURL) ;
|
171
|
+
return;
|
172
|
+
}
|
173
|
+
}
|
174
|
+
}
|
69
175
|
|
176
|
+
if isCanOpen {
|
177
|
+
if #available(iOS 10.0, *) {
|
178
|
+
UIApplication.shared.open(navURL, options: [:], completionHandler: nil);
|
179
|
+
} else {
|
180
|
+
UIApplication.shared.openURL(navURL)
|
181
|
+
}
|
182
|
+
decisionHandler(.cancel)
|
183
|
+
return;
|
184
|
+
}
|
70
185
|
|
71
|
-
//bridge.webViewDelegationHandler.willLoadWebview(webView)
|
72
|
-
_ = webView?.load(URLRequest(url: url!))
|
73
186
|
|
187
|
+
// first, give plugins the chance to handle the decision
|
188
|
+
// for pluginObject in bridge.plugins {
|
189
|
+
// let plugin = pluginObject.value
|
190
|
+
// let selector = NSSelectorFromString("shouldOverrideLoad:")
|
191
|
+
// if plugin.responds(to: selector) {
|
192
|
+
// let shouldOverrideLoad = plugin.shouldOverrideLoad(navigationAction)
|
193
|
+
// if shouldOverrideLoad != nil {
|
194
|
+
// if shouldOverrideLoad == true {
|
195
|
+
// decisionHandler(.cancel)
|
196
|
+
// return
|
197
|
+
// } else if shouldOverrideLoad == false {
|
198
|
+
// decisionHandler(.allow)
|
199
|
+
// return
|
200
|
+
// }
|
201
|
+
// }
|
202
|
+
// }
|
203
|
+
// }
|
204
|
+
|
205
|
+
// next, check if this is covered by the allowedNavigation configuration
|
206
|
+
if let host = navURL.host, bridge.config.shouldAllowNavigation(to: host) {
|
207
|
+
decisionHandler(.allow)
|
208
|
+
return
|
209
|
+
}
|
210
|
+
|
211
|
+
// otherwise, is this a new window or a main frame navigation but to an outside source
|
212
|
+
let toplevelNavigation = (navigationAction.targetFrame == nil || navigationAction.targetFrame?.isMainFrame == true)
|
213
|
+
if navURL.absoluteString.contains(bridge.config.serverURL.absoluteString) == false, toplevelNavigation {
|
214
|
+
// disallow and let the system handle it
|
215
|
+
if UIApplication.shared.applicationState == .active {
|
216
|
+
UIApplication.shared.open(navURL, options: [:], completionHandler: nil)
|
217
|
+
}
|
218
|
+
decisionHandler(.cancel)
|
219
|
+
return
|
220
|
+
}
|
221
|
+
|
222
|
+
// fallthrough to allowing it
|
223
|
+
decisionHandler(.allow)
|
224
|
+
}
|
225
|
+
|
226
|
+
|
227
|
+
// The force unwrap is part of the protocol declaration, so we should keep it.
|
228
|
+
// swiftlint:disable:next implicitly_unwrapped_optional
|
229
|
+
public func webView(_ webView: WKWebView, didFinish navigation: WKNavigation!) {
|
230
|
+
// if case .initialLoad(let isOpaque) = webViewLoadingState {
|
231
|
+
// webView.isOpaque = isOpaque
|
232
|
+
// webViewLoadingState = .subsequentLoad
|
233
|
+
// }
|
234
|
+
webContainerView.showLoading(false)
|
235
|
+
webContainerView.showError(false)
|
236
|
+
CAPLog.print("⚡️ WebView loaded")
|
237
|
+
}
|
238
|
+
|
239
|
+
// The force unwrap is part of the protocol declaration, so we should keep it.
|
240
|
+
// swiftlint:disable:next implicitly_unwrapped_optional
|
241
|
+
public func webView(_ webView: WKWebView, didFail navigation: WKNavigation!, withError error: Error) {
|
242
|
+
// if case .initialLoad(let isOpaque) = webViewLoadingState {
|
243
|
+
// webView.isOpaque = isOpaque
|
244
|
+
// webViewLoadingState = .subsequentLoad
|
245
|
+
// }
|
246
|
+
webContainerView.showLoading(false)
|
247
|
+
|
248
|
+
webContainerView.showError(true, error.localizedDescription)
|
249
|
+
CAPLog.print("⚡️ WebView failed to load")
|
250
|
+
CAPLog.print("⚡️ Error: " + error.localizedDescription)
|
251
|
+
}
|
252
|
+
|
253
|
+
// The force unwrap is part of the protocol declaration, so we should keep it.
|
254
|
+
// swiftlint:disable:next implicitly_unwrapped_optional
|
255
|
+
public func webView(_ webView: WKWebView, didFailProvisionalNavigation navigation: WKNavigation!, withError error: Error) {
|
256
|
+
webContainerView.showLoading(false)
|
257
|
+
// cancel
|
258
|
+
let e = error as NSError
|
259
|
+
if (e.code == NSURLErrorCancelled || e.code == -999) {
|
260
|
+
webContainerView.showError(false)
|
261
|
+
}
|
262
|
+
CAPLog.print("⚡️ WebView failed provisional navigation")
|
263
|
+
CAPLog.print("⚡️ Error: " + error.localizedDescription)
|
264
|
+
webContainerView.showError(true, error.localizedDescription)
|
265
|
+
}
|
266
|
+
|
267
|
+
public func webViewWebContentProcessDidTerminate(_ webView: WKWebView) {
|
268
|
+
webView.reload()
|
269
|
+
}
|
270
|
+
}
|
74
271
|
|
272
|
+
extension UIColor {
|
273
|
+
static func getHex(hex: String, _ alpha: CGFloat = 1.0) -> UIColor? {
|
274
|
+
guard !hex.isEmpty && hex.hasPrefix("#") else { return nil }
|
275
|
+
var rgbValue: UInt32 = 0
|
276
|
+
let scanner = Scanner(string: hex)
|
277
|
+
scanner.scanLocation = 1
|
278
|
+
guard scanner.scanHexInt32(&rgbValue) else { return nil }
|
279
|
+
return UIColor(red: CGFloat((rgbValue & 0xFF0000) >> 16) / 255.0,
|
280
|
+
green: CGFloat((rgbValue & 0xFF00) >> 8) / 255.0,
|
281
|
+
blue: CGFloat((rgbValue & 0xFF)) / 255.0,
|
282
|
+
alpha: alpha);
|
75
283
|
}
|
76
284
|
}
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@aigens/aigens-sdk-core",
|
3
|
-
"version": "0.0.
|
3
|
+
"version": "0.0.8",
|
4
4
|
"description": "Aigens Order.Place Core Plugin",
|
5
5
|
"main": "dist/plugin.cjs.js",
|
6
6
|
"module": "dist/esm/index.js",
|
@@ -74,5 +74,8 @@
|
|
74
74
|
"android": {
|
75
75
|
"src": "android"
|
76
76
|
}
|
77
|
+
},
|
78
|
+
"dependencies": {
|
79
|
+
"aigens-mono": "file:../.."
|
77
80
|
}
|
78
81
|
}
|