nicholas
nicholas

Reputation: 14593

Disable swipe navigation on Android Webview through CapacitorJS?

I've build an Android app using CapacitorJS and I want to disable the native webview's swipe navigation (swipe from edges to go forward/back). Is that possible?

Can this be done through Javascript or an HTML meta tag? As far as I can tell this is not possible.

Is there a Capacitor plugin or setting to do this? (Ionic, which uses Capacitor, has the swipeBackEnabled setting that sounds like it does what I'm looking for)

If not, can it be set on the Android WebView directly?

Upvotes: 2

Views: 399

Answers (1)

Yousha Aleayoub
Yousha Aleayoub

Reputation: 5638

For edge-swipe navigation

Disabling swipe navigation in Android's WebView when using CapacitorJS cannot be achieved directly through JavaScript or HTML metatag, because this behavior is tied to the native WebView's default settings.

But you can achieve SOMETHING LIKE THAT by customizing native Android codes:

  1. Go to Android folder in your CapacitorJS project.
  2. Open MainActivity file.
  3. Modify your OnCreate() method:
protected void onCreate(Bundle savedInstanceState)
{
    super.onCreate(savedInstanceState);
    WebView webView = this.bridge.getWebView();
    webView.setOverScrollMode(WebView.OVER_SCROLL_NEVER); // This disables edge-swipe navigation.
}

Upvotes: 0

Related Questions