67 lines
2.1 KiB
C#
67 lines
2.1 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using Android.App;
|
|
using Android.Content;
|
|
using Android.OS;
|
|
using Android.Runtime;
|
|
using Android.Views;
|
|
using Android.Widget;
|
|
using Sarand.Core.Base;
|
|
using Xamarin.Forms;
|
|
using Xamarin.Forms.Platform.Android;
|
|
|
|
[assembly: ExportRenderer(typeof(WebView), typeof(Sarand.LogisticsMgr.Mobile.Droid.Forms.Views.SlmWebViewRenderer))]
|
|
namespace Sarand.LogisticsMgr.Mobile.Droid.Forms.Views
|
|
{
|
|
//=======================================================================
|
|
/// <summary>
|
|
/// Rerplacement Web View Renderer to enable/override default behaviour.
|
|
/// <para>1. Enable scrcolling within Scroll View etc.</para>
|
|
/// <para>Ref. https://forums.xamarin.com/discussion/54365/android-enabling-scrolling-for-a-webview-inside-a-scrollview</para>
|
|
/// </summary>
|
|
public class SlmWebViewRenderer : WebViewRenderer
|
|
{
|
|
//-------------------------------------------------------------------
|
|
// Construction.
|
|
public SlmWebViewRenderer (Context context) : base(context)
|
|
{
|
|
Logger.Trace(GetType().Name + " CTR");
|
|
}
|
|
|
|
//-------------------------------------------------------------------
|
|
protected override void OnElementChanged (ElementChangedEventArgs<WebView> e)
|
|
{
|
|
base.OnElementChanged(e);
|
|
if (e.OldElement != null)
|
|
{
|
|
Control.Touch -= Control_Touch;
|
|
}
|
|
if (e.NewElement != null)
|
|
{
|
|
Control.Touch += Control_Touch;
|
|
}
|
|
}
|
|
|
|
//-------------------------------------------------------------------
|
|
void Control_Touch (object sender, Android.Views.View.TouchEventArgs e)
|
|
{
|
|
// Executing this will prevent the Scrolling to be intercepted by parent views.
|
|
switch (e.Event.Action)
|
|
{
|
|
case MotionEventActions.Down:
|
|
Control.Parent.RequestDisallowInterceptTouchEvent(true);
|
|
break;
|
|
case MotionEventActions.Up:
|
|
Control.Parent.RequestDisallowInterceptTouchEvent(false);
|
|
break;
|
|
}
|
|
// Calling this will allow the scrolling event to be executed in the WebView.
|
|
Control.OnTouchEvent(e.Event);
|
|
}
|
|
|
|
//-------------------------------------------------------------------
|
|
}
|
|
//=======================================================================
|
|
} |