Ga naar hoofdinhoud
Logo Appt Light

Input cancellation on Xamarin

Users should be able to cancel accidental interaction. For example, when users accidentally touches the wrong button, they should be able to undo this and avoid performing an action. Accidental interaction is more common for people with various disabilities.

In Xamarin.Forms, be careful when building a CustomRenderer to detect touch events. Make sure not to use the down event for actions. For tap events, you should use TapGestureRecognizer.

// Android CustomRenderer
public override bool OnTouchEvent(MotionEvent event)
{
    if (e.Action == MotionEventActions.Down)
    {
        // Don't use down event
    }
    return base.OnTouchEvent(event);
}
    
// iOS CustomRenderer
public override void TouchesBegan(NSSet touches, UIEvent event)
{
    // Don't use down event
    base.TouchesBegan(touches, event);
}
Bijdragen

Feedback?

Laat 't ons weten!