2

I've implemented floating Toolbar in my app (hides with scroll down, shows on up) and now I see some flickering views inside WebView, to be precise these sticked to the bottom. I've noticed that this happens when I'm resizing WebView due to Toolbar offset change like this:

appBarLayout.addOnOffsetChangedListener(this);

@Override
public final void onOffsetChanged(AppBarLayout appBarLayout, int verticalOffset) {
    boolean scrollFlagsSet = ((AppBarLayout.LayoutParams) getToolbar().getLayoutParams()).
            getScrollFlags() != 0;
    int bottom = (!scrollFlagsSet ? 0 : getToolbarHeightAttr()) + verticalOffset;
    swipeRefreshLayout.setPadding(0, 0, 0, bottom);
    swipeRefreshLayout.requestLayout();
}

swipeRefreshLayout is WebViews parent. Method causes proper resizing WebView and it's pretty efficient, no lags (EDIT: a bit laggy on older devices). But when WebView loads site with some views sticked to the bottom then these views are flickering when resizing occurs. I can even see text in gap between bottom WebViews edge (gap present when scrolling down, view are cutted on the bottom when scrolling up). I've catched this behavior on screens (blue - Toolbar, gray - WebView, light blue & orange - in-webview views sticked to bottom). It looks like this only for a couple of millis (one frame?) and get back to the bottom fixed position. How to fix this?

scrolling gap

Same page loaded in Chrome or Firefox behaves correctly, these views are sticked to bottom and have fixed position, doesn't flicker with scroll/toolbar offset change

I'm using this NestedWebView. My app uses a lot of fragments loaded into Activities, which all are extending abstract BaseActivity in which I have CoordinatorLayout. WebViews belong to fragments and are placed in different containers, there is no option to place WebView straight into CoordinatorLayout

edit: XMLs

activity:

<androidx.coordinatorlayout.widget.CoordinatorLayout 
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/activity_main_cooridnator_layout"
android:layout_width="match_parent"
android:layout_height="match_parent">

<androidx.drawerlayout.widget.DrawerLayout
    android:id="@+id/drawer_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    app:layout_behavior="@string/appbar_scrolling_view_behavior">

    <FrameLayout
        android:id="@+id/activity_main_content_container"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@color/white" />

fragment:

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/white">

<androidx.swiperefreshlayout.widget.SwipeRefreshLayout
    android:id="@+id/fragment_webview_swipe_refresh"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <my.package.widgets.web.NestedWebView
        android:id="@+id/fragment_webview_webview"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:scrollbarStyle="outsideOverlay" />
snachmsm
  • 17,866
  • 3
  • 32
  • 74
  • Could you please provide the XML layout files? – Magudesh Apr 03 '19 at 05:14
  • I'm pretty shure that XMLs are unrelated, but I've posted both for `Activity` and `Fragment`. In fact after own reserach I'm pretty shure that it can't be done without own Chromium implementation, sadly... – snachmsm Apr 04 '19 at 09:54
  • Preload WebView page In case you are loading the WebView later (after resizing Toolbar), consider preloading its contents. –  Mar 09 '21 at 05:20
  • well, page loading takes more time and is "more noticeable" that this "jump", thats not a solution at all... this is the case when `WebView` is already initialised and have loaded content/web page, then user starts scrolling – snachmsm Mar 09 '21 at 17:51
  • 1
    GeckoDisplay has method setVerticalClipping(int clippingHeight) we want similar functionality for WebView. https://mozilla.github.io/geckoview/javadoc/mozilla-central/org/mozilla/geckoview/GeckoDisplay.html#setVerticalClipping-int- – Chaitanya Karmarkar Mar 13 '21 at 07:21

0 Answers0