Skip to content
This repository was archived by the owner on Jan 10, 2024. It is now read-only.

Commit a5e195c

Browse files
committed
Merge branch 'Genotek/master'
2 parents c93563f + 26ef50c commit a5e195c

File tree

4 files changed

+39
-8
lines changed

4 files changed

+39
-8
lines changed

README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ tns plugin add @nota/nativescript-webview-ext
3737

3838
### Update minSdkVersion to 19 or higher
3939

40-
Android SDK 19 is required, update `App_Resources/Android/app.gradle`:
40+
Android SDK 19 is required, update `App_Resources/Android/app.gradle`:
4141
```
4242
android {
4343
defaultConfig {
@@ -101,6 +101,7 @@ Custom-scheme support for `iOS <11` was removed because of [ITMS-90809](https://
101101
| scrollBounce | true / false | iOS: Should the scrollView bounce? Defaults to true. |
102102
| supportZoom | true / false | Android: should the webview support zoom |
103103
| viewPortSize | false / view-port string / ViewPortProperties | Set the viewport metadata on load finished. **Note:** WkWebView sets initial-scale=1.0 by default. |
104+
| limitsNavigationsToAppBoundDomains | false | iOS: allows to enable Service Workers **Note:** If set to true, WKAppBoundDomains also should be set in info.plist. |
104105

105106
| Function | Description |
106107
| --- | --- |
@@ -150,7 +151,7 @@ Inside the WebView we have the `nsWebViewBridge` for sending events between the
150151
```javascript
151152
window.addEventListener("ns-bridge-ready", function(e) {
152153
var nsWebViewBridge = e.detail || window.nsWebViewBridge;
153-
154+
154155
// do stuff here
155156
});
156157
```

src/webview-ext-common.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,11 @@ export const scrollBounceProperty = new Property<WebViewExtBase, boolean>({
7373
valueConverter: booleanConverter,
7474
});
7575

76+
export const limitsNavigationsToAppBoundDomainsProperty = new Property<WebViewExtBase, boolean>({
77+
name: "limitsNavigationsToAppBoundDomains",
78+
valueConverter: booleanConverter,
79+
});
80+
7681
export type ViewPortValue = boolean | ViewPortProperties;
7782
export const viewPortProperty = new Property<WebViewExtBase, ViewPortValue>({
7883
name: "viewPortSize",
@@ -1499,3 +1504,4 @@ srcProperty.register(WebViewExtBase);
14991504
supportZoomProperty.register(WebViewExtBase);
15001505
scrollBounceProperty.register(WebViewExtBase);
15011506
viewPortProperty.register(WebViewExtBase);
1507+
limitsNavigationsToAppBoundDomainsProperty.register(WebViewExtBase);

src/webview-ext.android.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ const extToBinaryEncoding = new Set<string>(["gif", "jpeg", "jpg", "otf", "png",
3939
//#region android_native_classes
4040
let cacheModeMap: Map<CacheMode, number>;
4141

42-
export interface AndroidWebViewClient extends android.webkit.WebViewClient { }
42+
export interface AndroidWebViewClient extends android.webkit.WebViewClient {}
4343

4444
export interface AndroidWebView extends android.webkit.WebView {
4545
client: AndroidWebViewClient | null;

src/webview-ext.ios.ts

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,18 @@
11
/// <reference path="./types/ios/NotaWebViewExt.d.ts" />
22

33
import "@nativescript/core";
4-
import { alert, confirm, profile, prompt, Trace, File, knownFolders } from "@nativescript/core";
4+
import { alert, confirm, File, knownFolders, profile, prompt, Trace } from "@nativescript/core";
55
import { isEnabledProperty } from "@nativescript/core/ui/core/view";
66
import { webViewBridge } from "./nativescript-webview-bridge-loader";
7-
import { autoInjectJSBridgeProperty, NavigationType, scrollBounceProperty, WebViewExtBase } from "./webview-ext-common";
7+
import {
8+
autoInjectJSBridgeProperty,
9+
limitsNavigationsToAppBoundDomainsProperty,
10+
NavigationType,
11+
scrollBounceProperty,
12+
ViewPortProperties,
13+
viewPortProperty,
14+
WebViewExtBase,
15+
} from "./webview-ext-common";
816

917
export * from "./webview-ext-common";
1018

@@ -30,6 +38,7 @@ export class WebViewExt extends WebViewExtBase {
3038
public readonly supportXLocalScheme = typeof CustomUrlSchemeHandler !== "undefined";
3139

3240
public viewPortSize = { initialScale: 1.0 };
41+
private limitsNavigationsToAppBoundDomains = false;
3342

3443
public createNativeView() {
3544
const configuration = WKWebViewConfiguration.new();
@@ -42,7 +51,7 @@ export class WebViewExt extends WebViewExtBase {
4251
configuration.userContentController = wkUController;
4352
configuration.preferences.setValueForKey(true, "allowFileAccessFromFileURLs");
4453
configuration.setValueForKey(true, "allowUniversalAccessFromFileURLs");
45-
54+
configuration.limitsNavigationsToAppBoundDomains = this.limitsNavigationsToAppBoundDomains;
4655
if (this.supportXLocalScheme) {
4756
this.wkCustomUrlSchemeHandler = new CustomUrlSchemeHandler();
4857
configuration.setURLSchemeHandlerForURLScheme(this.wkCustomUrlSchemeHandler, this.interceptScheme);
@@ -386,7 +395,6 @@ export class WebViewExt extends WebViewExtBase {
386395
if (!nativeView) {
387396
return false;
388397
}
389-
390398
return nativeView.scrollView.bounces;
391399
}
392400

@@ -399,6 +407,20 @@ export class WebViewExt extends WebViewExtBase {
399407
nativeView.scrollView.bounces = !!enabled;
400408
}
401409

410+
[viewPortProperty.setNative](value: ViewPortProperties) {
411+
if (this.src) {
412+
this.injectViewPortMeta();
413+
}
414+
}
415+
416+
[limitsNavigationsToAppBoundDomainsProperty.setNative](enabled: boolean) {
417+
this.limitsNavigationsToAppBoundDomains = enabled;
418+
}
419+
420+
[limitsNavigationsToAppBoundDomainsProperty.getDefault]() {
421+
return false;
422+
}
423+
402424
[isEnabledProperty.setNative](enabled: boolean) {
403425
const nativeView = this.nativeViewProtected;
404426
if (!nativeView) {
@@ -700,7 +722,9 @@ export class WKScriptMessageHandlerNotaImpl extends NSObject implements WKScript
700722
owner.onWebViewEvent(message.eventName, message.data);
701723
} catch (err) {
702724
owner.writeTrace(
703-
`userContentControllerDidReceiveScriptMessage(${userContentController}, ${webViewMessage}) - bad message: ${JSON.stringify(webViewMessage.body)}`,
725+
`userContentControllerDidReceiveScriptMessage(${userContentController}, ${webViewMessage}) - bad message: ${JSON.stringify(
726+
webViewMessage.body,
727+
)}`,
704728
Trace.messageType.error,
705729
);
706730
}

0 commit comments

Comments
 (0)