Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WebView OverScroll

I'm trying to make a webView "bounce" when pulled after scroll reached the max (kind of like the "pull-to-refresh" effect).

I have my custom view extending WebView, and overriding the method

 @Override
protected boolean overScrollBy(final int deltaX, final int deltaY, final int scrollX, final int scrollY, final int scrollRangeX, final int scrollRangeY, final int maxOverScrollX, final int maxOverScrollY, final boolean isTouchEvent)
{
    VerticalOverScrollController.Result result = overscrollController.calcVerticalOverScroll(deltaY, scrollY);
    Log.d("overScrollBy", "scrollY " + result.scrollY + " overScrollY " + result.overScrollY);

    return super.overScrollBy(deltaX, deltaY, scrollX, result.getScrollY(), scrollRangeX, scrollRangeY, maxOverScrollX, result.getOverScrollY(), isTouchEvent);
}

and calcVerticalOverScroll is

 public Result calcVerticalOverScroll(final int deltaY, final int scrollY)
{
    Result result = new Result();

    if (scrollY <= 0 && deltaY < 0)//if at top and pulling down...
    {
        result.scrollY = (maxTopOverScroll > 0) ? scrollY : 0;
        result.overScrollY = maxTopOverScroll;
    } else
    {
        result.scrollY = (maxBottomOverScroll > 0) ? scrollY : 0;
        result.overScrollY = maxBottomOverScroll;
    }

    return result;
}

and Result is just

  public static class Result
{
    int scrollY;
    int overScrollY;

    ... getters()
}

The thing is, this works perfectly on any view (including webview) before KitKat.

After KitKat this works perfectly on any view except WebView, where the log for scrollY is always 0.

Any ideas on what could have changed on this version of the WebView?

If this does not fly, any ideas on how to achieve the overScroll effect on a WebView correctly?

Thanks in Advance.

like image 757
Cheborra Avatar asked Aug 26 '15 21:08

Cheborra


Video Answer


1 Answers

Android 4.4 KitKat (Android 19 )introduces a new version of WebView that is based on Chromium. Here in this chromium browser they have removed many features from webview.

Some of these bugs have already been reported to Google. Check the links : Restore scroll position feature doesn't work on KitKat

From the links, this is also one of the bug reported

On Android 4.4 KitKat, probably related to the Chromium WebView, the scroll position of the previous article is not restored when you go back.

This is not an exact answer for this question, but just pointing to the things. But there must be a workaround for doing this in new webview. Let me check it and update my answer!!

like image 181
King of Masses Avatar answered Oct 04 '22 05:10

King of Masses