@capgo/inappbrowser 0.0.1
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/CapgoInappbrowser.podspec +17 -0
- package/README.md +118 -0
- package/android/build.gradle +58 -0
- package/android/src/main/AndroidManifest.xml +3 -0
- package/android/src/main/java/ee/forgr/capacitor_inappbrowser/InAppBrowserPlugin.java +160 -0
- package/android/src/main/java/ee/forgr/capacitor_inappbrowser/Options.java +88 -0
- package/android/src/main/java/ee/forgr/capacitor_inappbrowser/WebViewCallbacks.java +7 -0
- package/android/src/main/java/ee/forgr/capacitor_inappbrowser/WebViewDialog.java +218 -0
- package/android/src/main/res/.gitkeep +0 -0
- package/android/src/main/res/drawable/arrow_back_disabled.xml +9 -0
- package/android/src/main/res/drawable/arrow_back_enabled.xml +9 -0
- package/android/src/main/res/drawable/arrow_forward_disabled.xml +9 -0
- package/android/src/main/res/drawable/arrow_forward_enabled.xml +9 -0
- package/android/src/main/res/drawable/ic_clear_24px.xml +9 -0
- package/android/src/main/res/layout/activity_browser.xml +22 -0
- package/android/src/main/res/layout/bridge_layout_main.xml +15 -0
- package/android/src/main/res/layout/content_browser.xml +16 -0
- package/android/src/main/res/layout/tool_bar.xml +50 -0
- package/android/src/main/res/values/colors.xml +5 -0
- package/android/src/main/res/values/dimens.xml +3 -0
- package/android/src/main/res/values/strings.xml +9 -0
- package/android/src/main/res/values/styles.xml +12 -0
- package/dist/docs.json +234 -0
- package/dist/esm/definitions.d.ts +34 -0
- package/dist/esm/definitions.js +8 -0
- package/dist/esm/definitions.js.map +1 -0
- package/dist/esm/index.d.ts +4 -0
- package/dist/esm/index.js +7 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/web.d.ts +7 -0
- package/dist/esm/web.js +16 -0
- package/dist/esm/web.js.map +1 -0
- package/dist/plugin.cjs.js +40 -0
- package/dist/plugin.cjs.js.map +1 -0
- package/dist/plugin.js +43 -0
- package/dist/plugin.js.map +1 -0
- package/ios/Plugin/Enums.swift +64 -0
- package/ios/Plugin/InAppBrowserPlugin.h +10 -0
- package/ios/Plugin/InAppBrowserPlugin.m +14 -0
- package/ios/Plugin/InAppBrowserPlugin.swift +191 -0
- package/ios/Plugin/Info.plist +24 -0
- package/ios/Plugin/WKWebViewController.swift +782 -0
- package/package.json +78 -0
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Enums.swift
|
|
3
|
+
// Sample
|
|
4
|
+
//
|
|
5
|
+
// Created by Meniny on 2018-01-20.
|
|
6
|
+
// Copyright © 2018年 Meniny. All rights reserved.
|
|
7
|
+
//
|
|
8
|
+
|
|
9
|
+
import Foundation
|
|
10
|
+
|
|
11
|
+
public enum WKWebSource: Equatable {
|
|
12
|
+
case remote(URL)
|
|
13
|
+
case file(URL, access: URL)
|
|
14
|
+
case string(String, base: URL?)
|
|
15
|
+
|
|
16
|
+
public var url: URL? {
|
|
17
|
+
switch self {
|
|
18
|
+
case .remote(let u): return u
|
|
19
|
+
case .file(let u, access: _): return u
|
|
20
|
+
default: return nil
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
public var remoteURL: URL? {
|
|
25
|
+
switch self {
|
|
26
|
+
case .remote(let u): return u
|
|
27
|
+
default: return nil
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
public var absoluteString: String? {
|
|
32
|
+
switch self {
|
|
33
|
+
case .remote(let u): return u.absoluteString
|
|
34
|
+
case .file(let u, access: _): return u.absoluteString
|
|
35
|
+
default: return nil
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
public enum BarButtonItemType {
|
|
41
|
+
case back
|
|
42
|
+
case forward
|
|
43
|
+
case reload
|
|
44
|
+
case stop
|
|
45
|
+
case activity
|
|
46
|
+
case done
|
|
47
|
+
case flexibleSpace
|
|
48
|
+
case custom(icon: UIImage?, title: String?, action: (WKWebViewController) -> Void)
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
public enum NavigationBarPosition: String, Equatable, Codable {
|
|
52
|
+
case none
|
|
53
|
+
case left
|
|
54
|
+
case right
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
@objc public enum NavigationType: Int, Equatable, Codable {
|
|
58
|
+
case linkActivated
|
|
59
|
+
case formSubmitted
|
|
60
|
+
case backForward
|
|
61
|
+
case reload
|
|
62
|
+
case formResubmitted
|
|
63
|
+
case other
|
|
64
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
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
|
+
|
|
@@ -0,0 +1,14 @@
|
|
|
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(open, CAPPluginReturnPromise);
|
|
9
|
+
CAP_PLUGIN_METHOD(show, CAPPluginReturnPromise);
|
|
10
|
+
CAP_PLUGIN_METHOD(close, CAPPluginReturnPromise);
|
|
11
|
+
CAP_PLUGIN_METHOD(hide, CAPPluginReturnPromise);
|
|
12
|
+
CAP_PLUGIN_METHOD(executeScript, CAPPluginReturnPromise);
|
|
13
|
+
CAP_PLUGIN_METHOD(insertCSS, CAPPluginReturnPromise);
|
|
14
|
+
)
|
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
import Foundation
|
|
2
|
+
import Capacitor
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Please read the Capacitor iOS Plugin Development Guide
|
|
6
|
+
* here: https://capacitorjs.com/docs/plugins/ios
|
|
7
|
+
*/
|
|
8
|
+
@objc(InAppBrowserPlugin)
|
|
9
|
+
public class InAppBrowserPlugin: CAPPlugin {
|
|
10
|
+
var navigationWebViewController: UINavigationController?
|
|
11
|
+
private var privacyScreen: UIImageView?
|
|
12
|
+
private var isSetupDone = false
|
|
13
|
+
var currentPluginCall: CAPPluginCall?
|
|
14
|
+
var isPresentAfterPageLoad = false
|
|
15
|
+
|
|
16
|
+
private func setup(){
|
|
17
|
+
self.isSetupDone = true
|
|
18
|
+
|
|
19
|
+
#if swift(>=4.2)
|
|
20
|
+
NotificationCenter.default.addObserver(self, selector: #selector(appDidBecomeActive(_:)), name: UIApplication.didBecomeActiveNotification, object: nil)
|
|
21
|
+
NotificationCenter.default.addObserver(self, selector: #selector(appWillResignActive(_:)), name: UIApplication.willResignActiveNotification, object: nil)
|
|
22
|
+
#else
|
|
23
|
+
NotificationCenter.default.addObserver(self, selector: #selector(appDidBecomeActive(_:)), name:.UIApplicationDidBecomeActive, object: nil)
|
|
24
|
+
NotificationCenter.default.addObserver(self, selector: #selector(appWillResignActive(_:)), name:.UIApplicationWillResignActive, object: nil)
|
|
25
|
+
#endif
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
func presentView() {
|
|
29
|
+
self.bridge.viewController.present(self.navigationWebViewController!, animated: true, completion: {
|
|
30
|
+
self.currentPluginCall?.success()
|
|
31
|
+
})
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
@objc func openWebView(_ call: CAPPluginCall) {
|
|
35
|
+
if !self.isSetupDone {
|
|
36
|
+
self.setup()
|
|
37
|
+
}
|
|
38
|
+
self.currentPluginCall = call
|
|
39
|
+
|
|
40
|
+
guard let urlString = call.getString("url") else {
|
|
41
|
+
call.error("Must provide a URL to open")
|
|
42
|
+
return
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
if urlString.isEmpty {
|
|
46
|
+
call.error("URL must not be empty")
|
|
47
|
+
return
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
let headers = call.get("headers", [String: String].self, [:])
|
|
51
|
+
|
|
52
|
+
var disclaimerContent = call.getObject("shareDisclaimer", defaultValue: nil)
|
|
53
|
+
let toolbarType = call.getString("toolbarType")
|
|
54
|
+
if toolbarType != "activity" {
|
|
55
|
+
disclaimerContent = nil
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
self.isPresentAfterPageLoad = call.getBool("isPresentAfterPageLoad", false) ?? false
|
|
59
|
+
|
|
60
|
+
DispatchQueue.main.async {
|
|
61
|
+
let url = URL(string: urlString)
|
|
62
|
+
let webViewController: WKWebViewController?
|
|
63
|
+
|
|
64
|
+
if self.isPresentAfterPageLoad {
|
|
65
|
+
webViewController = WKWebViewController.init(url: url!, headers: headers ?? [:])
|
|
66
|
+
} else {
|
|
67
|
+
webViewController = WKWebViewController.init()
|
|
68
|
+
webViewController?.setHeaders(headers: headers ?? [:])
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
webViewController?.source = .remote(url!)
|
|
72
|
+
webViewController?.leftNavigaionBarItemTypes = self.getToolbarItems(toolbarType: toolbarType ?? "")
|
|
73
|
+
|
|
74
|
+
webViewController?.toolbarItemTypes = []
|
|
75
|
+
webViewController?.doneBarButtonItemPosition = .right
|
|
76
|
+
webViewController?.capBrowserPlugin = self
|
|
77
|
+
webViewController?.title = call.getString("title") ?? ""
|
|
78
|
+
webViewController?.shareSubject = call.getString("shareSubject")
|
|
79
|
+
webViewController?.shareDisclaimer = disclaimerContent
|
|
80
|
+
self.navigationWebViewController = UINavigationController.init(rootViewController: webViewController!)
|
|
81
|
+
self.navigationWebViewController?.navigationBar.isTranslucent = false
|
|
82
|
+
self.navigationWebViewController?.toolbar.isTranslucent = false
|
|
83
|
+
self.navigationWebViewController?.navigationBar.backgroundColor = .white
|
|
84
|
+
self.navigationWebViewController?.toolbar.backgroundColor = .white
|
|
85
|
+
self.navigationWebViewController?.modalPresentationStyle = .fullScreen
|
|
86
|
+
if toolbarType == "blank" {
|
|
87
|
+
self.navigationWebViewController?.navigationBar.isHidden = true
|
|
88
|
+
}
|
|
89
|
+
if !self.isPresentAfterPageLoad {
|
|
90
|
+
self.presentView()
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
func getToolbarItems(toolbarType: String) -> [BarButtonItemType] {
|
|
96
|
+
var result: [BarButtonItemType] = []
|
|
97
|
+
if toolbarType == "activity" {
|
|
98
|
+
result.append(.activity)
|
|
99
|
+
} else if toolbarType == "navigation" {
|
|
100
|
+
result.append(.back)
|
|
101
|
+
result.append(.forward)
|
|
102
|
+
}
|
|
103
|
+
return result
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
@objc func open(_ call: CAPPluginCall) {
|
|
107
|
+
if !self.isSetupDone {
|
|
108
|
+
self.setup()
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
self.currentPluginCall = call
|
|
112
|
+
|
|
113
|
+
guard let urlString = call.getString("url") else {
|
|
114
|
+
call.error("Must provide a URL to open")
|
|
115
|
+
return
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
if urlString.isEmpty {
|
|
119
|
+
call.error("URL must not be empty")
|
|
120
|
+
return
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
let headers = call.get("headers", [String: String].self, [:])
|
|
124
|
+
|
|
125
|
+
self.isPresentAfterPageLoad = call.getBool("isPresentAfterPageLoad", false) ?? false
|
|
126
|
+
|
|
127
|
+
DispatchQueue.main.async {
|
|
128
|
+
let url = URL(string: urlString)
|
|
129
|
+
let webViewController: WKWebViewController?
|
|
130
|
+
|
|
131
|
+
if self.isPresentAfterPageLoad {
|
|
132
|
+
webViewController = WKWebViewController.init(url: url!, headers: headers ?? [:])
|
|
133
|
+
} else {
|
|
134
|
+
webViewController = WKWebViewController.init()
|
|
135
|
+
webViewController?.setHeaders(headers: headers ?? [:])
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
webViewController?.source = .remote(url!)
|
|
139
|
+
webViewController?.leftNavigaionBarItemTypes = [.reload]
|
|
140
|
+
webViewController?.toolbarItemTypes = [.back, .forward, .activity]
|
|
141
|
+
webViewController?.capBrowserPlugin = self
|
|
142
|
+
webViewController?.hasDynamicTitle = true
|
|
143
|
+
self.navigationWebViewController = UINavigationController.init(rootViewController: webViewController!)
|
|
144
|
+
self.navigationWebViewController?.navigationBar.isTranslucent = false
|
|
145
|
+
self.navigationWebViewController?.toolbar.isTranslucent = false
|
|
146
|
+
self.navigationWebViewController?.navigationBar.backgroundColor = .white
|
|
147
|
+
self.navigationWebViewController?.toolbar.backgroundColor = .white
|
|
148
|
+
self.navigationWebViewController?.modalPresentationStyle = .fullScreen
|
|
149
|
+
if !self.isPresentAfterPageLoad {
|
|
150
|
+
self.presentView()
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
@objc func close(_ call: CAPPluginCall) {
|
|
156
|
+
DispatchQueue.main.async {
|
|
157
|
+
self.navigationWebViewController?.dismiss(animated: true, completion: nil)
|
|
158
|
+
call.success()
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
private func showPrivacyScreen(){
|
|
163
|
+
if privacyScreen == nil {
|
|
164
|
+
self.privacyScreen = UIImageView()
|
|
165
|
+
if let launchImage = UIImage(named: "LaunchImage") {
|
|
166
|
+
privacyScreen!.image = launchImage
|
|
167
|
+
privacyScreen!.frame = UIScreen.main.bounds
|
|
168
|
+
privacyScreen!.contentMode = .scaleAspectFill
|
|
169
|
+
privacyScreen!.isUserInteractionEnabled = false
|
|
170
|
+
} else if let launchImage = UIImage(named: "Splash") {
|
|
171
|
+
privacyScreen!.image = launchImage
|
|
172
|
+
privacyScreen!.frame = UIScreen.main.bounds
|
|
173
|
+
privacyScreen!.contentMode = .scaleAspectFill
|
|
174
|
+
privacyScreen!.isUserInteractionEnabled = false
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
self.navigationWebViewController?.view.addSubview(self.privacyScreen!)
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
private func hidePrivacyScreen(){
|
|
181
|
+
self.privacyScreen?.removeFromSuperview()
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
@objc func appDidBecomeActive(_ notification: NSNotification) {
|
|
185
|
+
self.hidePrivacyScreen()
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
@objc func appWillResignActive(_ notification: NSNotification) {
|
|
189
|
+
self.showPrivacyScreen()
|
|
190
|
+
}
|
|
191
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
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>CFBundleDevelopmentRegion</key>
|
|
6
|
+
<string>$(DEVELOPMENT_LANGUAGE)</string>
|
|
7
|
+
<key>CFBundleExecutable</key>
|
|
8
|
+
<string>$(EXECUTABLE_NAME)</string>
|
|
9
|
+
<key>CFBundleIdentifier</key>
|
|
10
|
+
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
|
|
11
|
+
<key>CFBundleInfoDictionaryVersion</key>
|
|
12
|
+
<string>6.0</string>
|
|
13
|
+
<key>CFBundleName</key>
|
|
14
|
+
<string>$(PRODUCT_NAME)</string>
|
|
15
|
+
<key>CFBundlePackageType</key>
|
|
16
|
+
<string>FMWK</string>
|
|
17
|
+
<key>CFBundleShortVersionString</key>
|
|
18
|
+
<string>1.0</string>
|
|
19
|
+
<key>CFBundleVersion</key>
|
|
20
|
+
<string>$(CURRENT_PROJECT_VERSION)</string>
|
|
21
|
+
<key>NSPrincipalClass</key>
|
|
22
|
+
<string></string>
|
|
23
|
+
</dict>
|
|
24
|
+
</plist>
|