Reputation: 1051
I am overriding Xamarin's built in OnTouchEvent. I need the coordinates and the actions, the user creates. It properly emits Move, and Up actions, only if I move my finger on the screen.
It does not however: 1, emit anything, if I don't move my finger, only tap once (should be 1 Down and 1 Up event). 2, emit Down action, when I move my finger.
The XAML:
<renderers:CustomCollectionView
x:Name="ListItemsContaner"
IsGrouped="True"
ItemsSource="{Binding GroupedItems}">
<CollectionView.GestureRecognizers>
<TapGestureRecognizer NumberOfTapsRequired="1" Tapped="OnClicked"></TapGestureRecognizer>
</CollectionView.GestureRecognizers>
...
</renderers:CustomCollectionView>
Here's the renderer's code
using Android.Views;
using AppTourism.Droid.Renderers;
using AppTourism.Renderers;
using Xamarin.Forms;
using Xamarin.Forms.Platform.Android;
[assembly: ExportRenderer(typeof(CustomCollectionView), typeof(CustomCollectionViewRenderer))]
namespace AppTourism.Droid.Renderers
{
public class CustomCollectionViewRenderer : CollectionViewRenderer, ICustomCollectionViewRenderer
{
public CustomCollectionViewRenderer(Android.Content.Context context) : base(context) { }
public override bool OnTouchEvent(MotionEvent e)
{
System.Console.WriteLine(e.Action);
System.Console.WriteLine(e.RawX + " " + e.RawY);
return base.OnTouchEvent(e);
}
}
}
Upvotes: 0
Views: 501
Reputation: 1944
It seems a bug on not only collectionview but also other views in xamarin, like this issue said:
https://github.com/xamarin/Xamarin.Forms/issues/7159
The workaround is use TapGestureRecognizer instead:
<CollectionView.GestureRecognizers>
<TapGestureRecognizer NumberOfTapsRequired="1" Tapped="OnClicked"></TapGestureRecognizer>
</CollectionView.GestureRecognizers>
EDIT:
You can override the DispatchTouchEvent
public override bool DispatchTouchEvent(MotionEvent e)
{System.Console.WriteLine(e.Action);
System.Console.WriteLine(e.RawX + " " + e.RawY);
return base.DispatchTouchEvent(e);}
Upvotes: 1