From 02f5955ba55e0625a096858edfa163f4c696da9f Mon Sep 17 00:00:00 2001 From: Michael Gangolf Date: Wed, 8 May 2024 23:10:14 +0200 Subject: [PATCH 1/2] feat(android): hide scrollbars in WebView --- .../java/ti/modules/titanium/ui/WebViewProxy.java | 3 ++- .../modules/titanium/ui/android/AndroidModule.java | 9 +++++++++ .../titanium/ui/widget/webview/TiUIWebView.java | 14 ++++++++++++++ .../src/java/org/appcelerator/titanium/TiC.java | 1 + 4 files changed, 26 insertions(+), 1 deletion(-) diff --git a/android/modules/ui/src/java/ti/modules/titanium/ui/WebViewProxy.java b/android/modules/ui/src/java/ti/modules/titanium/ui/WebViewProxy.java index c1f9e1a34d6..8be6063b52b 100644 --- a/android/modules/ui/src/java/ti/modules/titanium/ui/WebViewProxy.java +++ b/android/modules/ui/src/java/ti/modules/titanium/ui/WebViewProxy.java @@ -54,7 +54,8 @@ TiC.PROPERTY_OVER_SCROLL_MODE, TiC.PROPERTY_CACHE_MODE, TiC.PROPERTY_LIGHT_TOUCH_ENABLED, - TiC.PROPERTY_ON_LINK + TiC.PROPERTY_ON_LINK, + TiC.PROPERTY_SCROLLBARS }) public class WebViewProxy extends ViewProxy implements Handler.Callback, OnLifecycleEvent, interceptOnBackPressedEvent { diff --git a/android/modules/ui/src/java/ti/modules/titanium/ui/android/AndroidModule.java b/android/modules/ui/src/java/ti/modules/titanium/ui/android/AndroidModule.java index bc9e666347c..e5905f249d4 100644 --- a/android/modules/ui/src/java/ti/modules/titanium/ui/android/AndroidModule.java +++ b/android/modules/ui/src/java/ti/modules/titanium/ui/android/AndroidModule.java @@ -253,6 +253,15 @@ public class AndroidModule extends KrollModule @Kroll.constant public static final int SCROLL_FLAG_SNAP_MARGINS = 32; + @Kroll.constant + public static final int WEBVIEW_SCROLLBARS_DEFAULT = 0; + @Kroll.constant + public static final int WEBVIEW_SCROLLBARS_HIDE_VERTICAL = 1; + @Kroll.constant + public static final int WEBVIEW_SCROLLBARS_HIDE_HORIZONTAL = 2; + @Kroll.constant + public static final int WEBVIEW_SCROLLBARS_HIDE_ALL = 3; + public AndroidModule() { super(); diff --git a/android/modules/ui/src/java/ti/modules/titanium/ui/widget/webview/TiUIWebView.java b/android/modules/ui/src/java/ti/modules/titanium/ui/widget/webview/TiUIWebView.java index be414648747..e7099c1dee4 100644 --- a/android/modules/ui/src/java/ti/modules/titanium/ui/widget/webview/TiUIWebView.java +++ b/android/modules/ui/src/java/ti/modules/titanium/ui/widget/webview/TiUIWebView.java @@ -456,6 +456,14 @@ public void processProperties(KrollDict d) if (d.containsKey(TiC.PROPERTY_ZOOM_LEVEL)) { zoomBy(getWebView(), TiConvert.toFloat(d, TiC.PROPERTY_ZOOM_LEVEL)); } + + if (d.containsKey(TiC.PROPERTY_SCROLLBARS)) { + int scrollbarValue = TiConvert.toInt(d, TiC.PROPERTY_SCROLLBARS); + webView.setVerticalScrollBarEnabled(scrollbarValue == AndroidModule.WEBVIEW_SCROLLBARS_DEFAULT + || scrollbarValue == AndroidModule.WEBVIEW_SCROLLBARS_HIDE_HORIZONTAL); + webView.setHorizontalScrollBarEnabled(scrollbarValue == AndroidModule.WEBVIEW_SCROLLBARS_DEFAULT + || scrollbarValue == AndroidModule.WEBVIEW_SCROLLBARS_HIDE_VERTICAL); + } } @Override @@ -496,6 +504,12 @@ public void propertyChanged(String key, Object oldValue, Object newValue, KrollP zoomBy(webView, TiConvert.toFloat(newValue, 1.0f)); } else if (TiC.PROPERTY_USER_AGENT.equals(key)) { ((WebViewProxy) getProxy()).setUserAgent(TiConvert.toString(newValue)); + } else if (TiC.PROPERTY_SCROLLBARS.equals(key)) { + int scrollbarValue = TiConvert.toInt(newValue); + webView.setVerticalScrollBarEnabled(scrollbarValue == AndroidModule.WEBVIEW_SCROLLBARS_DEFAULT + || scrollbarValue == AndroidModule.WEBVIEW_SCROLLBARS_HIDE_HORIZONTAL); + webView.setHorizontalScrollBarEnabled(scrollbarValue == AndroidModule.WEBVIEW_SCROLLBARS_DEFAULT + || scrollbarValue == AndroidModule.WEBVIEW_SCROLLBARS_HIDE_VERTICAL); } else { super.propertyChanged(key, oldValue, newValue, proxy); } diff --git a/android/titanium/src/java/org/appcelerator/titanium/TiC.java b/android/titanium/src/java/org/appcelerator/titanium/TiC.java index 704af44e031..a09ba8969b5 100644 --- a/android/titanium/src/java/org/appcelerator/titanium/TiC.java +++ b/android/titanium/src/java/org/appcelerator/titanium/TiC.java @@ -689,6 +689,7 @@ public class TiC public static final String PROPERTY_SCROLL_ENABLED = "scrollEnabled"; public static final String PROPERTY_SCROLL_TYPE = "scrollType"; public static final String PROPERTY_SCROLLABLE = "scrollable"; + public static final String PROPERTY_SCROLLBARS = "scrollbars"; public static final String PROPERTY_SEARCH = "search"; public static final String PROPERTY_SEARCH_AS_CHILD = "searchAsChild"; public static final String PROPERTY_SEARCH_TEXT = "searchText"; From 4c7e8f8f9f036f9c3e4e507abd8a8116541ec104 Mon Sep 17 00:00:00 2001 From: Michael Gangolf Date: Wed, 8 May 2024 23:21:02 +0200 Subject: [PATCH 2/2] docs --- apidoc/Titanium/UI/Android/Android.yml | 28 ++++++++++++++++++++++++++ apidoc/Titanium/UI/WebView.yml | 8 ++++++++ 2 files changed, 36 insertions(+) diff --git a/apidoc/Titanium/UI/Android/Android.yml b/apidoc/Titanium/UI/Android/Android.yml index cb0788372eb..da74d51c6f0 100644 --- a/apidoc/Titanium/UI/Android/Android.yml +++ b/apidoc/Titanium/UI/Android/Android.yml @@ -957,6 +957,34 @@ properties: platforms: [android] since: "12.1.0" + - name: WEBVIEW_SCROLLBARS_DEFAULT + summary: Show horizontal and vertical scrollbar in a Ti.UI.WebView. + type: Number + permission: read-only + platforms: [android] + since: "12.3.0" + + - name: WEBVIEW_SCROLLBARS_HIDE_VERTICAL + summary: Hide vertical scrollbar in a Ti.UI.WebView. + type: Number + permission: read-only + platforms: [android] + since: "12.3.0" + + - name: WEBVIEW_SCROLLBARS_HIDE_HORIZONTAL + summary: Hide horizontal scrollbar in a Ti.UI.WebView. + type: Number + permission: read-only + platforms: [android] + since: "12.3.0" + + - name: WEBVIEW_SCROLLBARS_HIDE_ALL + summary: Hide all scrollbars in a Ti.UI.WebView. + type: Number + permission: read-only + platforms: [android] + since: "12.3.0" + examples: - title: Android Preferences Example example: | diff --git a/apidoc/Titanium/UI/WebView.yml b/apidoc/Titanium/UI/WebView.yml index 0c715e3f03e..3b447f95fb3 100644 --- a/apidoc/Titanium/UI/WebView.yml +++ b/apidoc/Titanium/UI/WebView.yml @@ -1130,6 +1130,14 @@ properties: platforms: [android, iphone, ipad, macos] since: {android: "7.3.0", iphone: "7.3.0", ipad: "7.3.0", macos: "9.2.0"} + - name: scrollbars + summary: Enable or disable horizontal/vertical scrollbars in a WebView. + type: Number + constants: Titanium.UI.Android.WEBVIEW_SCROLLBARS_* + platforms: [android] + since: "12.3.0" + default: + - name: allowsBackForwardNavigationGestures summary: | A Boolean value indicating whether horizontal swipe gestures will trigger back-forward list navigations.