GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — GitHub - Telefonica/android-nested-scroll-webview: Android WebView implementation for nested scrolling layouts

BranchesTags
Open more actions menu

Latest commit

 

History

23 Commits
23 Commits

Folders and files

NameName
Last commit message
Last commit date
.github
.github
 
 
app
app
 
 
gradle
gradle
 
 
nestedscrollwebview
nestedscrollwebview
 
 
.gitignore
.gitignore
 
 
LICENSE
LICENSE
 
 
README.md
README.md
 
 
build.gradle
build.gradle
 
 
detekt.yml
detekt.yml
 
 
gradle.properties
gradle.properties
 
 
gradlew
gradlew
 
 
gradlew.bat
gradlew.bat
 
 
mavencentral.gradle
mavencentral.gradle
 
 
publish_maven_central.gradle
publish_maven_central.gradle
 
 
settings.gradle
settings.gradle
 
 

Repository files navigation

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 to handle correctly nested scrolling to expand/collapse the toolbar.

This is usually done like this:

<androidx.core.widget.NestedScrollView
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    app:layout_behavior="@string/appbar_scrolling_view_behavior">

    <WebView
        android:id="@+id/webView"
        android:layout_width="match_parent"
        android:layout_height="match_parent"/>

</androidx.core.widget.NestedScrollView>

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 version="1.0" encoding="utf-8"?>
<androidx.coordinatorlayout.widget.CoordinatorLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <com.google.android.material.appbar.AppBarLayout
        android:id="@+id/app_bar"
        android:layout_width="match_parent"
        android:layout_height="@dimen/app_bar_height"
        android:theme="@style/Theme.NestedScrollWebViewDemo.AppBarOverlay">

        <com.google.android.material.appbar.CollapsingToolbarLayout
            android:id="@+id/toolbar_layout"
            style="@style/Widget.MaterialComponents.Toolbar.Primary"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            app:contentScrim="?attr/colorPrimary"
            app:layout_scrollFlags="scroll|exitUntilCollapsed"
            app:toolbarId="@+id/toolbar">

            <androidx.appcompat.widget.Toolbar
                android:id="@+id/toolbar"
                android:layout_width="match_parent"
                android:layout_height="?attr/actionBarSize"
                app:layout_collapseMode="pin"
                app:popupTheme="@style/Theme.NestedScrollWebViewDemo.PopupOverlay" />

        </com.google.android.material.appbar.CollapsingToolbarLayout>
    </com.google.android.material.appbar.AppBarLayout>

    <com.telefonica.nestedscrollwebview.NestedScrollWebView
        android:id="@+id/webView"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:layout_behavior="@string/appbar_scrolling_view_behavior" />

</androidx.coordinatorlayout.widget.CoordinatorLayout>

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.

<com.telefonica.nestedscrollwebview.NestedScrollWebView
    android:id="@+id/webView"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    app:coordinatorBottomMatchingEnabled="true"
    app:layout_behavior="@string/appbar_scrolling_view_behavior" />

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.

<com.telefonica.nestedscrollwebview.NestedScrollWebView
    android:id="@+id/webView"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    app:blockNestedScrollingOnInternalContentScrolls="false"
    app:layout_behavior="@string/appbar_scrolling_view_behavior" />

How we do it?

Implementation extends WebView applying nested scrolling code logic from androidx.core NestedScrollView.

Videos

Nested.Scroll.WebView.mp4
Nested.Scroll.WebView.with.Fixed.Footer.mp4

Usage

To include the library add to your app's build.gradle:

implementation 'com.telefonica:nestedscrollwebview:{version}'

About

Android WebView implementation for nested scrolling layouts

Topics

area-home-mobilemanagedorg-cdosrv-novumtool-cdo-agenttool-tf-github-repos

Resources

Readme
Apache-2.0 license

Security policy

Security policy
Activity
Custom properties

Stars

37 stars

Watchers

20 watching

Forks

9 forks
Report repository

Releases

Packages

Contributors

Languages

You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.