@modos189/nativescript-webview-x 1.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/LICENSE ADDED
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "{}"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright (c) 2015-2019 Progress Software Corporation
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
package/README.md ADDED
@@ -0,0 +1,136 @@
1
+ <!-- ⚠️ This file is generated by tools/scripts/generate-readme.js — do not edit directly. -->
2
+ # @modos189/nativescript-webview-x
3
+
4
+ A NativeScript WebView plugin wrapping the Android system WebView and iOS WKWebView.
5
+ Built on top of [`@nativescript-community/ui-webview`](https://github.com/nativescript-community/ui-webview) — `WebViewX` extends `AWebView` directly, so the full upstream API is available.
6
+
7
+ Both `@modos189/nativescript-webview-x` and `@modos189/nativescript-webview-x-gecko` export an identically named `WebViewX` class.
8
+ Swap the engine by changing only the import path.
9
+
10
+ ## Installation
11
+
12
+ ```bash
13
+ npm install @modos189/nativescript-webview-x
14
+ ```
15
+
16
+ ## Usage
17
+
18
+ ### XML
19
+
20
+ ```xml
21
+ <Page xmlns="http://schemas.nativescript.org/tns.xsd"
22
+ xmlns:wv="@modos189/nativescript-webview-x">
23
+ <GridLayout rows="auto, *">
24
+ <TextField row="0" hint="Enter URL" text="{{ url }}" returnPress="{{ onNavigate }}" />
25
+ <wv:WebViewX row="1" src="{{ src }}" />
26
+ </GridLayout>
27
+ </Page>
28
+ ```
29
+
30
+ ### TypeScript
31
+
32
+ ```typescript
33
+ import { WebViewX } from '@modos189/nativescript-webview-x';
34
+
35
+ const webview = new WebViewX();
36
+ webview.loadUrl('https://example.com');
37
+ webview.on('loadFinished', () => {
38
+ webview.executeJavaScript('document.title');
39
+ });
40
+ ```
41
+
42
+ ## Implemented
43
+
44
+ _Available in both `@modos189/nativescript-webview-x` and `@modos189/nativescript-webview-x-gecko`._
45
+
46
+ ### Static properties
47
+
48
+ | Static property | Type | Description |
49
+ | --- | --- | --- |
50
+ | `userAgentTransform` | `((defaultUA: string \| null) => string \| null) \| null` | Set once at app startup before any `WebViewX` is created. Applied automatically during native view initialization, before the first URL loads. `defaultUA` is the platform default UA string on Android system WebView, `null` on iOS/GeckoView (unavailable synchronously). Return the desired UA string, or `null` to leave the platform default unchanged. |
51
+
52
+ ### Properties
53
+
54
+ | Property | Type | Description |
55
+ | --- | --- | --- |
56
+ | `src` | `string` | URL to load (data-binding supported) |
57
+ | `debugMode` | `boolean` | Enable remote WebView debugging |
58
+ | `supportPopups` | `boolean` | Open `window.open()` / `target="_blank"` links in a native popup. Default: `true` |
59
+
60
+ ### Methods
61
+
62
+ | Method | Returns | Description |
63
+ | --- | --- | --- |
64
+ | `getUserAgentOverride()` | `string \| null` | Return the active UA override, or `null` if none is set (platform default is used) |
65
+ | `setUserAgentOverride(ua: string \| null)` | `void` | Set a custom UA string for this instance; pass `null` or empty string to clear the override and restore the platform default. Applies to subsequent navigations |
66
+ | `getDefaultUserAgent()` | `string` | **Android only.** Return the system default UA string for this device, unaffected by any override. Useful as the input to `userAgentTransform` |
67
+
68
+ ### Events
69
+
70
+ | Event | Description |
71
+ | --- | --- |
72
+ | `popupNavigate` | Android: fired on each navigation inside a popup; set `args.cancel = true` to intercept and dismiss the popup (e.g. capture OAuth redirect). `args.url` contains the target URL. |
73
+
74
+
75
+ ## API Reference
76
+
77
+ Full API inherited from `@nativescript-community/ui-webview`. All items are available — `WebViewX` extends `AWebView` directly.
78
+
79
+ ### Properties
80
+
81
+ | Property | Type | Description |
82
+ | --- | --- | --- |
83
+ | `src` | `string` | URL to load |
84
+ | `autoInjectJSBridge` | `boolean` | Inject `window.nsWebViewBridge` on load finished. Default: `true` |
85
+ | `domStorage` | `boolean` | Android: enable DOM Storage API (e.g. `localStorage`) |
86
+ | `databaseStorage` | `boolean` | Android: enable database storage API |
87
+ | `builtInZoomControls` | `boolean` | Android: use built-in zoom mechanisms |
88
+ | `displayZoomControls` | `boolean` | Android: show on-screen zoom controls |
89
+ | `supportZoom` | `boolean` | Android: enable zoom support |
90
+ | `cacheMode` | `string` | Android: `default`, `no_cache`, `cache_first`, or `cache_only` |
91
+ | `debugMode` | `boolean` | Enable Chrome (Android) / Safari (iOS) remote debugger |
92
+ | `scrollBounce` | `boolean` | iOS: scrollView bounce. Default: `true` |
93
+ | `viewPortSize` | `boolean \| string \| ViewPortProperties` | Set viewport metadata after load |
94
+ | `limitsNavigationsToAppBoundDomains` | `boolean` | iOS: enable Service Workers |
95
+ | `supportPopups` | `boolean` | iOS: support `window.open` / `target="_blank"`. Default: `true` |
96
+ | `scrollBarIndicatorVisible` | `boolean` | Show/hide scrollbars |
97
+
98
+ ### Methods
99
+
100
+ | Method | Returns | Description |
101
+ | --- | --- | --- |
102
+ | `loadUrl(src: string)` | `Promise<LoadFinishedEventData>` | Load a URL, resolves when finished |
103
+ | `executeJavaScript(code: string)` | `Promise<any>` | Execute JavaScript and return the result |
104
+ | `executePromise(code: string, timeout?: number)` | `Promise<any>` | Run a promise inside the webview |
105
+ | `getTitle()` | `Promise<string>` | Return `document.title` |
106
+ | `emitToWebView(eventName: string, data: any)` | `void` | Emit an event into the webview |
107
+ | `autoLoadJavaScriptFile(name: string, path: string)` | `void` | Auto-inject a JS file on every `loadFinished` |
108
+ | `autoLoadStyleSheetFile(name: string, path: string, insertBefore?: boolean)` | `void` | Auto-inject a CSS file on every `loadFinished` |
109
+ | `autoExecuteJavaScript(code: string, name: string)` | `void` | Auto-execute a script on every `loadFinished` |
110
+
111
+ ### Events
112
+
113
+ | Event | Description |
114
+ | --- | --- |
115
+ | `loadStarted` | Navigation started |
116
+ | `loadFinished` | Navigation finished. `args.error` is set on failure |
117
+ | `loadProgress` | Android: page load progress (`args.progress: number`) |
118
+ | `shouldOverrideUrlLoading` | Raised before each navigation; set `args.cancel = true` to block |
119
+ | `titleChanged` | `document.title` changed |
120
+ | `webAlert` | `window.alert()` triggered; call `args.callback()` to dismiss |
121
+ | `webConfirm` | `window.confirm()` triggered; call `args.callback(boolean)` to dismiss |
122
+ | `webPrompt` | `window.prompt()` triggered; call `args.callback(string \| null)` to dismiss |
123
+ | `webConsole` | Android: a line was added to the web console |
124
+
125
+ ### nsWebViewBridge (inside the WebView)
126
+
127
+ When `autoInjectJSBridge` is `true`, the bridge is available after `DOMContentLoaded`:
128
+
129
+ ```javascript
130
+ window.nsWebViewBridge.emit('myEvent', { key: 'value' }); // → NativeScript
131
+ window.nsWebViewBridge.on('nativeEvent', (data) => { }); // ← NativeScript
132
+ ```
133
+
134
+ ## License
135
+
136
+ Apache License Version 2.0
package/common.d.ts ADDED
@@ -0,0 +1 @@
1
+ export { WebViewExtBase as WebviewXCommon } from '@nativescript-community/ui-webview';
package/common.js ADDED
@@ -0,0 +1,2 @@
1
+ export { WebViewExtBase as WebviewXCommon } from '@nativescript-community/ui-webview';
2
+ //# sourceMappingURL=common.js.map
package/common.js.map ADDED
@@ -0,0 +1 @@
1
+ {"version":3,"file":"common.js","sourceRoot":"","sources":["../../../packages/webview-x/common.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,IAAI,cAAc,EAAE,MAAM,oCAAoC,CAAC"}
@@ -0,0 +1,14 @@
1
+ export * from '@nativescript-community/ui-webview/index.android';
2
+ import { AWebView } from '@nativescript-community/ui-webview/index.android';
3
+ export declare class WebViewX extends AWebView {
4
+ static userAgentTransform: ((defaultUA: string | null) => string | null) | null;
5
+ static get popupNavigateEvent(): string;
6
+ private _popupClient;
7
+ private _userAgentOverride;
8
+ _onPopupNavigate(url: string): boolean;
9
+ initNativeView(): void;
10
+ disposeNativeView(): void;
11
+ getUserAgentOverride(): string | null;
12
+ setUserAgentOverride(ua: string | null): void;
13
+ getDefaultUserAgent(): string;
14
+ }
@@ -0,0 +1,76 @@
1
+ export * from '@nativescript-community/ui-webview/index.android';
2
+ import { AWebView, supportPopupsProperty } from '@nativescript-community/ui-webview/index.android';
3
+ const POPUP_NAVIGATE_EVENT = 'popupNavigate';
4
+ export class WebViewX extends AWebView {
5
+ constructor() {
6
+ super(...arguments);
7
+ this._popupClient = null;
8
+ this._userAgentOverride = null;
9
+ }
10
+ static get popupNavigateEvent() {
11
+ return POPUP_NAVIGATE_EVENT;
12
+ }
13
+ _onPopupNavigate(url) {
14
+ const args = {
15
+ eventName: POPUP_NAVIGATE_EVENT,
16
+ url,
17
+ cancel: false,
18
+ };
19
+ this.notify(args);
20
+ return args.cancel === true;
21
+ }
22
+ initNativeView() {
23
+ super.initNativeView();
24
+ const nv = this.nativeViewProtected;
25
+ if (!nv)
26
+ return;
27
+ const wv = nv;
28
+ if (WebViewX.userAgentTransform) {
29
+ const defaultUA = android.webkit.WebSettings.getDefaultUserAgent(this._context);
30
+ const newUA = WebViewX.userAgentTransform(defaultUA);
31
+ if (newUA !== null) {
32
+ wv.getSettings().setUserAgentString(newUA);
33
+ this._userAgentOverride = newUA;
34
+ }
35
+ }
36
+ const existing = wv.getWebChromeClient();
37
+ this._popupClient = new com.modos189.webviewx.PopupWebChromeClient(existing, true, this._context);
38
+ const interceptor = new com.modos189.webviewx.PopupWebChromeClient.PopupUrlInterceptor({
39
+ shouldHandleExternally: (url) => {
40
+ return this._onPopupNavigate(url != null ? '' + url : '');
41
+ },
42
+ });
43
+ this._popupClient.setUrlInterceptor(interceptor);
44
+ wv.setWebChromeClient(this._popupClient);
45
+ const settings = wv.getSettings();
46
+ settings.setJavaScriptCanOpenWindowsAutomatically(true);
47
+ settings.setSupportMultipleWindows(true);
48
+ }
49
+ disposeNativeView() {
50
+ this._popupClient = null;
51
+ super.disposeNativeView();
52
+ }
53
+ getUserAgentOverride() {
54
+ return this._userAgentOverride;
55
+ }
56
+ setUserAgentOverride(ua) {
57
+ this._userAgentOverride = ua || null;
58
+ const wv = this.nativeViewProtected;
59
+ if (wv)
60
+ wv.getSettings().setUserAgentString(this._userAgentOverride);
61
+ }
62
+ getDefaultUserAgent() {
63
+ return android.webkit.WebSettings.getDefaultUserAgent(this._context);
64
+ }
65
+ [supportPopupsProperty.setNative](value) {
66
+ const nv = this.nativeViewProtected;
67
+ if (!nv)
68
+ return;
69
+ const settings = nv.getSettings();
70
+ settings.setJavaScriptCanOpenWindowsAutomatically(value);
71
+ settings.setSupportMultipleWindows(value);
72
+ this._popupClient?.setSupportPopups(value);
73
+ }
74
+ }
75
+ WebViewX.userAgentTransform = null;
76
+ //# sourceMappingURL=index.android.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.android.js","sourceRoot":"","sources":["../../../packages/webview-x/index.android.ts"],"names":[],"mappings":"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"}
package/index.d.ts ADDED
@@ -0,0 +1,16 @@
1
+ export * from '@nativescript-community/ui-webview';
2
+ import { AWebView } from '@nativescript-community/ui-webview';
3
+
4
+ export declare class WebViewX extends AWebView {
5
+ /**
6
+ * Set once before any instance is created; applied automatically during native view init before the first URL loads.
7
+ * Receives the platform default UA (string on Android WebView, null on iOS/GeckoView where it is unavailable synchronously).
8
+ * Return the desired UA string, or null to leave the platform default unchanged.
9
+ */
10
+ static userAgentTransform: ((defaultUA: string | null) => string | null) | null;
11
+ static readonly popupNavigateEvent: string;
12
+ getUserAgentOverride(): string | null;
13
+ setUserAgentOverride(ua: string | null): void;
14
+ /** Android system WebView only: returns the device default UA string (unaffected by any override). */
15
+ getDefaultUserAgent(): string;
16
+ }
package/index.ios.d.ts ADDED
@@ -0,0 +1,8 @@
1
+ export * from '@nativescript-community/ui-webview/index.ios';
2
+ import { AWebView } from '@nativescript-community/ui-webview/index.ios';
3
+ export declare class WebViewX extends AWebView {
4
+ static userAgentTransform: ((defaultUA: string | null) => string | null) | null;
5
+ initNativeView(): void;
6
+ getUserAgentOverride(): string | null;
7
+ setUserAgentOverride(ua: string | null): void;
8
+ }
package/index.ios.js ADDED
@@ -0,0 +1,23 @@
1
+ export * from '@nativescript-community/ui-webview/index.ios';
2
+ import { AWebView } from '@nativescript-community/ui-webview/index.ios';
3
+ export class WebViewX extends AWebView {
4
+ initNativeView() {
5
+ super.initNativeView();
6
+ if (WebViewX.userAgentTransform) {
7
+ const newUA = WebViewX.userAgentTransform(null);
8
+ if (newUA !== null && this.nativeViewProtected) {
9
+ this.nativeViewProtected.customUserAgent = newUA;
10
+ }
11
+ }
12
+ }
13
+ getUserAgentOverride() {
14
+ return this.nativeViewProtected?.customUserAgent ?? null;
15
+ }
16
+ setUserAgentOverride(ua) {
17
+ if (this.nativeViewProtected) {
18
+ this.nativeViewProtected.customUserAgent = ua || null;
19
+ }
20
+ }
21
+ }
22
+ WebViewX.userAgentTransform = null;
23
+ //# sourceMappingURL=index.ios.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.ios.js","sourceRoot":"","sources":["../../../packages/webview-x/index.ios.ts"],"names":[],"mappings":"AAAA,cAAc,8CAA8C,CAAC;AAC7D,OAAO,EAAE,QAAQ,EAAE,MAAM,8CAA8C,CAAC;AAExE,MAAM,OAAO,QAAS,SAAQ,QAAQ;IAGpC,cAAc;QACZ,KAAK,CAAC,cAAc,EAAE,CAAC;QACvB,IAAI,QAAQ,CAAC,kBAAkB,EAAE,CAAC;YAChC,MAAM,KAAK,GAAG,QAAQ,CAAC,kBAAkB,CAAC,IAAI,CAAC,CAAC;YAChD,IAAI,KAAK,KAAK,IAAI,IAAI,IAAI,CAAC,mBAAmB,EAAE,CAAC;gBAC/C,IAAI,CAAC,mBAAmB,CAAC,eAAe,GAAG,KAAK,CAAC;YACnD,CAAC;QACH,CAAC;IACH,CAAC;IAED,oBAAoB;QAClB,OAAO,IAAI,CAAC,mBAAmB,EAAE,eAAe,IAAI,IAAI,CAAC;IAC3D,CAAC;IAED,oBAAoB,CAAC,EAAiB;QACpC,IAAI,IAAI,CAAC,mBAAmB,EAAE,CAAC;YAC7B,IAAI,CAAC,mBAAmB,CAAC,eAAe,GAAG,EAAE,IAAI,IAAI,CAAC;QACxD,CAAC;IACH,CAAC;;AApBM,2BAAkB,GAAyD,IAAI,CAAC"}
package/package.json ADDED
@@ -0,0 +1,42 @@
1
+ {
2
+ "name": "@modos189/nativescript-webview-x",
3
+ "version": "1.0.1",
4
+ "description": "Add a plugin description",
5
+ "main": "index",
6
+ "types": "index.d.ts",
7
+ "exports": {
8
+ ".": "./index",
9
+ "./vue": "./vue/index"
10
+ },
11
+ "nativescript": {
12
+ "platforms": {
13
+ "ios": "6.0.0",
14
+ "android": "6.0.0"
15
+ }
16
+ },
17
+ "repository": {
18
+ "type": "git",
19
+ "url": "https://github.com/modos189/nativescript-plugins.git"
20
+ },
21
+ "keywords": [
22
+ "NativeScript",
23
+ "JavaScript",
24
+ "TypeScript",
25
+ "iOS",
26
+ "Android"
27
+ ],
28
+ "author": {
29
+ "name": "modos189",
30
+ "email": "oss@nativescript.org"
31
+ },
32
+ "bugs": {
33
+ "url": "https://github.com/modos189/nativescript-plugins/issues"
34
+ },
35
+ "license": "Apache-2.0",
36
+ "homepage": "https://github.com/modos189/nativescript-plugins",
37
+ "readmeFilename": "README.md",
38
+ "bootstrapper": "@nativescript/plugin-seed",
39
+ "peerDependencies": {
40
+ "@nativescript-community/ui-webview": "^1.6.1"
41
+ }
42
+ }
@@ -0,0 +1,3 @@
1
+ dependencies {
2
+ implementation "com.google.android.material:material:1.11.0"
3
+ }
@@ -0,0 +1,540 @@
1
+ package com.modos189.webviewx;
2
+
3
+ import android.app.Activity;
4
+ import android.app.Dialog;
5
+ import android.content.Context;
6
+ import android.content.ContextWrapper;
7
+ import android.content.DialogInterface;
8
+ import android.content.Intent;
9
+ import android.graphics.Bitmap;
10
+ import android.graphics.Color;
11
+ import android.graphics.drawable.ColorDrawable;
12
+ import android.graphics.drawable.GradientDrawable;
13
+ import android.net.Uri;
14
+ import android.os.Message;
15
+ import android.util.TypedValue;
16
+ import android.view.Gravity;
17
+ import android.view.KeyEvent;
18
+ import android.view.MotionEvent;
19
+ import android.view.VelocityTracker;
20
+ import android.view.View;
21
+ import android.view.ViewConfiguration;
22
+ import android.view.ViewGroup;
23
+ import android.view.Window;
24
+ import android.webkit.ConsoleMessage;
25
+ import android.webkit.GeolocationPermissions;
26
+ import android.webkit.JsPromptResult;
27
+ import android.webkit.JsResult;
28
+ import android.webkit.PermissionRequest;
29
+ import android.webkit.ValueCallback;
30
+ import android.webkit.WebChromeClient;
31
+ import android.webkit.WebSettings;
32
+ import android.webkit.WebView;
33
+ import android.webkit.WebViewClient;
34
+ import android.widget.Button;
35
+ import android.widget.FrameLayout;
36
+ import android.widget.LinearLayout;
37
+ import android.widget.TextView;
38
+ import java.lang.ref.WeakReference;
39
+ import java.util.HashMap;
40
+ import java.util.Map;
41
+
42
+ /**
43
+ * Wraps a WebChromeClient delegate and adds popup window support via a bottom-sheet Dialog.
44
+ * Slide-up entrance, swipe-to-dismiss, dim overlay. Uses only standard Android APIs (API 19+).
45
+ */
46
+ public class PopupWebChromeClient extends WebChromeClient {
47
+
48
+ /** Callback so the host app can intercept popup navigations (e.g. OAuth redirects). */
49
+ public interface PopupUrlInterceptor {
50
+ /** Return true to intercept: the popup is dismissed and the URL is passed to the host. */
51
+ boolean shouldHandleExternally(String url);
52
+ }
53
+
54
+ private final WebChromeClient delegate;
55
+ private volatile boolean supportPopups;
56
+ private final WeakReference<Context> activityContextRef;
57
+ private final Map<WebView, Dialog> popupDialogs = new HashMap<>();
58
+ private PopupUrlInterceptor urlInterceptor;
59
+
60
+ public PopupWebChromeClient(WebChromeClient delegate, boolean supportPopups, Context activityContext) {
61
+ this.delegate = delegate;
62
+ this.supportPopups = supportPopups;
63
+ this.activityContextRef = new WeakReference<>(activityContext);
64
+ }
65
+
66
+ public void setSupportPopups(boolean value) {
67
+ this.supportPopups = value;
68
+ }
69
+
70
+ public void setUrlInterceptor(PopupUrlInterceptor interceptor) {
71
+ this.urlInterceptor = interceptor;
72
+ }
73
+
74
+ @Override
75
+ public boolean onCreateWindow(WebView view, boolean isDialog, boolean isUserGesture, Message resultMsg) {
76
+ if (!supportPopups) return false;
77
+
78
+ Context context = activityContextRef.get();
79
+ if (context == null) return false;
80
+
81
+ Activity activity = getActivity(context);
82
+ if (activity == null) return false;
83
+
84
+ final WebView popupWebView = new WebView(activity);
85
+ WebSettings settings = popupWebView.getSettings();
86
+ settings.setJavaScriptEnabled(true);
87
+ settings.setDomStorageEnabled(true);
88
+ settings.setSupportMultipleWindows(true);
89
+ settings.setUserAgentString(view.getSettings().getUserAgentString());
90
+
91
+ // Wire the new WebView into the system's popup transport before showing UI.
92
+ WebView.WebViewTransport transport = (WebView.WebViewTransport) resultMsg.obj;
93
+ transport.setWebView(popupWebView);
94
+ resultMsg.sendToTarget();
95
+
96
+ Dialog dialog = showPopupDialog(activity, popupWebView);
97
+ popupDialogs.put(popupWebView, dialog);
98
+
99
+ return true;
100
+ }
101
+
102
+ @Override
103
+ public void onCloseWindow(WebView window) {
104
+ Dialog d = popupDialogs.remove(window);
105
+ if (d != null) d.dismiss();
106
+ delegate.onCloseWindow(window);
107
+ }
108
+
109
+ /** Unwrap ContextWrapper chain to find the hosting Activity (required for Dialog). */
110
+ private static Activity getActivity(Context context) {
111
+ while (context instanceof ContextWrapper) {
112
+ if (context instanceof Activity) return (Activity) context;
113
+ context = ((ContextWrapper) context).getBaseContext();
114
+ }
115
+ return null;
116
+ }
117
+
118
+ private Dialog showPopupDialog(final Activity activity, final WebView popupWebView) {
119
+ final float dp = activity.getResources().getDisplayMetrics().density;
120
+ final int toolbarH = (int) (48 * dp);
121
+ final int padH = (int) (20 * dp);
122
+ android.graphics.Rect initFrame = new android.graphics.Rect();
123
+ activity.getWindow().getDecorView().getWindowVisibleDisplayFrame(initFrame);
124
+ final int[] sheetH = {initFrame.height() - toolbarH / 2};
125
+
126
+ // Dim overlay on the Activity decor view
127
+ final ViewGroup activityDecor = (ViewGroup) activity.getWindow().getDecorView();
128
+ final View dimView = new View(activity);
129
+ dimView.setBackgroundColor(Color.argb(102, 0, 0, 0)); // 40 % dim
130
+ dimView.setAlpha(0f);
131
+ activityDecor.addView(dimView, new ViewGroup.LayoutParams(
132
+ ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
133
+ dimView.animate().alpha(1f).setDuration(350).start();
134
+
135
+ final Dialog dialog = new Dialog(activity);
136
+ dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
137
+
138
+ // Sheet root with rounded top corners.
139
+ // onMeasure recalculates sheetH[0] on every layout pass so rotation
140
+ // automatically updates the sheet height while respecting the status bar safe area
141
+ final LinearLayout content = new LinearLayout(activity) {
142
+ @Override
143
+ protected void onMeasure(int widthSpec, int heightSpec) {
144
+ // Query the dialog's own window frame; the activity window frame would
145
+ // not reflect keyboard insets inside a separate dialog window.
146
+ android.graphics.Rect fr = new android.graphics.Rect();
147
+ getWindowVisibleDisplayFrame(fr);
148
+ if (fr.height() > 0) sheetH[0] = fr.height() - toolbarH / 2;
149
+ super.onMeasure(widthSpec,
150
+ MeasureSpec.makeMeasureSpec(sheetH[0], MeasureSpec.EXACTLY));
151
+ }
152
+ };
153
+ content.setOrientation(LinearLayout.VERTICAL);
154
+ GradientDrawable sheetBg = new GradientDrawable();
155
+ sheetBg.setColor(Color.parseColor("#222222"));
156
+ float cornerR = 16 * dp;
157
+ sheetBg.setCornerRadii(new float[]{cornerR, cornerR, cornerR, cornerR, 0, 0, 0, 0});
158
+ content.setBackground(sheetBg);
159
+
160
+ // Shared drag state
161
+ final int touchSlop = ViewConfiguration.get(activity).getScaledTouchSlop();
162
+ final float[] dragStartRawY = {0f};
163
+ final float[] interceptDownY = {0f};
164
+ final VelocityTracker[] vt = {null};
165
+
166
+ // Slide-down animation shared by toolbar, webViewWrapper, and back key
167
+ final Runnable[] doAnimatedDismiss = {null};
168
+ doAnimatedDismiss[0] = new Runnable() {
169
+ @Override public void run() {
170
+ float current = content.getTranslationY();
171
+ long duration = Math.max(80L, (long) (250 * (1f - current / sheetH[0])));
172
+ dimView.animate().alpha(0f).setDuration(duration).start();
173
+ content.animate()
174
+ .translationY(sheetH[0])
175
+ .setDuration(duration)
176
+ .withEndAction(new Runnable() {
177
+ @Override public void run() { dialog.dismiss(); }
178
+ })
179
+ .start();
180
+ }
181
+ };
182
+
183
+ // Toolbar: drag downward to dismiss.
184
+ // Two touch paths:
185
+ // (A) Touch on close button: button consumes ACTION_DOWN; onInterceptTouchEvent
186
+ // steals subsequent MOVE once drag is detected.
187
+ // (B) Touch on title area: TextView is not clickable, so no child takes
188
+ // ACTION_DOWN; onTouchEvent receives it, returns true to own the gesture,
189
+ // then detects and handles the drag itself.
190
+ final LinearLayout toolbar = new LinearLayout(activity) {
191
+ private float downY;
192
+ private boolean dragging;
193
+
194
+ // Path A: steal touch from a child (close button) once drag is detected.
195
+ @Override
196
+ public boolean onInterceptTouchEvent(MotionEvent ev) {
197
+ switch (ev.getAction()) {
198
+ case MotionEvent.ACTION_DOWN:
199
+ downY = ev.getRawY();
200
+ dragging = false;
201
+ break;
202
+ case MotionEvent.ACTION_MOVE:
203
+ if (!dragging && ev.getRawY() - downY > touchSlop) {
204
+ dragging = true;
205
+ dragStartRawY[0] = ev.getRawY();
206
+ if (vt[0] != null) vt[0].recycle();
207
+ vt[0] = VelocityTracker.obtain();
208
+ vt[0].addMovement(ev);
209
+ content.animate().cancel();
210
+ }
211
+ break;
212
+ case MotionEvent.ACTION_UP:
213
+ case MotionEvent.ACTION_CANCEL:
214
+ dragging = false;
215
+ break;
216
+ }
217
+ return dragging;
218
+ }
219
+
220
+ // Path B: direct touch on non-clickable area (title), or continuation
221
+ // after interception from a child.
222
+ @Override
223
+ public boolean onTouchEvent(MotionEvent ev) {
224
+ switch (ev.getAction()) {
225
+ case MotionEvent.ACTION_DOWN:
226
+ // Own the gesture so we receive future MOVE events.
227
+ downY = ev.getRawY();
228
+ dragging = false;
229
+ return true;
230
+ case MotionEvent.ACTION_MOVE:
231
+ if (!dragging) {
232
+ if (ev.getRawY() - downY > touchSlop) {
233
+ dragging = true;
234
+ dragStartRawY[0] = ev.getRawY();
235
+ if (vt[0] != null) vt[0].recycle();
236
+ vt[0] = VelocityTracker.obtain();
237
+ vt[0].addMovement(ev);
238
+ content.animate().cancel();
239
+ }
240
+ return true;
241
+ }
242
+ float delta = ev.getRawY() - dragStartRawY[0];
243
+ if (delta > 0) content.setTranslationY(delta);
244
+ if (vt[0] != null) vt[0].addMovement(ev);
245
+ return true;
246
+ case MotionEvent.ACTION_UP:
247
+ case MotionEvent.ACTION_CANCEL:
248
+ if (dragging) {
249
+ dragging = false;
250
+ float totalDelta = ev.getRawY() - dragStartRawY[0];
251
+ float yVelocity = 0;
252
+ if (vt[0] != null) {
253
+ vt[0].addMovement(ev);
254
+ vt[0].computeCurrentVelocity(1000);
255
+ yVelocity = vt[0].getYVelocity();
256
+ vt[0].recycle();
257
+ vt[0] = null;
258
+ }
259
+ if (totalDelta > sheetH[0] * 0.3f || yVelocity > 1000) {
260
+ doAnimatedDismiss[0].run();
261
+ } else {
262
+ content.animate().translationY(0).setDuration(200).start();
263
+ }
264
+ }
265
+ return true;
266
+ }
267
+ return false;
268
+ }
269
+ };
270
+ toolbar.setOrientation(LinearLayout.HORIZONTAL);
271
+ toolbar.setGravity(Gravity.CENTER_VERTICAL);
272
+ content.addView(toolbar, new LinearLayout.LayoutParams(
273
+ LinearLayout.LayoutParams.MATCH_PARENT, toolbarH));
274
+
275
+ final TextView titleView = new TextView(activity);
276
+ titleView.setText("loading...");
277
+ titleView.setTextColor(Color.WHITE);
278
+ titleView.setTextSize(TypedValue.COMPLEX_UNIT_SP, 15);
279
+ titleView.setIncludeFontPadding(false);
280
+ titleView.setPadding(padH, 0, 0, 0);
281
+ toolbar.addView(titleView, new LinearLayout.LayoutParams(
282
+ 0, LinearLayout.LayoutParams.WRAP_CONTENT, 1f));
283
+
284
+ final Button closeBtn = new Button(activity);
285
+ closeBtn.setText("✕");
286
+ closeBtn.setTextColor(Color.WHITE);
287
+ closeBtn.setBackgroundColor(Color.TRANSPARENT);
288
+ closeBtn.setMinWidth(0);
289
+ closeBtn.setMinimumWidth(0);
290
+ closeBtn.setGravity(Gravity.CENTER);
291
+ closeBtn.setPadding(padH / 2, 0, padH, 0);
292
+ toolbar.addView(closeBtn, new LinearLayout.LayoutParams(
293
+ LinearLayout.LayoutParams.WRAP_CONTENT,
294
+ LinearLayout.LayoutParams.MATCH_PARENT));
295
+
296
+ // WebView wrapper: intercepts swipe-to-dismiss over the WebView area.
297
+ // When the WebView is scrolled to the top and the user drags downward,
298
+ // steal the touch sequence and slide the sheet down.
299
+ FrameLayout webViewWrapper = new FrameLayout(activity) {
300
+ private boolean intercepting;
301
+
302
+ @Override
303
+ public boolean onInterceptTouchEvent(MotionEvent ev) {
304
+ switch (ev.getAction()) {
305
+ case MotionEvent.ACTION_DOWN:
306
+ interceptDownY[0] = ev.getRawY();
307
+ intercepting = false;
308
+ break;
309
+ case MotionEvent.ACTION_MOVE:
310
+ if (!intercepting) {
311
+ float dy = ev.getRawY() - interceptDownY[0];
312
+ // Intercept downward drags when WebView is at scroll top.
313
+ if (dy > touchSlop && popupWebView.getScrollY() == 0) {
314
+ intercepting = true;
315
+ dragStartRawY[0] = ev.getRawY();
316
+ if (vt[0] != null) vt[0].recycle();
317
+ vt[0] = VelocityTracker.obtain();
318
+ vt[0].addMovement(ev);
319
+ content.animate().cancel();
320
+ }
321
+ }
322
+ break;
323
+ case MotionEvent.ACTION_UP:
324
+ case MotionEvent.ACTION_CANCEL:
325
+ intercepting = false;
326
+ break;
327
+ }
328
+ return intercepting;
329
+ }
330
+
331
+ @Override
332
+ public boolean onTouchEvent(MotionEvent ev) {
333
+ if (!intercepting) return false;
334
+ switch (ev.getAction()) {
335
+ case MotionEvent.ACTION_MOVE:
336
+ float delta = ev.getRawY() - dragStartRawY[0];
337
+ if (delta > 0) content.setTranslationY(delta);
338
+ if (vt[0] != null) vt[0].addMovement(ev);
339
+ return true;
340
+ case MotionEvent.ACTION_UP:
341
+ case MotionEvent.ACTION_CANCEL:
342
+ intercepting = false;
343
+ float totalDelta = ev.getRawY() - dragStartRawY[0];
344
+ float yVelocity = 0;
345
+ if (vt[0] != null) {
346
+ vt[0].addMovement(ev);
347
+ vt[0].computeCurrentVelocity(1000);
348
+ yVelocity = vt[0].getYVelocity();
349
+ vt[0].recycle();
350
+ vt[0] = null;
351
+ }
352
+ if (totalDelta > sheetH[0] * 0.3f || yVelocity > 1000) {
353
+ doAnimatedDismiss[0].run();
354
+ } else {
355
+ content.animate().translationY(0).setDuration(200).start();
356
+ }
357
+ return true;
358
+ }
359
+ return true;
360
+ }
361
+ };
362
+ webViewWrapper.addView(popupWebView, new FrameLayout.LayoutParams(
363
+ FrameLayout.LayoutParams.MATCH_PARENT, FrameLayout.LayoutParams.MATCH_PARENT));
364
+ content.addView(webViewWrapper, new LinearLayout.LayoutParams(
365
+ LinearLayout.LayoutParams.MATCH_PARENT, 0, 1f));
366
+
367
+ // Popup WebView clients
368
+ popupWebView.setBackgroundColor(Color.WHITE);
369
+ popupWebView.setWebChromeClient(new WebChromeClient() {
370
+ @Override
371
+ public void onCloseWindow(WebView window) {
372
+ Dialog d = popupDialogs.remove(window);
373
+ if (d != null) d.dismiss();
374
+ }
375
+
376
+ @Override
377
+ public boolean onCreateWindow(WebView view, boolean isDialog, boolean isUserGesture, Message resultMsg) {
378
+ // target="_blank" links inside the popup: capture URL and open in system browser.
379
+ // A temporary WebView is needed to receive the transport URL from the system.
380
+ final WebView tempView = new WebView(activity);
381
+ tempView.setWebViewClient(new WebViewClient() {
382
+ @Override
383
+ public boolean shouldOverrideUrlLoading(WebView v, String url) {
384
+ Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
385
+ intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
386
+ activity.startActivity(intent);
387
+ tempView.destroy();
388
+ return true;
389
+ }
390
+ });
391
+ WebView.WebViewTransport transport = (WebView.WebViewTransport) resultMsg.obj;
392
+ transport.setWebView(tempView);
393
+ resultMsg.sendToTarget();
394
+ return true;
395
+ }
396
+ });
397
+ popupWebView.setWebViewClient(new WebViewClient() {
398
+ @Override
399
+ public boolean shouldOverrideUrlLoading(WebView view, String url) {
400
+ if (urlInterceptor != null && urlInterceptor.shouldHandleExternally(url)) {
401
+ doAnimatedDismiss[0].run();
402
+ return true;
403
+ }
404
+ return false;
405
+ }
406
+
407
+ @Override
408
+ public void onPageStarted(WebView view, String url, Bitmap favicon) {
409
+ String host = Uri.parse(url).getHost();
410
+ if (host != null && !host.isEmpty()) titleView.setText(host);
411
+ }
412
+ });
413
+
414
+ // Wrap sheet in a full-screen transparent root so the dialog window can be
415
+ // MATCH_PARENT × MATCH_PARENT; the sheet aligns itself to the bottom.
416
+ // This lets onMeasure in content drive the height after every rotation.
417
+ FrameLayout dialogRoot = new FrameLayout(activity);
418
+ FrameLayout.LayoutParams contentLp = new FrameLayout.LayoutParams(
419
+ FrameLayout.LayoutParams.MATCH_PARENT,
420
+ FrameLayout.LayoutParams.WRAP_CONTENT);
421
+ contentLp.gravity = Gravity.BOTTOM;
422
+ dialogRoot.addView(content, contentLp);
423
+ dialog.setContentView(dialogRoot);
424
+
425
+ Window window = dialog.getWindow();
426
+ if (window != null) {
427
+ window.setLayout(ViewGroup.LayoutParams.MATCH_PARENT,
428
+ ViewGroup.LayoutParams.MATCH_PARENT);
429
+ // No FLAG_DIM_BEHIND — we manage the dim ourselves via dimView.
430
+ window.setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
431
+ window.setDimAmount(0f);
432
+ // Resize the dialog window to the visible area above the keyboard
433
+ window.setSoftInputMode(android.view.WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);
434
+ }
435
+
436
+ closeBtn.setOnClickListener(new View.OnClickListener() {
437
+ @Override
438
+ public void onClick(View v) { doAnimatedDismiss[0].run(); }
439
+ });
440
+
441
+ // Animate slide-down on back key instead of instant dismiss
442
+ dialog.setOnKeyListener(new DialogInterface.OnKeyListener() {
443
+ @Override
444
+ public boolean onKey(DialogInterface d, int keyCode, KeyEvent event) {
445
+ if (keyCode == KeyEvent.KEYCODE_BACK
446
+ && event.getAction() == KeyEvent.ACTION_UP) {
447
+ doAnimatedDismiss[0].run();
448
+ return true;
449
+ }
450
+ return false;
451
+ }
452
+ });
453
+
454
+ dialog.setOnDismissListener(new DialogInterface.OnDismissListener() {
455
+ @Override
456
+ public void onDismiss(DialogInterface d) {
457
+ // Remove the dim overlay from the decor view.
458
+ activityDecor.removeView(dimView);
459
+ popupDialogs.remove(popupWebView);
460
+ popupWebView.destroy();
461
+ }
462
+ });
463
+
464
+ // Slide-up entrance animation
465
+ dialog.show();
466
+ content.setTranslationY(sheetH[0]);
467
+ content.animate().translationY(0).setDuration(350).start();
468
+
469
+ return dialog;
470
+ }
471
+
472
+ // Delegate all standard WebChromeClient callbacks
473
+
474
+ @Override
475
+ public void onProgressChanged(WebView view, int newProgress) {
476
+ delegate.onProgressChanged(view, newProgress);
477
+ }
478
+
479
+ @Override
480
+ public void onReceivedTitle(WebView view, String title) {
481
+ delegate.onReceivedTitle(view, title);
482
+ }
483
+
484
+ @Override
485
+ public void onReceivedIcon(WebView view, Bitmap icon) {
486
+ delegate.onReceivedIcon(view, icon);
487
+ }
488
+
489
+ @Override
490
+ public void onReceivedTouchIconUrl(WebView view, String url, boolean precomposed) {
491
+ delegate.onReceivedTouchIconUrl(view, url, precomposed);
492
+ }
493
+
494
+ @Override
495
+ public void onShowCustomView(View view, CustomViewCallback callback) {
496
+ delegate.onShowCustomView(view, callback);
497
+ }
498
+
499
+ @Override
500
+ public void onHideCustomView() {
501
+ delegate.onHideCustomView();
502
+ }
503
+
504
+ @Override
505
+ public boolean onJsAlert(WebView view, String url, String message, JsResult result) {
506
+ return delegate.onJsAlert(view, url, message, result);
507
+ }
508
+
509
+ @Override
510
+ public boolean onJsConfirm(WebView view, String url, String message, JsResult result) {
511
+ return delegate.onJsConfirm(view, url, message, result);
512
+ }
513
+
514
+ @Override
515
+ public boolean onJsPrompt(WebView view, String url, String message, String defaultValue, JsPromptResult result) {
516
+ return delegate.onJsPrompt(view, url, message, defaultValue, result);
517
+ }
518
+
519
+ @Override
520
+ public boolean onConsoleMessage(ConsoleMessage consoleMessage) {
521
+ return delegate.onConsoleMessage(consoleMessage);
522
+ }
523
+
524
+ @Override
525
+ public boolean onShowFileChooser(WebView webView, ValueCallback<Uri[]> filePathCallback,
526
+ FileChooserParams fileChooserParams) {
527
+ return delegate.onShowFileChooser(webView, filePathCallback, fileChooserParams);
528
+ }
529
+
530
+ @Override
531
+ public void onPermissionRequest(PermissionRequest request) {
532
+ delegate.onPermissionRequest(request);
533
+ }
534
+
535
+ @Override
536
+ public void onGeolocationPermissionsShowPrompt(String origin, GeolocationPermissions.Callback callback) {
537
+ delegate.onGeolocationPermissionsShowPrompt(origin, callback);
538
+ }
539
+
540
+ }
package/vue/index.d.ts ADDED
@@ -0,0 +1,4 @@
1
+ declare const Plugin: {
2
+ install(Vue: any): void;
3
+ };
4
+ export default Plugin;
package/vue/index.js ADDED
@@ -0,0 +1,7 @@
1
+ const Plugin = {
2
+ install(Vue) {
3
+ Vue.registerElement('WebViewX', () => require('../').WebViewX);
4
+ },
5
+ };
6
+ export default Plugin;
7
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../packages/webview-x/vue/index.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,GAAG;IACb,OAAO,CAAC,GAAG;QACT,GAAG,CAAC,eAAe,CAAC,UAAU,EAAE,GAAG,EAAE,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,QAAQ,CAAC,CAAC;IACjE,CAAC;CACF,CAAC;AAEF,eAAe,MAAM,CAAC"}