--- /dev/null
+using System;
+using Xamarin.Forms.CustomAttributes;
+using Xamarin.Forms.Internals;
+using System.Threading.Tasks;
+
+#if UITEST
+using Xamarin.UITest;
+using NUnit.Framework;
+using Xamarin.Forms.Core.UITests;
+#endif
+
+namespace Xamarin.Forms.Controls.Issues
+{
+#if UITEST
+ [Category(UITestCategories.Animation)]
+#endif
+ [Preserve(AllMembers = true)]
+ [Issue(IssueTracker.Github, 8004, "Add a ScaleXTo and ScaleYTo animation extension method", PlatformAffected.All)]
+ public class Issue8004 : TestContentPage
+ {
+ BoxView _boxView;
+ const string AnimateBoxViewButton = "AnimateBoxViewButton";
+ const string BoxToScale = "BoxToScale";
+
+ protected override void Init()
+ {
+ var label = new Label
+ {
+ Text = "Click the button below to animate the BoxView using individual ScaleXTo and ScaleYTo extension methods.",
+ TextColor = Color.Black
+ };
+
+ var button = new Button
+ {
+ AutomationId = AnimateBoxViewButton,
+ Text = "Animate BoxView",
+ BackgroundColor = Color.Black,
+ TextColor = Color.White,
+ VerticalOptions = LayoutOptions.EndAndExpand
+ };
+
+ button.Clicked += AnimateButton_Clicked;
+
+ _boxView = new BoxView
+ {
+ AutomationId = BoxToScale,
+ BackgroundColor = Color.Blue,
+ WidthRequest = 200,
+ HeightRequest = 100,
+ HorizontalOptions = LayoutOptions.Center
+ };
+
+ var grid = new Grid();
+
+ Grid.SetRow(label, 0);
+ Grid.SetRow(_boxView, 1);
+ Grid.SetRow(button, 2);
+
+ grid.Children.Add(label);
+ grid.Children.Add(_boxView);
+ grid.Children.Add(button);
+
+ Content = grid;
+ }
+
+ void AnimateButton_Clicked(object sender, EventArgs e)
+ {
+ _boxView.ScaleYTo(2, 250, Easing.CubicInOut);
+ _boxView.ScaleXTo(1.5, 400, Easing.BounceOut);
+ }
+
+#if UITEST
+ [Test]
+ public async Task AnimateScaleOfBoxView()
+ {
+ RunningApp.Screenshot("Small blue box");
+
+ // Check the box and button elements.
+ RunningApp.WaitForElement(q => q.Marked(BoxToScale));
+ RunningApp.WaitForElement(q => q.Marked(AnimateBoxViewButton));
+
+ // Tap the button.
+ RunningApp.Tap(q => q.Marked(AnimateBoxViewButton));
+
+ // Wait for animation to finish.
+ await Task.Delay(500);
+
+ RunningApp.Screenshot("Bigger blue box");
+ }
+#endif
+ }
+}
view.AbortAnimation(nameof(RotateYTo));
view.AbortAnimation(nameof(RotateXTo));
view.AbortAnimation(nameof(ScaleTo));
+ view.AbortAnimation(nameof(ScaleXTo));
+ view.AbortAnimation(nameof(ScaleYTo));
view.AbortAnimation(nameof(FadeTo));
}
return AnimateTo(view, view.Scale, scale, nameof(ScaleTo), (v, value) => v.Scale = value, length, easing);
}
+ public static Task<bool> ScaleXTo(this VisualElement view, double scale, uint length = 250, Easing easing = null)
+ {
+ if (view == null)
+ throw new ArgumentNullException(nameof(view));
+
+ return AnimateTo(view, view.ScaleX, scale, nameof(ScaleXTo), (v, value) => v.ScaleX = value, length, easing);
+ }
+
+ public static Task<bool> ScaleYTo(this VisualElement view, double scale, uint length = 250, Easing easing = null)
+ {
+ if (view == null)
+ throw new ArgumentNullException(nameof(view));
+
+ return AnimateTo(view, view.ScaleY, scale, nameof(ScaleYTo), (v, value) => v.ScaleY = value, length, easing);
+ }
+
public static Task<bool> TranslateTo(this VisualElement view, double x, double y, uint length = 250, Easing easing = null)
{
if (view == null)