Skip to content

Instantly share code, notes, and snippets.

@peterfoot
Created May 5, 2016 19:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save peterfoot/0cec7531d022c7cc8939115d466a6759 to your computer and use it in GitHub Desktop.
Save peterfoot/0cec7531d022c7cc8939115d466a6759 to your computer and use it in GitHub Desktop.
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