https://github.com/telefonica/android-nested-scroll-webview
Android WebView implementation for nested scrolling layouts
https://github.com/telefonica/android-nested-scroll-webview
cdco managed org-cdo srv-novum
Last synced: about 1 month ago
JSON representation
Android WebView implementation for nested scrolling layouts
- Host: GitHub
- URL: https://github.com/telefonica/android-nested-scroll-webview
- Owner: Telefonica
- License: apache-2.0
- Created: 2022-08-01T12:18:38.000Z (almost 3 years ago)
- Default Branch: main
- Last Pushed: 2024-12-20T13:00:24.000Z (5 months ago)
- Last Synced: 2025-04-13T05:07:24.822Z (about 1 month ago)
- Topics: cdco, managed, org-cdo, srv-novum
- Language: Java
- Homepage:
- Size: 147 KB
- Stars: 29
- Watchers: 22
- Forks: 7
- Open Issues: 5
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
![]()
![]()
![]()
# Android Nested Scroll WebView
Android WebView implementation for nested scrolling layouts.
## Introduction
In case you have a native application that uses a collapsing toolbar layout, you may need to wrap your webview into a [NestedScrollingView](https://developer.android.com/reference/androidx/core/widget/NestedScrollView) to handle correctly nested scrolling to expand/collapse the toolbar.
This is usually done like this:
```xml
```
You may quickly realize that **webview viewport height takes all content size height**. So, for all effects, you are using a browser window with an infinite viewport height, which has important implications:
* If page content is long, this may suppose performance penalties as whole page must be rendered.
* In case of scrolling pages where new content is continuously loaded as user scrolls down the page, it will trigger all these loads automatically, this could end on serious performance problems. Think about a "infinite" news feed for example.
* Page content based on viewport height may be displayed wrongly. Think about on fixed footer elements for example, these will be always displayed at the end of the scrollable content.If you are thinking on using the `android:fillViewport="false"` property for your NestedScrollView, you won't be able to perform any scroll on your webview content...
NestedScrollWebview implementation avoids this "height issue", making webview to have correct viewport size, while working with a collapsable toolbar layout.
## How to use it?
Just include directly the `NestedScrollWebView` in your layout:
```xml
```
## Configuration
Utility methods for specific WebView content requirements.
### Adjust WebView bottom margin to match CoordinatorLayout visible space
When expanding toolbar inside a CoordinatorLayout, instead of resizing the space left by the toolbar, it pushes down the content below.
This may be an issue for example for pages where a fixed footer element is displayed. So, in order to correctly resize the webview viewport on these expands you can add this attribute to the NestedScrollWebView.
`app:coordinatorBottomMatchingEnabled={"true"|"false"}`
This is **disabled by default**, as webview resizing is expensive.
```xml
```
### Block vertical nested scrolling on WebView internal elements scrolls
If your WebView content includes scrollable elements such as horizontal carousels or map views, nested scrolling should not be performed when scrolling these.
`app:blockNestedScrollingOnInternalContentScrolls={"true"|"false"}`
This is **enabled by default**, but can be disabled with this flag in case it does not work properly in any specific situation.
```xml
```
## How we do it?
Implementation extends [WebView](https://developer.android.com/reference/android/webkit/WebView) applying nested scrolling code logic from androidx.core [NestedScrollView](https://developer.android.com/reference/androidx/core/widget/NestedScrollView).
## Videos
# Usage
To include the library add to your app's `build.gradle`:
```gradle
implementation 'com.telefonica:nestedscrollwebview:{version}'
```