Hi,
I have a use case with a Collectionview with custom views where a click/touch on a item will open a new page and a longclick will open a popup with some options for the view in the collection (remove, edit, etc).
From what I understand I can't implement this in Forms, I would have to use an effect or custom renderer. I thought I would be able to use the TouchEffect effect from the Xamarin documentation and its been working great for the Touch to open.
Now I would like to be able to use a LongClick/LongPress interaction as well. I've decided to modify the existing TouchEffect effect so that it also can fire a LongPressEvent. My TouchEffect class now looks like this:
public class TouchEffect : RoutingEffect
{
public event TouchActionEventHandler TouchAction;
public event EventHandler<EventArgs> LongPressAction;
public TouchEffect() : base("XamarinDocs.TouchEffect")
{
}
public bool Capture { set; get; }
public void OnTouchAction(Element element, TouchActionEventArgs args)
{
TouchAction?.Invoke(element, args);
}
public void OnLongPressAction(Element element, EventArgs args)
{
LongPressAction?.Invoke(element, args);
}
}
This works great in iOS, for the iOS platform effect I just added a UILongPressGestureRecognizer to the view and call the OnLongPressAction in its callback.
For Android I thought that I would be able to do the same and just add a callback to view.OnLongClick and call OnLongPressAction from there.
This does not seem to work since I also have a callback for view.OnTouch that sets the event.Handled to true, and setting event.Handled to false would mean that that other events like MotionEventActions.Up wont fire.
I read here that if I want to be able to use both OnClick and OnTouch that I would need a GestureDetector. Does that mean that I need a custom renderer? Is there any other way to solve this?
Any input would be greatly appreciated.