MainPage.xaml
page with single WebView element<WebView Source="https://www.youtube.com/" ></WebView>
YouTube webpage should be scrolled.
Nothing happened after scrolling.
Reproducible by modifying a Shell template in VS2019 preview.
Hello,
The problem also occurs in my project with WebView and Maps (Xamarin.Forms.GoogleMaps).
I could solve it easily by a custom ContentView.
See below...
Shared-Project:
Create a custom ContentView:
public class GesturelessContentView : ContentView
{
}
In Xaml add the WebView to this ContentView:
<controls:GesturelessContentView x:Name="view" HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand">
<WebView x:Name="webView" Source="{Binding Source}" HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand"/>
</controls:GesturelessContentView>
Android-Project:
Create a custom ViewRenderer for this ContentView and override the "DispatchTouchEvent":
public override bool DispatchTouchEvent(MotionEvent e)
{
/* Switching between touch-events
switch (e.Action)
{
case MotionEventActions.Down:
case MotionEventActions.Move:
case MotionEventActions.Up:
this.Parent.RequestDisallowInterceptTouchEvent(true);
break;
}*/
// For all touch-events
this.Parent.RequestDisallowInterceptTouchEvent(true);
return base.DispatchTouchEvent(e);
}
In my case it works as expected.
I have this issue as well. Please fix.
Hello,
Having the same issue in 4.0.0 pre 9. Will this be fixed soon ?
The problem is still there. Tested with preview 9.
As a workaround, you can create a custom renderer for your WebView
and add the following override:
public override bool DispatchTouchEvent(MotionEvent e)
{
Parent.RequestDisallowInterceptTouchEvent(true);
return base.DispatchTouchEvent(e);
}
It works for me.
thx.
As a workaround, you can create a custom renderer for your
WebView
and add the following override:public override bool DispatchTouchEvent(MotionEvent e) { Parent.RequestDisallowInterceptTouchEvent(true); return base.DispatchTouchEvent(e); }
Could you please explain how can I do this?
You have to create a custom renderer for the webview (Android, iOS)
namespace MyNamespace
{
public class MyWebView : WebView
{
}
}
2. For each project create a custom renderer
```C#
using Android.Content;
using Android.Views;
using Xamarin.Forms.Platform.Android;
using Xamarin.Forms;
using MyNamespace;
using MyNamespace.Droid;
[assembly: ExportRenderer(typeof(MyWebView), typeof(MyWebViewRenderer))]
namespace MyNamespace.Droid
{
class MyWebViewRenderer : WebViewRenderer
{
public MyWebViewRenderer(Context context) : base(context)
{
}
protected override void OnElementChanged(ElementChangedEventArgs<WebView> e)
{
base.OnElementChanged(e);
}
public override bool DispatchTouchEvent(MotionEvent e)
{
Parent.RequestDisallowInterceptTouchEvent(true);
return base.DispatchTouchEvent(e);
}
}
}
This is still not working for me. I get the same "no scrolling" behavior in standard WebView and when using Xam.Plugin.Web. This seems like a pretty big bug since webviews are common. Help :) ?
I can confirm that the workaround works (at least for Android). Even though I would prefer it to work out of the box...
closed by #7032
@philousb - you sir deserve a medal. Works perfect. Ty!
I have tried philousb custom webview renderer on a contentpage with a scrollview inside the scrollview a grid and in the grid at the 3 Row a webview. Without the custom renderer scrolling works only in landscape mode. With the custom renderer it works only when it is not in landscape mode. When i remove the scrollview it works with standard webview in both modes. Tested on a Huawei p20 pro with android 9
Most helpful comment
You have to create a custom renderer for the webview (Android, iOS)
```C#
using System;
using System.Collections.Generic;
using System.Text;
using Xamarin.Forms;
namespace MyNamespace
{
public class MyWebView : WebView
{
}
}