Skip to content

Instantly share code, notes, and snippets.

@programmation
Created September 18, 2015 07:24
Show Gist options
  • Save programmation/7408f2888a9c51a0d58f to your computer and use it in GitHub Desktop.
Save programmation/7408f2888a9c51a0d58f to your computer and use it in GitHub Desktop.
Xamarin Forms View extension (shake)
public static void Shake (this View view, int shakes = 4, Action completion = null)
{
Task.Run (() => {
Device.BeginInvokeOnMainThread (async () => {
uint duration = 50;
await view.TranslateTo (5.0, 0, duration, Easing.Linear);
for (var shake = 1; shake < shakes - 1; shake++) {
await view.TranslateTo (-10.0, 0, duration, Easing.Linear);
await view.TranslateTo (10.0, 0, duration, Easing.Linear);
}
await view.TranslateTo (0, 0, duration, Easing.Linear);
if (completion != null) {
completion ();
}
});
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment