using Android.Content;
using Android.Views;
using Microsoft.Maui.Handlers;
using Microsoft.Maui.Platform;
namespace JiDangJia;
public sealed class HorizontalChoiceScrollHandler : ScrollViewHandler
{
protected override MauiScrollView CreatePlatformView()=>new ChoiceScroll(MauiContext?.Context??throw new InvalidOperationException("Android context is unavailable")){ClipToOutline=true,FillViewport=true};
private sealed class ChoiceScroll(Context context) : MauiScrollView(context)
{
private float startX,startY;
private readonly int slop=ViewConfiguration.Get(context)!.ScaledTouchSlop;
public override bool DispatchTouchEvent(MotionEvent? e)
{
if(e is null)return base.DispatchTouchEvent(e);
if(e.ActionMasked==MotionEventActions.Down){startX=e.RawX;startY=e.RawY;Parent?.RequestDisallowInterceptTouchEvent(true);}
else if(e.ActionMasked==MotionEventActions.Move)
{
var dx=Math.Abs(e.RawX-startX);var dy=Math.Abs(e.RawY-startY);
// Horizontal gestures belong to the category strip. Release a
// vertical drag so the page's scroller can still receive it.
if(dy>slop&&dy>dx)Parent?.RequestDisallowInterceptTouchEvent(false);
}
var handled=base.DispatchTouchEvent(e);
if(e.ActionMasked is MotionEventActions.Up or MotionEventActions.Cancel)Parent?.RequestDisallowInterceptTouchEvent(false);
return handled;
}
}
}
using Android.Content;
using Android.Views;
using Microsoft.Maui.Handlers;
using Microsoft.Maui.Platform;
namespace JiDangJia;
public sealed class HorizontalChoiceScrollHandler : ScrollViewHandler
{
protected override MauiScrollView CreatePlatformView()=>new ChoiceScroll(MauiContext?.Context??throw new InvalidOperationException("Android context is unavailable")){ClipToOutline=true,FillViewport=true};
private sealed class ChoiceScroll(Context context) : MauiScrollView(context)
{
private float startX,startY;
private readonly int slop=ViewConfiguration.Get(context)!.ScaledTouchSlop;
public override bool DispatchTouchEvent(MotionEvent? e)
{
if(e is null)return base.DispatchTouchEvent(e);
if(e.ActionMasked==MotionEventActions.Down){startX=e.RawX;startY=e.RawY;Parent?.RequestDisallowInterceptTouchEvent(true);}
else if(e.ActionMasked==MotionEventActions.Move)
{
var dx=Math.Abs(e.RawX-startX);var dy=Math.Abs(e.RawY-startY);
// Horizontal gestures belong to the category strip. Release a
// vertical drag so the page's scroller can still receive it.
if(dy>slop&&dy>dx)Parent?.RequestDisallowInterceptTouchEvent(false);
}
var handled=base.DispatchTouchEvent(e);
if(e.ActionMasked is MotionEventActions.Up or MotionEventActions.Cancel)Parent?.RequestDisallowInterceptTouchEvent(false);
return handled;
}
}
}