Add extension methods for ScaleXTo and ScaleYTo (#8007) fixes #8004

* Add extension methods for ScaleXTo and ScaleYTo

* Updated sample with small description

* Updated test
This commit is contained in:
Steven Thewissen 2019-10-18 12:22:48 +01:00 коммит произвёл Rui Marinho
Родитель 98b9f7d6ba
Коммит b5beace03b
4 изменённых файлов: 112 добавлений и 1 удалений

Просмотреть файл

@ -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
}
}

Просмотреть файл

@ -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()

Просмотреть файл

@ -1118,6 +1118,7 @@
<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>

Просмотреть файл

@ -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)