capacitor icon indicating copy to clipboard operation
capacitor copied to clipboard

feat: Android 12 - Deactivate Stretch/Bounce effect scroll

Open NeluQi opened this issue 3 years ago • 21 comments

How can I disable page stretching on over scroll in android?

my project on vue3

image

https://9to5google.com/2021/05/26/google-chrome-android-12-stretchy-scrolling/#:~:text=Android%2012%20and%20higher%20have,flag%20in%20chrome%3A%2F%2Fflags.

NeluQi avatar Jan 20 '22 11:01 NeluQi

Same issue here. Setting "overscroll-behavior-y: none" in css does not help

lmfmaier avatar Jan 25 '22 20:01 lmfmaier

In the layout, setting :

android:overScrollMode="never"

doesn't work either...

l5chaill avatar Mar 02 '22 21:03 l5chaill

Hi have you found a fix yet?? I haven't yet so I took it upon myself to try and create an Xposed module to help out with this, first I'll try disabling this effect then I'll try to implement the iOS over scroll which I'm a huge fan of even tho I'd consider myself an Android enthusiast

I have no experience in making Xposed modules but I will try this out with the help of a friend

OffTheRip0 avatar May 27 '22 05:05 OffTheRip0

thatweedie, I didn't find a solution It is very necessary, I wish you good luck! Describe here how the results will be, please

NeluQi avatar May 27 '22 09:05 NeluQi

I have found WebView#setOverScrollMode(int mode) to be working fine:

class MainActivity : BridgeActivity() {
    // ...

    /**
     * Called during initialization of the application.
     */
    public override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)

        // Disable the rubber-band over-scroll effect.
        // The `WebView` stretching does not take `position: fixed` elements into account, which
        // causes the app UI to get stretched.
        // https://github.com/ionic-team/capacitor/issues/5384#issuecomment-1165811208
        bridge.webView.overScrollMode = OVER_SCROLL_NEVER
    }
}
Before After

https://user-images.githubusercontent.com/834636/175665314-c9b3d6dd-36a1-44d8-bccc-0581de47f677.mp4

https://user-images.githubusercontent.com/834636/175665288-2d91beb3-5316-4cf2-8057-08110a9f3bd5.mp4

buschtoens avatar Jun 24 '22 18:06 buschtoens

I have found WebView#setOverScrollMode(int mode) to be working fine:

class MainActivity : BridgeActivity() {
    // ...

    /**
     * Called during initialization of the application.
     */
    public override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)

        // Disable the rubber-band over-scroll effect.
        // The `WebView` stretching does not take `position: fixed` elements into account, which
        // causes the app UI to get stretched.
        // https://github.com/ionic-team/capacitor/issues/5384#issuecomment-1165811208
        bridge.webView.overScrollMode = OVER_SCROLL_NEVER
    }
}

Before After before.mp4 after.mp4

Thank you!

lmfmaier avatar Jun 25 '22 05:06 lmfmaier

Here's my working implementation in Java. Note that getBridge() returns null in the onCreate() method in Capacitor 3, but works in onStart()

import android.os.Bundle;
import android.webkit.WebView;

import com.getcapacitor.BridgeActivity;

public class MainActivity extends BridgeActivity {
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
  }

  @Override
  public void onStart() {
    super.onStart();
    // Disable the rubber-band over-scroll effect that causes the app UI to get stretched.
    WebView v = getBridge().getWebView();
    v.setOverScrollMode(v.OVER_SCROLL_NEVER);
  }
}

lmfmaier avatar Jun 25 '22 08:06 lmfmaier

Here's my working implementation in Java. Note that getBridge() returns null in the onCreate() method in Capacitor 3, but works in onStart()

import android.os.Bundle;
import android.webkit.WebView;

import com.getcapacitor.BridgeActivity;

public class MainActivity extends BridgeActivity {
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
  }

  @Override
  public void onStart() {
    super.onStart();
    // Disable the rubber-band over-scroll effect that causes the app UI to get stretched.
    WebView v = getBridge().getWebView();
    v.setOverScrollMode(v.OVER_SCROLL_NEVER);
  }
}

Any chance of making this an Xposed module. I would be happy to pay someone.

Jal3223 avatar Oct 14 '22 01:10 Jal3223

This method doesn't seem to work in Capacitor 4 anymore. Is there anyway to disable the bounce scroll in Android in Capacitor 4?

user080975 avatar Mar 04 '23 15:03 user080975

This method doesn't seem to work in Capacitor 4 anymore. Is there anyway to disable the bounce scroll in Android in Capacitor 4?

Still works like a charm in Capacitor 4 for me

lmfmaier avatar Mar 04 '23 15:03 lmfmaier

I'm quite new to Capacitor on Android and if it works for you, I think that must mean I edited the wrong file. Can you please tell me which file did you make the change on and I'll try again. Thank You!

user080975 avatar Mar 04 '23 15:03 user080975

I'm quite new to Capacitor on Android and if it works for you, I think that must mean I edited the wrong file. Can you please tell me which file did you make the change on and I'll try again. Thank You!

Navigate to your capacitor project folder, then it's

android/app/src/main/com/yourdomain/yourapp/MainActivity.java

Directory structure after main depends on your appId

lmfmaier avatar Mar 04 '23 15:03 lmfmaier

Thank you! Now it's working great! :)

user080975 avatar Mar 04 '23 16:03 user080975

This is my code at capacitor version 4 using java.

package com.example.app;

import android.os.Bundle;
import android.webkit.WebView;

import com.getcapacitor.BridgeActivity;

public class MainActivity extends BridgeActivity {
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    }

    @Override
    public void onStart() {
        super.onStart();
        WebView webview = getBridge().getWebView();
        webview.setOverScrollMode(WebView.OVER_SCROLL_NEVER);
    }
}

KHJcode avatar Apr 26 '23 00:04 KHJcode

Thanks for opening this issue!

Great solutions, I used @KHJcode snippet in a capacitor 4 app.

anton-gustafsson avatar Apr 26 '23 13:04 anton-gustafsson

This is my code at capacitor version 4 using java.

package com.example.app;

import android.os.Bundle;
import android.webkit.WebView;

import com.getcapacitor.BridgeActivity;

public class MainActivity extends BridgeActivity {
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    }

    @Override
    public void onStart() {
        super.onStart();
        WebView webview = getBridge().getWebView();
        webview.setOverScrollMode(WebView.OVER_SCROLL_NEVER);
    }
}

Works great on Capacitor v5 also. Thanks!

manprit-tiwari avatar Jul 02 '23 09:07 manprit-tiwari

This is my code at capacitor version 4 using java.

package com.example.app;

import android.os.Bundle;
import android.webkit.WebView;

import com.getcapacitor.BridgeActivity;

public class MainActivity extends BridgeActivity {
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    }

    @Override
    public void onStart() {
        super.onStart();
        WebView webview = getBridge().getWebView();
        webview.setOverScrollMode(WebView.OVER_SCROLL_NEVER);
    }
}

Works with Capacitor v6-beta also. Thanks! Really hope this can be a default feature for Capacitor as it makes the app looks more native.

BobH-Official avatar Jan 20 '24 18:01 BobH-Official

I'm sure a PR adding this option to the android section of the capacitor.config.json would be appreciated.

buschtoens avatar Jan 21 '24 13:01 buschtoens

I'm sure a PR adding this option to the android section of the capacitor.config.json would be appreciated.

That would be amazing. Any one up to the task?

Also still working in Capacitor v 6.0

JoshuaHintze avatar Apr 21 '24 03:04 JoshuaHintze