Efficient WebView resizing

518 views Asked by At

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" />
0

There are 0 answers