Skip to content

Commit 88f9e38

Browse files
committed
feat(webview): useWideViewPort for android
1 parent 01aeb59 commit 88f9e38

File tree

3 files changed

+27
-95
lines changed

3 files changed

+27
-95
lines changed

src/webview/index.android.ts

Lines changed: 15 additions & 89 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import {
1616
isScrollEnabledProperty,
1717
mediaPlaybackRequiresUserActionProperty,
1818
supportZoomProperty,
19+
useWideViewPortProperty,
1920
webConsoleProperty
2021
} from './index.common';
2122
import { appCachePathProperty } from '.';
@@ -562,9 +563,6 @@ export class AWebView extends WebViewExtBase {
562563
settings.setJavaScriptEnabled(true);
563564
settings.setAllowFileAccess(true); // Needed for Android 11
564565

565-
// to support viewport tag
566-
settings.setUseWideViewPort(true);
567-
568566
if (sdkVersion() >= 21) {
569567
// Needed for x-local in https-sites
570568
settings.setMixedContentMode(android.webkit.WebSettings.MIXED_CONTENT_COMPATIBILITY_MODE);
@@ -858,52 +856,25 @@ export class AWebView extends WebViewExtBase {
858856
}
859857

860858
[builtInZoomControlsProperty.getDefault]() {
861-
const androidWebView = this.nativeViewProtected;
862-
if (!androidWebView) {
863-
return false;
864-
}
865-
866-
const settings = androidWebView.getSettings();
867-
868-
return settings.getBuiltInZoomControls();
859+
return this.nativeViewProtected.getSettings().getBuiltInZoomControls();
869860
}
870861

871862
[builtInZoomControlsProperty.setNative](enabled: boolean) {
872-
const androidWebView = this.nativeViewProtected;
873-
if (!androidWebView) {
874-
return;
875-
}
876-
const settings = androidWebView.getSettings();
877-
settings.setBuiltInZoomControls(!!enabled);
863+
this.nativeViewProtected.getSettings().setBuiltInZoomControls(!!enabled);
878864
}
879865
[appCachePathProperty.setNative](pth: string) {
880866
const androidWebView = this.nativeViewProtected;
881-
if (!androidWebView) {
882-
return;
883-
}
884867
const settings = androidWebView.getSettings();
885868
settings.setAppCachePath(pth);
886869
settings.setAppCacheEnabled(!!pth);
887870
}
888871

889872
[displayZoomControlsProperty.getDefault]() {
890-
const androidWebView = this.nativeViewProtected;
891-
if (!androidWebView) {
892-
return false;
893-
}
894-
895-
const settings = androidWebView.getSettings();
896-
897-
return settings.getDisplayZoomControls();
873+
return this.nativeViewProtected.getSettings().getDisplayZoomControls();
898874
}
899875

900876
[displayZoomControlsProperty.setNative](enabled: boolean) {
901-
const androidWebView = this.nativeViewProtected;
902-
if (!androidWebView) {
903-
return;
904-
}
905-
const settings = androidWebView.getSettings();
906-
settings.setDisplayZoomControls(!!enabled);
877+
this.nativeViewProtected.getSettings().setDisplayZoomControls(!!enabled);
907878
}
908879

909880
[cacheModeProperty.getDefault](): CacheMode | null {
@@ -926,76 +897,35 @@ export class AWebView extends WebViewExtBase {
926897
}
927898

928899
[cacheModeProperty.setNative](cacheMode: CacheMode) {
929-
const androidWebView = this.nativeViewProtected;
930-
if (!androidWebView) {
931-
return;
932-
}
900+
this.nativeViewProtected.getSettings().setCacheMode(cacheModeMap[cacheMode]);
901+
}
933902

934-
const settings = androidWebView.getSettings();
935-
settings.setCacheMode(cacheModeMap[cacheMode]);
903+
[useWideViewPortProperty.setNative](value: boolean) {
904+
this.nativeViewProtected.getSettings().setUseWideViewPort(value);
936905
}
937906

938907
[databaseStorageProperty.getDefault]() {
939-
const androidWebView = this.nativeViewProtected;
940-
if (!androidWebView) {
941-
return false;
942-
}
943-
944-
const settings = androidWebView.getSettings();
945-
946-
return settings.getDatabaseEnabled();
908+
return this.nativeViewProtected.getSettings().getDatabaseEnabled();
947909
}
948910

949911
[databaseStorageProperty.setNative](enabled: boolean) {
950-
const androidWebView = this.nativeViewProtected;
951-
if (!androidWebView) {
952-
return;
953-
}
954-
955-
const settings = androidWebView.getSettings();
956-
settings.setDatabaseEnabled(!!enabled);
912+
this.nativeViewProtected.getSettings().setDatabaseEnabled(!!enabled);
957913
}
958914

959915
[domStorageProperty.getDefault]() {
960-
const androidWebView = this.nativeViewProtected;
961-
if (!androidWebView) {
962-
return false;
963-
}
964-
965-
const settings = androidWebView.getSettings();
966-
967-
return settings.getDomStorageEnabled();
916+
return this.nativeViewProtected.getSettings().getDomStorageEnabled();
968917
}
969918

970919
[domStorageProperty.setNative](enabled: boolean) {
971-
const androidWebView = this.nativeViewProtected;
972-
if (!androidWebView) {
973-
return;
974-
}
975-
976-
const settings = androidWebView.getSettings();
977-
settings.setDomStorageEnabled(!!enabled);
920+
return this.nativeViewProtected.getSettings().setDomStorageEnabled(!!enabled);
978921
}
979922

980923
[supportZoomProperty.getDefault]() {
981-
const androidWebView = this.nativeViewProtected;
982-
if (!androidWebView) {
983-
return false;
984-
}
985-
986-
const settings = androidWebView.getSettings();
987-
988-
return settings.supportZoom();
924+
return this.nativeViewProtected.getSettings().supportZoom();
989925
}
990926

991927
[supportZoomProperty.setNative](enabled: boolean) {
992-
const androidWebView = this.nativeViewProtected;
993-
if (!androidWebView) {
994-
return;
995-
}
996-
997-
const settings = androidWebView.getSettings();
998-
settings.setSupportZoom(!!enabled);
928+
this.nativeViewProtected.getSettings().setSupportZoom(!!enabled);
999929
}
1000930

1001931
public [isScrollEnabledProperty.setNative](value: boolean) {
@@ -1004,10 +934,6 @@ export class AWebView extends WebViewExtBase {
1004934

1005935
[isEnabledProperty.setNative](enabled: boolean) {
1006936
const androidWebView = this.nativeViewProtected;
1007-
if (!androidWebView) {
1008-
return;
1009-
}
1010-
1011937
if (enabled) {
1012938
androidWebView.setOnTouchListener(null!);
1013939
} else {

src/webview/index.common.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -110,8 +110,14 @@ export const normalizeUrlsProperty = new Property<WebViewExtBase, boolean>({
110110
});
111111

112112
export const limitsNavigationsToAppBoundDomainsProperty = new Property<WebViewExtBase, boolean>({
113-
name: "limitsNavigationsToAppBoundDomains",
114-
valueConverter: booleanConverter,
113+
name: 'limitsNavigationsToAppBoundDomains',
114+
valueConverter: booleanConverter
115+
});
116+
117+
export const useWideViewPortProperty = new Property<WebViewExtBase, boolean>({
118+
name: 'useWideViewPort',
119+
defaultValue: true,
120+
valueConverter: booleanConverter
115121
});
116122

117123
export type ViewPortValue = boolean | ViewPortProperties;
@@ -1595,4 +1601,4 @@ isScrollEnabledProperty.register(WebViewExtBase);
15951601
scalesPageToFitProperty.register(WebViewExtBase);
15961602
mediaPlaybackRequiresUserActionProperty.register(WebViewExtBase);
15971603
appCachePathProperty.register(WebViewExtBase);
1598-
limitsNavigationsToAppBoundDomainsProperty.register(WebViewExtBase);
1604+
limitsNavigationsToAppBoundDomainsProperty.register(WebViewExtBase);

src/webview/index.ios.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@ import {
66
WebViewExtBase,
77
allowsInlineMediaPlaybackProperty,
88
autoInjectJSBridgeProperty,
9+
limitsNavigationsToAppBoundDomainsProperty,
910
mediaPlaybackRequiresUserActionProperty,
1011
scrollBounceProperty,
11-
viewPortProperty,
12-
limitsNavigationsToAppBoundDomainsProperty
12+
viewPortProperty
1313
} from './index.common';
1414
import { webViewBridge } from './nativescript-webview-bridge-loader';
1515

@@ -439,7 +439,7 @@ export class AWebView extends WebViewExtBase {
439439
nativeView.scrollView.bounces = !!enabled;
440440
}
441441

442-
[viewPortProperty.setNative](value: ViewPortProperties) {
442+
[viewPortProperty.setNative](value) {
443443
if (this.src) {
444444
this.injectViewPortMeta();
445445
}

0 commit comments

Comments
 (0)