How to Disable Swipe Refresh when Bootstrap Modal Appears in Android WebView?

978 Views Asked by At

I am building an Android WebView app and website which I load in WebView contain Bootstrap Modal ,it appears as Login/SignUp popup or Choose Image popup.

But problem is that when Modal appears Swipe refresh is working and i am not able to scroll up as swipe refresh automatically refresh the page, So i want to disable swipe refresh only when modal opens.

In Chrome App ,swipe refresh automatically disables when Modal opens or appears so i want setting just as chrome android app.

Thanks in Advance

enter image description here

activity_main.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/black"
    android:id="@+id/relative"
    tools:context=".MainActivity">
    <androidx.swiperefreshlayout.widget.SwipeRefreshLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:id="@+id/swipeRefreshLayout"
        android:overScrollMode="never">




                <LinearLayout
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:orientation="vertical"

                    tools:ignore="WebViewLayout">
    <ProgressBar
        android:layout_width="match_parent"
        android:layout_height="8dp"
        android:id="@+id/progressBar"
        style="?android:attr/progressBarStyleHorizontal"
        android:layout_marginTop="-2dp"
        android:progress="20"
        android:visibility="gone"
        android:indeterminate="true"
        android:indeterminateTintMode="src_atop"
        android:indeterminateTint="@color/white" />



                    <WebView
                        android:layout_width="match_parent"
                        android:layout_height="match_parent"
                        android:id="@+id/myWebView"
                        android:layout_centerHorizontal="true"
                        android:layout_alignParentTop="true"
                        android:layout_alignParentLeft="true"
                        android:layout_alignParentStart="true"
                        android:layout_alignParentRight="true"
                        android:layout_alignParentEnd="true"
                        android:focusable="true"
                        android:focusableInTouchMode="true"
                        android:nestedScrollingEnabled="true"
                        android:isScrollContainer="true"
                        tools:ignore="ObsoleteLayoutParam,RtlHardcoded" />



    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@color/black"
        android:id="@+id/relativeLayout">

        <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="No Internet Connetion, Please Connect To Internet And Try Again. "
            android:textSize="30dp"
            android:textColor="@color/white"
            android:layout_centerHorizontal="true"
            android:textAlignment="center"
            android:layout_marginTop="40dp"
            android:id="@+id/txtNoConeection"
            android:layout_marginRight="23dp"
            android:layout_marginLeft="25dp"
            android:gravity="center_horizontal" />

        <Button
            android:layout_width="140dp"
            android:layout_height="65dp"
            android:text="Retry"
            android:backgroundTint="@color/white"
            android:textColor="#620839"
            android:layout_below="@+id/txtNoConeection"
            android:layout_centerHorizontal="true"
            android:layout_marginTop="400dp"
            android:textSize="20dp"
            android:id="@+id/btnNoConnection"/>

    </RelativeLayout>
                </LinearLayout>






    </androidx.swiperefreshlayout.widget.SwipeRefreshLayout>
</RelativeLayout>

In onCreate

swipeRefreshLayout = findViewById(R.id.swipeRefreshLayout);
        swipeRefreshLayout.setColorSchemeColors(Color.rgb(0,72,85), Color.rgb(255,216,96) , Color.rgb(93,7,53) );
        swipeRefreshLayout.setOnRefreshListener(() -> {
            webView.reload();
            if (null != swipeRefreshLayout){
                swipeRefreshLayout.setRefreshing(false);
            }
        });

        //Solved WebView SwipeUp Problem
        swipeRefreshLayout.getViewTreeObserver().addOnScrollChangedListener(() -> swipeRefreshLayout.setEnabled(webView.getScrollY() == 0));
1

There are 1 best solutions below

0
On

It's pretty old but since it shows up on google searches, might help some people... I solved it with a weird method. Just added some js to my website. not using bootstrap but is there any reason it wouldn't work? when I'm opening the div:

 document.body.style.overflowY = "hidden";
 document.body.style.minHeight = "calc(100vh + 1px)";
 window.scrollBy(0, 1);

and when I'm closing it:

document.body.style.overflowY = "scroll";
document.body.style.minHeight = "0px";
window.scrollBy(0, -1);

if you have found a better solution i would like to hear about it as well... i really don't understand why it's not fixed yet. chrome handles it perfectly but webview is still like this...

first i tried using

document.body.style.overscrollBehavior = "none";

but it has no effect in webview...