Merge pull request #37 from jsuarezruiz/dev
Added Forms Community Toolkit animations code
This commit is contained in:
Коммит
b2ec324b26
|
@ -1,7 +1,7 @@
|
|||
|
||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
# Visual Studio 15
|
||||
VisualStudioVersion = 15.0.26430.4
|
||||
# Visual Studio 14
|
||||
VisualStudioVersion = 14.0.25420.1
|
||||
MinimumVisualStudioVersion = 10.0.40219.1
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Samples.Android", "Samples\Samples.Android\Samples.Android.csproj", "{B67F4E95-07A1-41CE-BF6F-3E5B8D4F2F48}"
|
||||
EndProject
|
||||
|
|
|
@ -40,6 +40,10 @@
|
|||
<DocumentationFile>bin\Release\FormsCommunityToolkit.Animations.Android.XML</DocumentationFile>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="FormsViewGroup, Version=2.0.0.0, Culture=neutral, processorArchitecture=MSIL">
|
||||
<HintPath>..\..\packages\Xamarin.Forms.2.3.4.247\lib\MonoAndroid10\FormsViewGroup.dll</HintPath>
|
||||
<Private>True</Private>
|
||||
</Reference>
|
||||
<Reference Include="Mono.Android" />
|
||||
<Reference Include="mscorlib" />
|
||||
<Reference Include="System" />
|
||||
|
@ -78,20 +82,21 @@
|
|||
<HintPath>..\..\packages\Xamarin.Android.Support.Vector.Drawable.23.3.0\lib\MonoAndroid403\Xamarin.Android.Support.Vector.Drawable.dll</HintPath>
|
||||
<Private>True</Private>
|
||||
</Reference>
|
||||
<Reference Include="FormsViewGroup">
|
||||
<HintPath>..\..\packages\Xamarin.Forms.2.3.2.127\lib\MonoAndroid10\FormsViewGroup.dll</HintPath>
|
||||
<Reference Include="Xamarin.Forms.Core, Version=2.0.0.0, Culture=neutral, processorArchitecture=MSIL">
|
||||
<HintPath>..\..\packages\Xamarin.Forms.2.3.4.247\lib\MonoAndroid10\Xamarin.Forms.Core.dll</HintPath>
|
||||
<Private>True</Private>
|
||||
</Reference>
|
||||
<Reference Include="Xamarin.Forms.Core">
|
||||
<HintPath>..\..\packages\Xamarin.Forms.2.3.2.127\lib\MonoAndroid10\Xamarin.Forms.Core.dll</HintPath>
|
||||
<Reference Include="Xamarin.Forms.Platform, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL">
|
||||
<HintPath>..\..\packages\Xamarin.Forms.2.3.4.247\lib\MonoAndroid10\Xamarin.Forms.Platform.dll</HintPath>
|
||||
<Private>True</Private>
|
||||
</Reference>
|
||||
<Reference Include="Xamarin.Forms.Platform.Android">
|
||||
<HintPath>..\..\packages\Xamarin.Forms.2.3.2.127\lib\MonoAndroid10\Xamarin.Forms.Platform.Android.dll</HintPath>
|
||||
<Reference Include="Xamarin.Forms.Platform.Android, Version=2.0.0.0, Culture=neutral, processorArchitecture=MSIL">
|
||||
<HintPath>..\..\packages\Xamarin.Forms.2.3.4.247\lib\MonoAndroid10\Xamarin.Forms.Platform.Android.dll</HintPath>
|
||||
<Private>True</Private>
|
||||
</Reference>
|
||||
<Reference Include="Xamarin.Forms.Platform">
|
||||
<HintPath>..\..\packages\Xamarin.Forms.2.3.2.127\lib\MonoAndroid10\Xamarin.Forms.Platform.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Xamarin.Forms.Xaml">
|
||||
<HintPath>..\..\packages\Xamarin.Forms.2.3.2.127\lib\MonoAndroid10\Xamarin.Forms.Xaml.dll</HintPath>
|
||||
<Reference Include="Xamarin.Forms.Xaml, Version=2.0.0.0, Culture=neutral, processorArchitecture=MSIL">
|
||||
<HintPath>..\..\packages\Xamarin.Forms.2.3.4.247\lib\MonoAndroid10\Xamarin.Forms.Xaml.dll</HintPath>
|
||||
<Private>True</Private>
|
||||
</Reference>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
|
@ -111,6 +116,7 @@
|
|||
<ErrorText>This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
|
||||
</PropertyGroup>
|
||||
<Error Condition="!Exists('..\..\packages\Xamarin.Android.Support.Vector.Drawable.23.3.0\build\Xamarin.Android.Support.Vector.Drawable.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\..\packages\Xamarin.Android.Support.Vector.Drawable.23.3.0\build\Xamarin.Android.Support.Vector.Drawable.targets'))" />
|
||||
<Error Condition="!Exists('..\..\packages\Xamarin.Forms.2.3.4.247\build\portable-win+net45+wp80+win81+wpa81+MonoAndroid10+Xamarin.iOS10+xamarinmac20\Xamarin.Forms.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\..\packages\Xamarin.Forms.2.3.4.247\build\portable-win+net45+wp80+win81+wpa81+MonoAndroid10+Xamarin.iOS10+xamarinmac20\Xamarin.Forms.targets'))" />
|
||||
</Target>
|
||||
<Import Project="..\..\packages\Xamarin.Forms.2.3.2.127\build\portable-win+net45+wp80+win81+wpa81+MonoAndroid10+MonoTouch10+Xamarin.iOS10\Xamarin.Forms.targets" Condition="Exists('..\..\packages\Xamarin.Forms.2.3.2.127\build\portable-win+net45+wp80+win81+wpa81+MonoAndroid10+MonoTouch10+Xamarin.iOS10\Xamarin.Forms.targets')" />
|
||||
<Import Project="..\..\packages\Xamarin.Forms.2.3.4.247\build\portable-win+net45+wp80+win81+wpa81+MonoAndroid10+Xamarin.iOS10+xamarinmac20\Xamarin.Forms.targets" Condition="Exists('..\..\packages\Xamarin.Forms.2.3.4.247\build\portable-win+net45+wp80+win81+wpa81+MonoAndroid10+Xamarin.iOS10+xamarinmac20\Xamarin.Forms.targets')" />
|
||||
</Project>
|
Разница между файлами не показана из-за своего большого размера
Загрузить разницу
|
@ -8,5 +8,5 @@
|
|||
<package id="Xamarin.Android.Support.v7.MediaRouter" version="23.3.0" targetFramework="monoandroid70" />
|
||||
<package id="Xamarin.Android.Support.v7.RecyclerView" version="23.3.0" targetFramework="monoandroid70" />
|
||||
<package id="Xamarin.Android.Support.Vector.Drawable" version="23.3.0" targetFramework="monoandroid70" />
|
||||
<package id="Xamarin.Forms" version="2.3.2.127" targetFramework="monoandroid70" />
|
||||
<package id="Xamarin.Forms" version="2.3.4.247" targetFramework="monoandroid60" />
|
||||
</packages>
|
|
@ -2,7 +2,7 @@
|
|||
"dependencies": {
|
||||
"Microsoft.NETCore.UniversalWindowsPlatform": "5.1.0",
|
||||
"Win2D.uwp": "1.19.0",
|
||||
"Xamarin.Forms": "2.3.2.127"
|
||||
"Xamarin.Forms": "2.3.4.247"
|
||||
},
|
||||
"frameworks": {
|
||||
"uap10.0": {}
|
||||
|
|
|
@ -37,19 +37,23 @@
|
|||
<Reference Include="System" />
|
||||
<Reference Include="System.Xml" />
|
||||
<Reference Include="System.Core" />
|
||||
<Reference Include="Xamarin.Forms.Core, Version=2.0.0.0, Culture=neutral, processorArchitecture=MSIL">
|
||||
<HintPath>..\..\packages\Xamarin.Forms.2.3.4.247\lib\Xamarin.iOS10\Xamarin.Forms.Core.dll</HintPath>
|
||||
<Private>True</Private>
|
||||
</Reference>
|
||||
<Reference Include="Xamarin.Forms.Platform, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL">
|
||||
<HintPath>..\..\packages\Xamarin.Forms.2.3.4.247\lib\Xamarin.iOS10\Xamarin.Forms.Platform.dll</HintPath>
|
||||
<Private>True</Private>
|
||||
</Reference>
|
||||
<Reference Include="Xamarin.Forms.Platform.iOS, Version=2.0.0.0, Culture=neutral, processorArchitecture=MSIL">
|
||||
<HintPath>..\..\packages\Xamarin.Forms.2.3.4.247\lib\Xamarin.iOS10\Xamarin.Forms.Platform.iOS.dll</HintPath>
|
||||
<Private>True</Private>
|
||||
</Reference>
|
||||
<Reference Include="Xamarin.Forms.Xaml, Version=2.0.0.0, Culture=neutral, processorArchitecture=MSIL">
|
||||
<HintPath>..\..\packages\Xamarin.Forms.2.3.4.247\lib\Xamarin.iOS10\Xamarin.Forms.Xaml.dll</HintPath>
|
||||
<Private>True</Private>
|
||||
</Reference>
|
||||
<Reference Include="Xamarin.iOS" />
|
||||
<Reference Include="Xamarin.Forms.Core">
|
||||
<HintPath>..\..\packages\Xamarin.Forms.2.3.2.127\lib\Xamarin.iOS10\Xamarin.Forms.Core.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Xamarin.Forms.Platform">
|
||||
<HintPath>..\..\packages\Xamarin.Forms.2.3.2.127\lib\Xamarin.iOS10\Xamarin.Forms.Platform.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Xamarin.Forms.Platform.iOS">
|
||||
<HintPath>..\..\packages\Xamarin.Forms.2.3.2.127\lib\Xamarin.iOS10\Xamarin.Forms.Platform.iOS.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Xamarin.Forms.Xaml">
|
||||
<HintPath>..\..\packages\Xamarin.Forms.2.3.2.127\lib\Xamarin.iOS10\Xamarin.Forms.Xaml.dll</HintPath>
|
||||
</Reference>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Folder Include="Resources\" />
|
||||
|
@ -64,5 +68,11 @@
|
|||
<None Include="packages.config" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildExtensionsPath)\Xamarin\iOS\Xamarin.iOS.CSharp.targets" />
|
||||
<Import Project="..\..\packages\Xamarin.Forms.2.3.2.127\build\portable-win+net45+wp80+win81+wpa81+MonoAndroid10+MonoTouch10+Xamarin.iOS10\Xamarin.Forms.targets" Condition="Exists('..\..\packages\Xamarin.Forms.2.3.2.127\build\portable-win+net45+wp80+win81+wpa81+MonoAndroid10+MonoTouch10+Xamarin.iOS10\Xamarin.Forms.targets')" />
|
||||
<Import Project="..\..\packages\Xamarin.Forms.2.3.4.247\build\portable-win+net45+wp80+win81+wpa81+MonoAndroid10+Xamarin.iOS10+xamarinmac20\Xamarin.Forms.targets" Condition="Exists('..\..\packages\Xamarin.Forms.2.3.4.247\build\portable-win+net45+wp80+win81+wpa81+MonoAndroid10+Xamarin.iOS10+xamarinmac20\Xamarin.Forms.targets')" />
|
||||
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
|
||||
<PropertyGroup>
|
||||
<ErrorText>Este proyecto hace referencia a los paquetes NuGet que faltan en este equipo. Use la restauración de paquetes NuGet para descargarlos. Para obtener más información, consulte http://go.microsoft.com/fwlink/?LinkID=322105. El archivo que falta es {0}.</ErrorText>
|
||||
</PropertyGroup>
|
||||
<Error Condition="!Exists('..\..\packages\Xamarin.Forms.2.3.4.247\build\portable-win+net45+wp80+win81+wpa81+MonoAndroid10+Xamarin.iOS10+xamarinmac20\Xamarin.Forms.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\..\packages\Xamarin.Forms.2.3.4.247\build\portable-win+net45+wp80+win81+wpa81+MonoAndroid10+Xamarin.iOS10+xamarinmac20\Xamarin.Forms.targets'))" />
|
||||
</Target>
|
||||
</Project>
|
|
@ -1,4 +1,4 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<packages>
|
||||
<package id="Xamarin.Forms" version="2.3.2.127" targetFramework="xamarinios10" />
|
||||
<package id="Xamarin.Forms" version="2.3.4.247" targetFramework="xamarinios10" />
|
||||
</packages>
|
|
@ -37,32 +37,49 @@
|
|||
<DocumentationFile>bin\Release\FormsCommunityToolkit.Animations.xml</DocumentationFile>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="Animations\Base\AnimationBase.cs" />
|
||||
<Compile Include="Animations\BounceAnimation.cs" />
|
||||
<Compile Include="Animations\EasingType.cs" />
|
||||
<Compile Include="Animations\FadeAnimation.cs" />
|
||||
<Compile Include="Animations\FlipAnimation.cs" />
|
||||
<Compile Include="Animations\HeartAnimation.cs" />
|
||||
<Compile Include="Animations\JumpAnimation.cs" />
|
||||
<Compile Include="Animations\RotateAnimation.cs" />
|
||||
<Compile Include="Animations\ScaleAnimation.cs" />
|
||||
<Compile Include="Animations\ShakeAnimation.cs" />
|
||||
<Compile Include="Animations\StoryBoard.cs" />
|
||||
<Compile Include="Animations\TranslateAnimation.cs" />
|
||||
<Compile Include="Animations\TurnstileAnimation.cs" />
|
||||
<Compile Include="Behaviors\BeginAnimationBehavior.cs" />
|
||||
<Compile Include="Extensions\AnimationExtension.cs" />
|
||||
<Compile Include="Helpers\EasingHelper.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="Xamarin.Forms.Core, Version=2.0.0.0, Culture=neutral, processorArchitecture=MSIL">
|
||||
<HintPath>..\..\packages\Xamarin.Forms.2.3.2.127\lib\portable-win+net45+wp80+win81+wpa81+MonoAndroid10+MonoTouch10+Xamarin.iOS10\Xamarin.Forms.Core.dll</HintPath>
|
||||
<HintPath>..\..\packages\Xamarin.Forms.2.3.4.247\lib\portable-win+net45+wp80+win81+wpa81+MonoAndroid10+Xamarin.iOS10+xamarinmac20\Xamarin.Forms.Core.dll</HintPath>
|
||||
<Private>True</Private>
|
||||
</Reference>
|
||||
<Reference Include="Xamarin.Forms.Platform, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL">
|
||||
<HintPath>..\..\packages\Xamarin.Forms.2.3.2.127\lib\portable-win+net45+wp80+win81+wpa81+MonoAndroid10+MonoTouch10+Xamarin.iOS10\Xamarin.Forms.Platform.dll</HintPath>
|
||||
<HintPath>..\..\packages\Xamarin.Forms.2.3.4.247\lib\portable-win+net45+wp80+win81+wpa81+MonoAndroid10+Xamarin.iOS10+xamarinmac20\Xamarin.Forms.Platform.dll</HintPath>
|
||||
<Private>True</Private>
|
||||
</Reference>
|
||||
<Reference Include="Xamarin.Forms.Xaml, Version=2.0.0.0, Culture=neutral, processorArchitecture=MSIL">
|
||||
<HintPath>..\..\packages\Xamarin.Forms.2.3.2.127\lib\portable-win+net45+wp80+win81+wpa81+MonoAndroid10+MonoTouch10+Xamarin.iOS10\Xamarin.Forms.Xaml.dll</HintPath>
|
||||
<HintPath>..\..\packages\Xamarin.Forms.2.3.4.247\lib\portable-win+net45+wp80+win81+wpa81+MonoAndroid10+Xamarin.iOS10+xamarinmac20\Xamarin.Forms.Xaml.dll</HintPath>
|
||||
<Private>True</Private>
|
||||
</Reference>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="packages.config" />
|
||||
</ItemGroup>
|
||||
<ItemGroup />
|
||||
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\Portable\$(TargetFrameworkVersion)\Microsoft.Portable.CSharp.targets" />
|
||||
<Import Project="..\..\packages\Xamarin.Forms.2.3.2.127\build\portable-win+net45+wp80+win81+wpa81+MonoAndroid10+MonoTouch10+Xamarin.iOS10\Xamarin.Forms.targets" Condition="Exists('..\..\packages\Xamarin.Forms.2.3.2.127\build\portable-win+net45+wp80+win81+wpa81+MonoAndroid10+MonoTouch10+Xamarin.iOS10\Xamarin.Forms.targets')" />
|
||||
<Import Project="..\..\packages\Xamarin.Forms.2.3.4.247\build\portable-win+net45+wp80+win81+wpa81+MonoAndroid10+Xamarin.iOS10+xamarinmac20\Xamarin.Forms.targets" Condition="Exists('..\..\packages\Xamarin.Forms.2.3.4.247\build\portable-win+net45+wp80+win81+wpa81+MonoAndroid10+Xamarin.iOS10+xamarinmac20\Xamarin.Forms.targets')" />
|
||||
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
|
||||
<PropertyGroup>
|
||||
<ErrorText>This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
|
||||
</PropertyGroup>
|
||||
<Error Condition="!Exists('..\..\packages\Xamarin.Forms.2.3.2.127\build\portable-win+net45+wp80+win81+wpa81+MonoAndroid10+MonoTouch10+Xamarin.iOS10\Xamarin.Forms.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\..\packages\Xamarin.Forms.2.3.2.127\build\portable-win+net45+wp80+win81+wpa81+MonoAndroid10+MonoTouch10+Xamarin.iOS10\Xamarin.Forms.targets'))" />
|
||||
<Error Condition="!Exists('..\..\packages\Xamarin.Forms.2.3.4.247\build\portable-win+net45+wp80+win81+wpa81+MonoAndroid10+Xamarin.iOS10+xamarinmac20\Xamarin.Forms.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\..\packages\Xamarin.Forms.2.3.4.247\build\portable-win+net45+wp80+win81+wpa81+MonoAndroid10+Xamarin.iOS10+xamarinmac20\Xamarin.Forms.targets'))" />
|
||||
</Target>
|
||||
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
|
||||
Other similar extension points exist, see Microsoft.Common.targets.
|
||||
|
|
|
@ -0,0 +1,45 @@
|
|||
using System.Threading.Tasks;
|
||||
using Xamarin.Forms;
|
||||
|
||||
namespace FormsCommunityToolkit.Animations
|
||||
{
|
||||
public abstract class AnimationBase : BindableObject
|
||||
{
|
||||
public static readonly BindableProperty TargetProperty =
|
||||
BindableProperty.Create(nameof(Target), typeof(VisualElement), typeof(AnimationBase), null,
|
||||
BindingMode.TwoWay, null);
|
||||
|
||||
public VisualElement Target
|
||||
{
|
||||
get { return (VisualElement)GetValue(TargetProperty); }
|
||||
set { SetValue(TargetProperty, value); }
|
||||
}
|
||||
|
||||
public static readonly BindableProperty DurationProperty =
|
||||
BindableProperty.Create(nameof(Duration), typeof(string), typeof(AnimationBase), "1000",
|
||||
BindingMode.TwoWay, null);
|
||||
|
||||
public string Duration
|
||||
{
|
||||
get { return (string)GetValue(DurationProperty); }
|
||||
set { SetValue(DurationProperty, value); }
|
||||
}
|
||||
|
||||
public static readonly BindableProperty EasingProperty =
|
||||
BindableProperty.Create(nameof(Easing), typeof(EasingType), typeof(AnimationBase), EasingType.Linear,
|
||||
BindingMode.TwoWay, null);
|
||||
|
||||
public EasingType Easing
|
||||
{
|
||||
get { return (EasingType)GetValue(EasingProperty); }
|
||||
set { SetValue(EasingProperty, value); }
|
||||
}
|
||||
|
||||
protected abstract Task BeginAnimation();
|
||||
|
||||
public async Task Begin()
|
||||
{
|
||||
await BeginAnimation();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,82 @@
|
|||
using System;
|
||||
using System.Threading.Tasks;
|
||||
using Xamarin.Forms;
|
||||
|
||||
namespace FormsCommunityToolkit.Animations
|
||||
{
|
||||
public class BounceInAnimation : AnimationBase
|
||||
{
|
||||
protected override Task BeginAnimation()
|
||||
{
|
||||
if (Target == null)
|
||||
{
|
||||
throw new NullReferenceException("Null Target property.");
|
||||
}
|
||||
|
||||
return Task.Run(() =>
|
||||
{
|
||||
Device.BeginInvokeOnMainThread(() =>
|
||||
{
|
||||
Target.Animate("BounceIn", BounceIn(), 16, Convert.ToUInt32(Duration));
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
internal Animation BounceIn()
|
||||
{
|
||||
var animation = new Animation();
|
||||
|
||||
animation.WithConcurrent(
|
||||
f => Target.Scale = f,
|
||||
0.5, 1,
|
||||
Xamarin.Forms.Easing.Linear, 0, 1);
|
||||
|
||||
animation.WithConcurrent(
|
||||
(f) => Target.Opacity = f,
|
||||
0, 1,
|
||||
null,
|
||||
0, 0.25);
|
||||
|
||||
return animation;
|
||||
}
|
||||
}
|
||||
|
||||
public class BounceOutAnimation : AnimationBase
|
||||
{
|
||||
protected override Task BeginAnimation()
|
||||
{
|
||||
if (Target == null)
|
||||
{
|
||||
throw new NullReferenceException("Null Target property.");
|
||||
}
|
||||
|
||||
return Task.Run(() =>
|
||||
{
|
||||
Device.BeginInvokeOnMainThread(() =>
|
||||
{
|
||||
Target.Animate("BounceOut", BounceOut(), 16, Convert.ToUInt32(Duration));
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
internal Animation BounceOut()
|
||||
{
|
||||
var animation = new Animation();
|
||||
|
||||
Target.Opacity = 1;
|
||||
|
||||
animation.WithConcurrent(
|
||||
(f) => Target.Opacity = f,
|
||||
1, 0,
|
||||
null,
|
||||
0.5, 1);
|
||||
|
||||
animation.WithConcurrent(
|
||||
(f) => Target.Scale = f,
|
||||
1, 0.3,
|
||||
Xamarin.Forms.Easing.Linear, 0, 1);
|
||||
|
||||
return animation;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,17 @@
|
|||
namespace FormsCommunityToolkit.Animations
|
||||
{
|
||||
public enum EasingType
|
||||
{
|
||||
BounceIn,
|
||||
BounceOut,
|
||||
CubicIn,
|
||||
CubicInOut,
|
||||
CubicOut,
|
||||
Linear,
|
||||
SinIn,
|
||||
SinInOut,
|
||||
SinOut,
|
||||
SpringIn,
|
||||
SpringOut
|
||||
}
|
||||
}
|
|
@ -0,0 +1,128 @@
|
|||
using System;
|
||||
using System.Threading.Tasks;
|
||||
using Xamarin.Forms;
|
||||
|
||||
namespace FormsCommunityToolkit.Animations
|
||||
{
|
||||
public class FadeToAnimation : AnimationBase
|
||||
{
|
||||
public static readonly BindableProperty OpacityProperty =
|
||||
BindableProperty.Create(nameof(Opacity), typeof(double), typeof(FadeToAnimation), default(double),
|
||||
BindingMode.TwoWay, null);
|
||||
|
||||
public double Opacity
|
||||
{
|
||||
get { return (double)GetValue(OpacityProperty); }
|
||||
set { SetValue(OpacityProperty, value); }
|
||||
}
|
||||
|
||||
protected override Task BeginAnimation()
|
||||
{
|
||||
if (Target == null)
|
||||
{
|
||||
throw new NullReferenceException("Null Target property.");
|
||||
}
|
||||
|
||||
return Target.FadeTo(Opacity, Convert.ToUInt32(Duration), EasingHelper.GetEasing(Easing));
|
||||
}
|
||||
}
|
||||
|
||||
public class FadeInAnimation : AnimationBase
|
||||
{
|
||||
public enum FadeDirection
|
||||
{
|
||||
Up,
|
||||
Down
|
||||
}
|
||||
|
||||
public static readonly BindableProperty DirectionProperty =
|
||||
BindableProperty.Create(nameof(Direction), typeof(FadeDirection), typeof(FadeInAnimation), FadeDirection.Up,
|
||||
BindingMode.TwoWay, null);
|
||||
|
||||
public FadeDirection Direction
|
||||
{
|
||||
get { return (FadeDirection)GetValue(DirectionProperty); }
|
||||
set { SetValue(DirectionProperty, value); }
|
||||
}
|
||||
|
||||
protected override Task BeginAnimation()
|
||||
{
|
||||
if (Target == null)
|
||||
{
|
||||
throw new NullReferenceException("Null Target property.");
|
||||
}
|
||||
|
||||
return Task.Run(() =>
|
||||
{
|
||||
Device.BeginInvokeOnMainThread(() =>
|
||||
{
|
||||
Target.Animate("FadeIn", FadeIn(), 16, Convert.ToUInt32(Duration));
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
internal Animation FadeIn()
|
||||
{
|
||||
var animation = new Animation();
|
||||
|
||||
animation.WithConcurrent((f) => Target.Opacity = f, 0, 1, Xamarin.Forms.Easing.CubicOut);
|
||||
|
||||
animation.WithConcurrent(
|
||||
(f) => Target.TranslationY = f,
|
||||
Target.TranslationY + ((Direction == FadeDirection.Up) ? 50 : -50), Target.TranslationY,
|
||||
Xamarin.Forms.Easing.CubicOut, 0, 1);
|
||||
|
||||
return animation;
|
||||
}
|
||||
}
|
||||
|
||||
public class FadeOutAnimation : AnimationBase
|
||||
{
|
||||
public enum FadeDirection
|
||||
{
|
||||
Up,
|
||||
Down
|
||||
}
|
||||
|
||||
public static readonly BindableProperty DirectionProperty =
|
||||
BindableProperty.Create(nameof(Direction), typeof(FadeDirection), typeof(FadeOutAnimation), FadeDirection.Up,
|
||||
BindingMode.TwoWay, null);
|
||||
|
||||
public FadeDirection Direction
|
||||
{
|
||||
get { return (FadeDirection)GetValue(DirectionProperty); }
|
||||
set { SetValue(DirectionProperty, value); }
|
||||
}
|
||||
|
||||
protected override Task BeginAnimation()
|
||||
{
|
||||
if (Target == null)
|
||||
{
|
||||
throw new NullReferenceException("Null Target property.");
|
||||
}
|
||||
|
||||
return Task.Run(() =>
|
||||
{
|
||||
Device.BeginInvokeOnMainThread(() =>
|
||||
{
|
||||
Target.Animate("FadeOut", FadeOut(), 16, Convert.ToUInt32(Duration));
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
internal Animation FadeOut()
|
||||
{
|
||||
var animation = new Animation();
|
||||
|
||||
animation.WithConcurrent(
|
||||
(f) => Target.Opacity = f,
|
||||
1, 0);
|
||||
|
||||
animation.WithConcurrent(
|
||||
(f) => Target.TranslationY = f,
|
||||
Target.TranslationY, Target.TranslationY + ((Direction == FadeDirection.Up) ? 50 : -50));
|
||||
|
||||
return animation;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,51 @@
|
|||
using System;
|
||||
using System.Threading.Tasks;
|
||||
using Xamarin.Forms;
|
||||
|
||||
namespace FormsCommunityToolkit.Animations
|
||||
{
|
||||
public class FlipAnimation : AnimationBase
|
||||
{
|
||||
public enum FlipDirection
|
||||
{
|
||||
Left,
|
||||
Right
|
||||
}
|
||||
|
||||
public static readonly BindableProperty DirectionProperty =
|
||||
BindableProperty.Create(nameof(Direction), typeof(FlipDirection), typeof(FlipAnimation), FlipDirection.Right,
|
||||
BindingMode.TwoWay, null);
|
||||
|
||||
public FlipDirection Direction
|
||||
{
|
||||
get { return (FlipDirection)GetValue(DirectionProperty); }
|
||||
set { SetValue(DirectionProperty, value); }
|
||||
}
|
||||
|
||||
protected override Task BeginAnimation()
|
||||
{
|
||||
if (Target == null)
|
||||
{
|
||||
throw new NullReferenceException("Null Target property.");
|
||||
}
|
||||
|
||||
return Task.Run(() =>
|
||||
{
|
||||
Device.BeginInvokeOnMainThread(() =>
|
||||
{
|
||||
Target.Animate("Flip", Flip(), 16, Convert.ToUInt32(Duration));
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
internal Animation Flip()
|
||||
{
|
||||
var animation = new Animation();
|
||||
|
||||
animation.WithConcurrent((f) => Target.Opacity = f, 0.5, 1);
|
||||
animation.WithConcurrent((f) => Target.RotationY = f, (Direction == FlipDirection.Left) ? 90 : -90, 0, Xamarin.Forms.Easing.Linear);
|
||||
|
||||
return animation;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,57 @@
|
|||
using System;
|
||||
using System.Threading.Tasks;
|
||||
using Xamarin.Forms;
|
||||
|
||||
namespace FormsCommunityToolkit.Animations
|
||||
{
|
||||
public class HeartAnimation : AnimationBase
|
||||
{
|
||||
protected override Task BeginAnimation()
|
||||
{
|
||||
if (Target == null)
|
||||
{
|
||||
throw new NullReferenceException("Null Target property.");
|
||||
}
|
||||
|
||||
return Task.Run(() =>
|
||||
{
|
||||
Device.BeginInvokeOnMainThread(() =>
|
||||
{
|
||||
Target.Animate("Hearth", Hearth(), 16, Convert.ToUInt32(Duration));
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
internal Animation Hearth()
|
||||
{
|
||||
var animation = new Animation();
|
||||
|
||||
animation.WithConcurrent(
|
||||
(f) => Target.Scale = f,
|
||||
Target.Scale, Target.Scale,
|
||||
Xamarin.Forms.Easing.Linear, 0, 0.1);
|
||||
|
||||
animation.WithConcurrent(
|
||||
(f) => Target.Scale = f,
|
||||
Target.Scale, Target.Scale * 1.1,
|
||||
Xamarin.Forms.Easing.Linear, 0.1, 0.4);
|
||||
|
||||
animation.WithConcurrent(
|
||||
(f) => Target.Scale = f,
|
||||
Target.Scale * 1.1, Target.Scale,
|
||||
Xamarin.Forms.Easing.Linear, 0.4, 0.5);
|
||||
|
||||
animation.WithConcurrent(
|
||||
(f) => Target.Scale = f,
|
||||
Target.Scale, Target.Scale * 1.1,
|
||||
Xamarin.Forms.Easing.Linear, 0.5, 0.8);
|
||||
|
||||
animation.WithConcurrent(
|
||||
(f) => Target.Scale = f,
|
||||
Target.Scale * 1.1, Target.Scale,
|
||||
Xamarin.Forms.Easing.Linear, 0.8, 1);
|
||||
|
||||
return animation;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,49 @@
|
|||
using System;
|
||||
using System.Threading.Tasks;
|
||||
using Xamarin.Forms;
|
||||
|
||||
namespace FormsCommunityToolkit.Animations
|
||||
{
|
||||
public class JumpAnimation : AnimationBase
|
||||
{
|
||||
private const int Movement = -25;
|
||||
|
||||
protected override Task BeginAnimation()
|
||||
{
|
||||
if (Target == null)
|
||||
{
|
||||
throw new NullReferenceException("Null Target property.");
|
||||
}
|
||||
|
||||
return Task.Run(() =>
|
||||
{
|
||||
Device.BeginInvokeOnMainThread(() =>
|
||||
{
|
||||
Target.Animate("Jump", Jump(), 16, Convert.ToUInt32(Duration));
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
internal Animation Jump()
|
||||
{
|
||||
var animation = new Animation();
|
||||
|
||||
animation.WithConcurrent(
|
||||
(f) => Target.TranslationY = f,
|
||||
Target.TranslationY, Target.TranslationX,
|
||||
Xamarin.Forms.Easing.Linear, 0, 0.2);
|
||||
|
||||
animation.WithConcurrent(
|
||||
(f) => Target.TranslationY = f,
|
||||
Target.TranslationY + Movement, Target.TranslationX,
|
||||
Xamarin.Forms.Easing.Linear, 0.2, 0.4);
|
||||
|
||||
animation.WithConcurrent(
|
||||
(f) => Target.TranslationY = f,
|
||||
Target.TranslationY, Target.TranslationX,
|
||||
Xamarin.Forms.Easing.Linear, 0.5, 1.0);
|
||||
|
||||
return animation;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,98 @@
|
|||
using System;
|
||||
using System.Threading.Tasks;
|
||||
using Xamarin.Forms;
|
||||
|
||||
namespace FormsCommunityToolkit.Animations
|
||||
{
|
||||
public class RotateToAnimation : AnimationBase
|
||||
{
|
||||
public static readonly BindableProperty RotationProperty =
|
||||
BindableProperty.Create(nameof(Rotation), typeof(double), typeof(RotateToAnimation), 0,
|
||||
BindingMode.TwoWay, null);
|
||||
|
||||
public double Rotation
|
||||
{
|
||||
get { return (double)GetValue(RotationProperty); }
|
||||
set { SetValue(RotationProperty, value); }
|
||||
}
|
||||
|
||||
protected override Task BeginAnimation()
|
||||
{
|
||||
if (Target == null)
|
||||
{
|
||||
throw new NullReferenceException("Null Target property.");
|
||||
}
|
||||
|
||||
return Target.RotateTo(Rotation, Convert.ToUInt32(Duration), EasingHelper.GetEasing(Easing));
|
||||
}
|
||||
}
|
||||
|
||||
public class RelRotateToAnimation : AnimationBase
|
||||
{
|
||||
public static readonly BindableProperty RotationProperty =
|
||||
BindableProperty.Create(nameof(Rotation), typeof(double), typeof(RelRotateToAnimation), 0,
|
||||
BindingMode.TwoWay, null);
|
||||
|
||||
public double Rotation
|
||||
{
|
||||
get { return (double)GetValue(RotationProperty); }
|
||||
set { SetValue(RotationProperty, value); }
|
||||
}
|
||||
|
||||
protected override Task BeginAnimation()
|
||||
{
|
||||
if (Target == null)
|
||||
{
|
||||
throw new NullReferenceException("Null Target property.");
|
||||
}
|
||||
|
||||
return Target.RelRotateTo(Rotation, Convert.ToUInt32(Duration), EasingHelper.GetEasing(Easing));
|
||||
}
|
||||
}
|
||||
|
||||
public class RotateXToAnimation : AnimationBase
|
||||
{
|
||||
public static readonly BindableProperty RotationProperty =
|
||||
BindableProperty.Create(nameof(Rotation), typeof(double), typeof(RotateXToAnimation), 0,
|
||||
BindingMode.TwoWay, null);
|
||||
|
||||
public double Rotation
|
||||
{
|
||||
get { return (double)GetValue(RotationProperty); }
|
||||
set { SetValue(RotationProperty, value); }
|
||||
}
|
||||
|
||||
protected override Task BeginAnimation()
|
||||
{
|
||||
if (Target == null)
|
||||
{
|
||||
throw new NullReferenceException("Null Target property.");
|
||||
}
|
||||
|
||||
return Target.RotateXTo(Rotation, Convert.ToUInt32(Duration), EasingHelper.GetEasing(Easing));
|
||||
}
|
||||
}
|
||||
|
||||
public class RotateYToAnimation : AnimationBase
|
||||
{
|
||||
public static readonly BindableProperty RotationProperty =
|
||||
BindableProperty.Create(nameof(Rotation), typeof(double), typeof(RotateYToAnimation), 0,
|
||||
BindingMode.TwoWay, null);
|
||||
|
||||
public double Rotation
|
||||
{
|
||||
get { return (double)GetValue(RotationProperty); }
|
||||
set { SetValue(RotationProperty, value); }
|
||||
}
|
||||
|
||||
protected override Task BeginAnimation()
|
||||
{
|
||||
if (Target == null)
|
||||
{
|
||||
throw new NullReferenceException("Null Target property.");
|
||||
}
|
||||
|
||||
return Target.RotateYTo(Rotation, Convert.ToUInt32(Duration), EasingHelper.GetEasing(Easing));
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,52 @@
|
|||
using System;
|
||||
using System.Threading.Tasks;
|
||||
using Xamarin.Forms;
|
||||
|
||||
namespace FormsCommunityToolkit.Animations
|
||||
{
|
||||
public class ScaleToAnimation : AnimationBase
|
||||
{
|
||||
public static readonly BindableProperty ScaleProperty =
|
||||
BindableProperty.Create(nameof(Scale), typeof(double), typeof(ScaleToAnimation), 0,
|
||||
BindingMode.TwoWay, null);
|
||||
|
||||
public double Scale
|
||||
{
|
||||
get { return (double)GetValue(ScaleProperty); }
|
||||
set { SetValue(ScaleProperty, value); }
|
||||
}
|
||||
|
||||
protected override Task BeginAnimation()
|
||||
{
|
||||
if (Target == null)
|
||||
{
|
||||
throw new NullReferenceException("Null Target property.");
|
||||
}
|
||||
|
||||
return Target.ScaleTo(Scale, Convert.ToUInt32(Duration), EasingHelper.GetEasing(Easing));
|
||||
}
|
||||
}
|
||||
|
||||
public class RelScaleToAnimation : AnimationBase
|
||||
{
|
||||
public static readonly BindableProperty ScaleProperty =
|
||||
BindableProperty.Create(nameof(Scale), typeof(double), typeof(RelScaleToAnimation), 0,
|
||||
BindingMode.TwoWay, null);
|
||||
|
||||
public double Scale
|
||||
{
|
||||
get { return (double)GetValue(ScaleProperty); }
|
||||
set { SetValue(ScaleProperty, value); }
|
||||
}
|
||||
|
||||
protected override Task BeginAnimation()
|
||||
{
|
||||
if (Target == null)
|
||||
{
|
||||
throw new NullReferenceException("Null Target property.");
|
||||
}
|
||||
|
||||
return Target.RelScaleTo(Scale, Convert.ToUInt32(Duration), EasingHelper.GetEasing(Easing));
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,74 @@
|
|||
using System;
|
||||
using System.Threading.Tasks;
|
||||
using Xamarin.Forms;
|
||||
|
||||
namespace FormsCommunityToolkit.Animations
|
||||
{
|
||||
public class ShakeAnimation : AnimationBase
|
||||
{
|
||||
private const int Movement = 5;
|
||||
|
||||
protected override Task BeginAnimation()
|
||||
{
|
||||
if (Target == null)
|
||||
{
|
||||
throw new NullReferenceException("Null Target property.");
|
||||
}
|
||||
|
||||
return Task.Run(() =>
|
||||
{
|
||||
Device.BeginInvokeOnMainThread(() =>
|
||||
{
|
||||
Target.Animate("Shake", Shake(), 16, Convert.ToUInt32(Duration));
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
internal Animation Shake()
|
||||
{
|
||||
var animation = new Animation();
|
||||
|
||||
animation.WithConcurrent(
|
||||
(f) => Target.TranslationX = f,
|
||||
Target.TranslationX + Movement, Target.TranslationX,
|
||||
Xamarin.Forms.Easing.Linear, 0, 0.1);
|
||||
|
||||
animation.WithConcurrent(
|
||||
(f) => Target.TranslationX = f,
|
||||
Target.TranslationX - Movement, Target.TranslationX,
|
||||
Xamarin.Forms.Easing.Linear, 0.1, 0.2);
|
||||
|
||||
animation.WithConcurrent(
|
||||
(f) => Target.TranslationX = f,
|
||||
Target.TranslationX + Movement, Target.TranslationX,
|
||||
Xamarin.Forms.Easing.Linear, 0.2, 0.3);
|
||||
|
||||
animation.WithConcurrent(
|
||||
(f) => Target.TranslationX = f,
|
||||
Target.TranslationX - Movement, Target.TranslationX,
|
||||
Xamarin.Forms.Easing.Linear, 0.3, 0.4);
|
||||
|
||||
animation.WithConcurrent(
|
||||
(f) => Target.TranslationX = f,
|
||||
Target.TranslationX + Movement, Target.TranslationX,
|
||||
Xamarin.Forms.Easing.Linear, 0.4, 0.5);
|
||||
|
||||
animation.WithConcurrent(
|
||||
(f) => Target.TranslationX = f,
|
||||
Target.TranslationX - Movement, Target.TranslationX,
|
||||
Xamarin.Forms.Easing.Linear, 0.5, 0.6);
|
||||
|
||||
animation.WithConcurrent(
|
||||
(f) => Target.TranslationX = f,
|
||||
Target.TranslationX + Movement, Target.TranslationX,
|
||||
Xamarin.Forms.Easing.Linear, 0.6, 0.7);
|
||||
|
||||
animation.WithConcurrent(
|
||||
(f) => Target.TranslationX = f,
|
||||
Target.TranslationX - Movement, Target.TranslationX,
|
||||
Xamarin.Forms.Easing.Linear, 0.7, 0.8);
|
||||
|
||||
return animation;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,36 @@
|
|||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
using Xamarin.Forms;
|
||||
|
||||
namespace FormsCommunityToolkit.Animations
|
||||
{
|
||||
[ContentProperty("Animations")]
|
||||
public class StoryBoard : AnimationBase
|
||||
{
|
||||
public StoryBoard()
|
||||
{
|
||||
Animations = new List<AnimationBase>();
|
||||
}
|
||||
|
||||
public StoryBoard(List<AnimationBase> animations)
|
||||
{
|
||||
Animations = animations;
|
||||
}
|
||||
|
||||
public List<AnimationBase> Animations
|
||||
{
|
||||
get;
|
||||
}
|
||||
|
||||
protected override async Task BeginAnimation()
|
||||
{
|
||||
foreach (var animation in Animations)
|
||||
{
|
||||
if (animation.Target == null)
|
||||
animation.Target = Target;
|
||||
|
||||
await animation.Begin();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,39 @@
|
|||
using System;
|
||||
using System.Threading.Tasks;
|
||||
using Xamarin.Forms;
|
||||
|
||||
namespace FormsCommunityToolkit.Animations
|
||||
{
|
||||
public class TranslateToAnimation : AnimationBase
|
||||
{
|
||||
public static readonly BindableProperty TranslateXProperty =
|
||||
BindableProperty.Create(nameof(TranslateX), typeof(double), typeof(TranslateToAnimation), default(double),
|
||||
BindingMode.TwoWay, null);
|
||||
|
||||
public double TranslateX
|
||||
{
|
||||
get { return (double)GetValue(TranslateXProperty); }
|
||||
set { SetValue(TranslateXProperty, value); }
|
||||
}
|
||||
|
||||
public static readonly BindableProperty TranslateYProperty =
|
||||
BindableProperty.Create(nameof(TranslateY), typeof(double), typeof(TranslateToAnimation), default(double),
|
||||
BindingMode.TwoWay, null);
|
||||
|
||||
public double TranslateY
|
||||
{
|
||||
get { return (double)GetValue(TranslateYProperty); }
|
||||
set { SetValue(TranslateYProperty, value); }
|
||||
}
|
||||
|
||||
protected override Task BeginAnimation()
|
||||
{
|
||||
if (Target == null)
|
||||
{
|
||||
throw new NullReferenceException("Null Target property.");
|
||||
}
|
||||
|
||||
return Target.TranslateTo(TranslateX, TranslateY, Convert.ToUInt32(Duration), EasingHelper.GetEasing(Easing));
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,64 @@
|
|||
using System;
|
||||
using System.Threading.Tasks;
|
||||
using Xamarin.Forms;
|
||||
|
||||
namespace FormsCommunityToolkit.Animations
|
||||
{
|
||||
public class TurnstileInAnimation : AnimationBase
|
||||
{
|
||||
protected override Task BeginAnimation()
|
||||
{
|
||||
if (Target == null)
|
||||
{
|
||||
throw new NullReferenceException("Null Target property.");
|
||||
}
|
||||
|
||||
return Task.Run(() =>
|
||||
{
|
||||
Device.BeginInvokeOnMainThread(() =>
|
||||
{
|
||||
Target.Animate("TurnstileIn", TurnstileIn(), 16, Convert.ToUInt32(Duration));
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
internal Animation TurnstileIn()
|
||||
{
|
||||
var animation = new Animation();
|
||||
|
||||
animation.WithConcurrent((f) => Target.RotationY = f, 75, 0, Xamarin.Forms.Easing.CubicOut);
|
||||
animation.WithConcurrent((f) => Target.Opacity = f, 0, 1, null, 0, 0.01);
|
||||
|
||||
return animation;
|
||||
}
|
||||
}
|
||||
|
||||
public class TurnstileOutAnimation : AnimationBase
|
||||
{
|
||||
protected override Task BeginAnimation()
|
||||
{
|
||||
if (Target == null)
|
||||
{
|
||||
throw new NullReferenceException("Null Target property.");
|
||||
}
|
||||
|
||||
return Task.Run(() =>
|
||||
{
|
||||
Device.BeginInvokeOnMainThread(() =>
|
||||
{
|
||||
Target.Animate("TurnstileOut", TurnstileOut(), 16, Convert.ToUInt32(Duration));
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
internal Animation TurnstileOut()
|
||||
{
|
||||
var animation = new Animation();
|
||||
|
||||
animation.WithConcurrent((f) => Target.RotationY = f, 0, -75, Xamarin.Forms.Easing.CubicOut);
|
||||
animation.WithConcurrent((f) => Target.Opacity = f, 1, 0, null, 0.9, 1);
|
||||
|
||||
return animation;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,46 @@
|
|||
using System.Threading.Tasks;
|
||||
using Xamarin.Forms;
|
||||
|
||||
namespace FormsCommunityToolkit.Animations
|
||||
{
|
||||
public class BeginAnimationBehavior : Behavior<VisualElement>
|
||||
{
|
||||
private static VisualElement associatedObject;
|
||||
|
||||
protected override async void OnAttachedTo(VisualElement bindable)
|
||||
{
|
||||
base.OnAttachedTo(bindable);
|
||||
associatedObject = bindable;
|
||||
|
||||
if (Animation == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (Animation.Target == null)
|
||||
{
|
||||
Animation.Target = associatedObject;
|
||||
}
|
||||
|
||||
var delay = Task.Delay(250);
|
||||
await Task.WhenAll(delay);
|
||||
await Animation.Begin();
|
||||
}
|
||||
|
||||
protected override void OnDetachingFrom(VisualElement bindable)
|
||||
{
|
||||
associatedObject = null;
|
||||
base.OnDetachingFrom(bindable);
|
||||
}
|
||||
|
||||
public static readonly BindableProperty AnimationProperty =
|
||||
BindableProperty.Create(nameof(Animation), typeof(AnimationBase), typeof(BeginAnimationBehavior), null,
|
||||
BindingMode.TwoWay, null);
|
||||
|
||||
public AnimationBase Animation
|
||||
{
|
||||
get { return (AnimationBase)GetValue(AnimationProperty); }
|
||||
set { SetValue(AnimationProperty, value); }
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,24 @@
|
|||
using System.Threading.Tasks;
|
||||
using Xamarin.Forms;
|
||||
|
||||
namespace FormsCommunityToolkit.Animations
|
||||
{
|
||||
public static class AnimationExtension
|
||||
{
|
||||
public static async Task<bool> Animate(this VisualElement visualElement, AnimationBase animation)
|
||||
{
|
||||
try
|
||||
{
|
||||
animation.Target = visualElement;
|
||||
|
||||
await animation.Begin();
|
||||
|
||||
return true;
|
||||
}
|
||||
catch
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,38 @@
|
|||
namespace FormsCommunityToolkit.Animations
|
||||
{
|
||||
using Xamarin.Forms;
|
||||
|
||||
public static class EasingHelper
|
||||
{
|
||||
public static Easing GetEasing(EasingType type)
|
||||
{
|
||||
switch(type)
|
||||
{
|
||||
case EasingType.BounceIn:
|
||||
return Easing.BounceIn;
|
||||
case EasingType.BounceOut:
|
||||
return Easing.BounceOut;
|
||||
case EasingType.CubicIn:
|
||||
return Easing.CubicIn;
|
||||
case EasingType.CubicInOut:
|
||||
return Easing.CubicInOut;
|
||||
case EasingType.CubicOut:
|
||||
return Easing.CubicOut;
|
||||
case EasingType.Linear:
|
||||
return Easing.Linear;
|
||||
case EasingType.SinIn:
|
||||
return Easing.SinIn;
|
||||
case EasingType.SinInOut:
|
||||
return Easing.SinInOut;
|
||||
case EasingType.SinOut:
|
||||
return Easing.SinOut;
|
||||
case EasingType.SpringIn:
|
||||
return Easing.SpringIn;
|
||||
case EasingType.SpringOut:
|
||||
return Easing.SpringOut;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,4 +1,4 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<packages>
|
||||
<package id="Xamarin.Forms" version="2.3.2.127" targetFramework="portable45-net45+win8+wp8+wpa81" />
|
||||
<package id="Xamarin.Forms" version="2.3.4.247" targetFramework="portable45-net45+win8+wp8+wpa81" />
|
||||
</packages>
|
Загрузка…
Ссылка в новой задаче