Created
February 12, 2019 07:15
-
-
Save taimila/1b4161dcbca43df6032ae34aa2576573 to your computer and use it in GitHub Desktop.
Xamarin.Forms view's width and height animation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static class ExtraAnimations | |
{ | |
public static async Task<bool> HeightTo(this View view, double height, uint duration = 250, Easing easing = null) | |
{ | |
var tcs = new TaskCompletionSource<bool>(); | |
var heightAnimation = new Animation(x => view.HeightRequest = x, view.Height, height); | |
heightAnimation.Commit(view, "HeightAnimation", 10, duration, easing, (finalValue, finished) => { tcs.SetResult(finished); }); | |
return await tcs.Task; | |
} | |
public static async Task<bool> WidthTo(this View view, double width, uint duration = 250, Easing easing = null) | |
{ | |
var tcs = new TaskCompletionSource<bool>(); | |
var heightAnimation = new Animation(x => view.WidthRequest = x, view.Height, width); | |
heightAnimation.Commit(view, "WidthAnimation", 10, duration, easing, (finalValue, finished) => { tcs.SetResult(finished); }); | |
return await tcs.Task; | |
} | |
} |
Works great! Might want to change the starting value in WidthTo() from view.Height to view.Width though.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Great.