Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Single Tap Xamarin Forms Button Renderer for Android
using Android.Views;
[assembly: Xamarin.Forms.ExportRenderer(typeof(Xamarin.Forms.Button), typeof(InTheHand.Forms.Platform.Android.SingleTapButtonRenderer))]
namespace InTheHand.Forms.Platform.Android
{
public sealed class SingleTapButtonRenderer : Xamarin.Forms.Platform.Android.ButtonRenderer
{
bool justClicked = false;
public override bool OnFilterTouchEventForSecurity(MotionEvent e)
{
if(e.Action == MotionEventActions.Up)
{
if(justClicked)
{
return false;
}
else
{
justClicked = true;
global::System.Threading.Tasks.Task.Run(async () =>
{
// reset after a timeout
await global::System.Threading.Tasks.Task.Delay(500);
justClicked = false;
});
}
return true;
}
return base.OnFilterTouchEventForSecurity(e);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.