Skip to content

Instantly share code, notes, and snippets.

@danvanderboom
Last active September 11, 2019 02:12
Show Gist options
  • Save danvanderboom/0319256fa3f1f2f50be2 to your computer and use it in GitHub Desktop.
Save danvanderboom/0319256fa3f1f2f50be2 to your computer and use it in GitHub Desktop.
using System;
using System.Threading.Tasks;
using Xamarin.Forms;
public static class ViewExtensions
{
public static void ShiftColorTo (this VisualElement view, Color sourceColor, Color targetColor, Action<Color> setter, uint length = 250, Easing easing = null)
{
view.Animate ("ShiftColorTo",
x =>
{
var red = sourceColor.R + (x * (targetColor.R - sourceColor.R));
var green = sourceColor.G + (x * (targetColor.G - sourceColor.G));
var blue = sourceColor.B + (x * (targetColor.B - sourceColor.B));
var alpha = sourceColor.A + (x * (targetColor.A - sourceColor.A));
setter(Color.FromRgba(red, green, blue, alpha));
},
length: length,
easing: easing);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment