From 136093b2294beac65ac2a99c7034b304197f2b5c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=99=88=E6=B3=B3=E6=BE=84?= Date: Tue, 31 Dec 2024 16:30:46 +0800 Subject: [PATCH] feat: add text zoom option with openWebView --- .../forgr/capacitor_inappbrowser/InAppBrowserPlugin.java | 2 ++ .../java/ee/forgr/capacitor_inappbrowser/Options.java | 9 +++++++++ .../ee/forgr/capacitor_inappbrowser/WebViewDialog.java | 5 ++++- src/definitions.ts | 4 ++++ 4 files changed, 19 insertions(+), 1 deletion(-) diff --git a/android/src/main/java/ee/forgr/capacitor_inappbrowser/InAppBrowserPlugin.java b/android/src/main/java/ee/forgr/capacitor_inappbrowser/InAppBrowserPlugin.java index 9aa5ac9..e760f85 100644 --- a/android/src/main/java/ee/forgr/capacitor_inappbrowser/InAppBrowserPlugin.java +++ b/android/src/main/java/ee/forgr/capacitor_inappbrowser/InAppBrowserPlugin.java @@ -428,6 +428,8 @@ public void openWebView(PluginCall call) { Boolean.TRUE.equals(call.getBoolean("ignoreUntrustedSSLError", false)) ); + options.setTextZoom(call.getDouble("textZoom")); + String proxyRequestsStr = call.getString("proxyRequests"); if (proxyRequestsStr != null) { try { diff --git a/android/src/main/java/ee/forgr/capacitor_inappbrowser/Options.java b/android/src/main/java/ee/forgr/capacitor_inappbrowser/Options.java index 179d3a5..81f74d8 100644 --- a/android/src/main/java/ee/forgr/capacitor_inappbrowser/Options.java +++ b/android/src/main/java/ee/forgr/capacitor_inappbrowser/Options.java @@ -131,6 +131,7 @@ public int getWidth() { private boolean ignoreUntrustedSSLError; private String preShowScript; private Pattern proxyRequestsPattern = null; + private Double textZoom; public Pattern getProxyRequestsPattern() { return proxyRequestsPattern; @@ -156,6 +157,14 @@ public void setTitle(String title) { this.title = title; } + public Double getTextZoom() { + return textZoom; + } + + public void setTextZoom(Double textZoom) { + this.textZoom = textZoom; + } + public boolean getCloseModal() { return CloseModal; } diff --git a/android/src/main/java/ee/forgr/capacitor_inappbrowser/WebViewDialog.java b/android/src/main/java/ee/forgr/capacitor_inappbrowser/WebViewDialog.java index 3b565bb..790ba62 100644 --- a/android/src/main/java/ee/forgr/capacitor_inappbrowser/WebViewDialog.java +++ b/android/src/main/java/ee/forgr/capacitor_inappbrowser/WebViewDialog.java @@ -191,7 +191,10 @@ public void presentWebView() { _webView.getSettings().setAllowFileAccessFromFileURLs(true); _webView.getSettings().setAllowUniversalAccessFromFileURLs(true); _webView.getSettings().setMediaPlaybackRequiresUserGesture(false); - + //text zoom + int rounded = (int) Math.round(_options.getTextZoom() * 100); + _webView.getSettings().setTextZoom(rounded); + _webView.setWebViewClient(new WebViewClient()); _webView.setWebChromeClient( diff --git a/src/definitions.ts b/src/definitions.ts index cbdbe05..f8cf06f 100644 --- a/src/definitions.ts +++ b/src/definitions.ts @@ -257,6 +257,10 @@ export interface OpenWebViewOptions { height?: number; }; }; + /** + * text zoom in webview, 1.0 is 100%, 1.2 is 120% + */ + textZoom?: number } export interface InAppBrowserPlugin {