Skip to content

Commit

Permalink
feat(android): hide scrollbars in WebView (#14031)
Browse files Browse the repository at this point in the history
* feat(android): hide scrollbars in WebView

* docs

---------

Co-authored-by: Chris Barber <chris@cb1inc.com>
  • Loading branch information
m1ga and cb1kenobi committed May 13, 2024
1 parent a7b145d commit 6642ed1
Show file tree
Hide file tree
Showing 6 changed files with 62 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
28 changes: 28 additions & 0 deletions apidoc/Titanium/UI/Android/Android.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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: |
Expand Down
8 changes: 8 additions & 0 deletions apidoc/Titanium/UI/WebView.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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: <Titanium.UI.Android.WEBVIEW_SCROLLBARS_DEFAULT>

- name: allowsBackForwardNavigationGestures
summary: |
A Boolean value indicating whether horizontal swipe gestures will trigger back-forward list navigations.
Expand Down

0 comments on commit 6642ed1

Please sign in to comment.