Add extension methods for ScaleXTo and ScaleYTo (#8007) fixes #8004
authorSteven Thewissen <github@thewissen.io>
Fri, 18 Oct 2019 11:22:48 +0000 (12:22 +0100)
committerRui Marinho <me@ruimarinho.net>
Fri, 18 Oct 2019 11:22:48 +0000 (12:22 +0100)
* Add extension methods for ScaleXTo and ScaleYTo

* Updated sample with small description

* Updated test

Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Issue8004.cs [new file with mode: 0644]
Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/TestPages/TestPages.cs
Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Xamarin.Forms.Controls.Issues.Shared.projitems
Xamarin.Forms.Core/ViewExtensions.cs

diff --git a/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Issue8004.cs b/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Issue8004.cs
new file mode 100644 (file)
index 0000000..862ec4a
--- /dev/null
@@ -0,0 +1,92 @@
+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
+       }
+}
index 3169042..f6db309 100644 (file)
@@ -89,7 +89,7 @@ namespace Xamarin.Forms.Controls
                        }
 
                        // Running on the simulator
-                       //var app = ConfigureApp.iOS
+                       // var app = ConfigureApp.iOS
                        //                                .PreferIdeSettings()
                        //                                .AppBundle("../../../Xamarin.Forms.ControlGallery.iOS/bin/iPhoneSimulator/Debug/XamarinFormsControlGalleryiOS.app")
                        //                                .Debug()
index 5315bdf..2536a6e 100644 (file)
     <Compile Include="$(MSBuildThisFileDirectory)Issue6127.cs" />
     <Compile Include="$(MSBuildThisFileDirectory)Issue7283.cs" />
     <Compile Include="$(MSBuildThisFileDirectory)Issue5395.cs" />
+    <Compile Include="$(MSBuildThisFileDirectory)Issue8004.cs" />
     <Compile Include="$(MSBuildThisFileDirectory)Issue7898.cs" />
   </ItemGroup>
   <ItemGroup>
index 46e80f1..02d8b3e 100644 (file)
@@ -15,6 +15,8 @@ namespace Xamarin.Forms
                        view.AbortAnimation(nameof(RotateYTo));
                        view.AbortAnimation(nameof(RotateXTo));
                        view.AbortAnimation(nameof(ScaleTo));
+                       view.AbortAnimation(nameof(ScaleXTo));
+                       view.AbortAnimation(nameof(ScaleYTo));
                        view.AbortAnimation(nameof(FadeTo));
                }
 
@@ -116,6 +118,22 @@ namespace Xamarin.Forms
                        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)