-
Notifications
You must be signed in to change notification settings - Fork 437
Initial work on adding remaining animations #1232
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
bijington
wants to merge
15
commits into
main
Choose a base branch
from
feature/add-animations
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
163ed96
Initial work on adding remaining animations
bijington ed99dee
Added FlipVertical
bijington 2560b69
Consistent behaviour when dealing with null
bijington 40723e4
Added samples for the new types of animation
bijington 3e18d3a
Merge branch 'main' into feature/add-animations
bijington 815b4fc
Merge branch 'main' into feature/add-animations
TheCodeTraveler 3306205
Merge branch 'main' into feature/add-animations
TheCodeTraveler ec6a24a
Merge branch 'main' into feature/add-animations
VladislavAntonyuk 1e12715
Merge branch 'main' into feature/add-animations
TheCodeTraveler fa62c5f
Merge branch 'main' into feature/add-animations
bijington 2ffb89a
Fix some unit tests
bijington 1e1bd6b
Merge branch 'main' into feature/add-animations
bijington 4ccb3b8
Merge branch 'main' into feature/add-animations
bijington 6590859
Merge branch 'main' into feature/add-animations
TheCodeTraveler 4a837eb
Update src/CommunityToolkit.Maui/Animations/ScaleAnimation.shared.cs
TheCodeTraveler File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
33 changes: 33 additions & 0 deletions
33
src/CommunityToolkit.Maui.UnitTests/Animations/BaseAnimationTests.cs
This file contains hidden or 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
using System.Diagnostics; | ||
using CommunityToolkit.Maui.Animations; | ||
using CommunityToolkit.Maui.UnitTests.Mocks; | ||
using FluentAssertions; | ||
using Xunit; | ||
|
||
namespace CommunityToolkit.Maui.UnitTests.Animations; | ||
|
||
public abstract class BaseAnimationTests<TAnimation> : BaseTest where TAnimation : BaseAnimation, new() | ||
{ | ||
protected virtual TAnimation CreateAnimation() => new(); | ||
|
||
[Fact] | ||
public async Task LengthShouldDictateFullAnimationLength() | ||
{ | ||
var animation = CreateAnimation(); | ||
|
||
Label label = new(); | ||
|
||
label.EnableAnimations(); | ||
|
||
var stopwatch = new Stopwatch(); | ||
stopwatch.Start(); | ||
await animation.Animate(label); | ||
stopwatch.Stop(); | ||
|
||
double allowance = (animation.Length * 0.1) + 50; | ||
|
||
stopwatch.ElapsedMilliseconds.Should().BeCloseTo(animation.Length, (uint)allowance); | ||
|
||
stopwatch.Reset(); | ||
} | ||
} |
This file contains hidden or 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
7 changes: 7 additions & 0 deletions
7
src/CommunityToolkit.Maui.UnitTests/Animations/FlipHorizontalAnimationTests.cs
This file contains hidden or 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
using CommunityToolkit.Maui.Animations; | ||
|
||
namespace CommunityToolkit.Maui.UnitTests.Animations; | ||
|
||
public class FlipHorizontalAnimationTests : BaseAnimationTests<FlipHorizontalAnimation> | ||
{ | ||
} |
7 changes: 7 additions & 0 deletions
7
src/CommunityToolkit.Maui.UnitTests/Animations/FlipVerticalAnimationTests.cs
This file contains hidden or 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
using CommunityToolkit.Maui.Animations; | ||
|
||
namespace CommunityToolkit.Maui.UnitTests.Animations; | ||
|
||
public class FlipVerticalAnimationTests : BaseAnimationTests<FlipVerticalAnimation> | ||
{ | ||
} |
7 changes: 7 additions & 0 deletions
7
src/CommunityToolkit.Maui.UnitTests/Animations/RotateAnimationTests.cs
This file contains hidden or 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
using CommunityToolkit.Maui.Animations; | ||
|
||
namespace CommunityToolkit.Maui.UnitTests.Animations; | ||
|
||
public class RotateAnimationTests : BaseAnimationTests<RotateAnimation> | ||
{ | ||
} |
7 changes: 7 additions & 0 deletions
7
src/CommunityToolkit.Maui.UnitTests/Animations/ScaleAnimationTests.cs
This file contains hidden or 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
using CommunityToolkit.Maui.Animations; | ||
|
||
namespace CommunityToolkit.Maui.UnitTests.Animations; | ||
|
||
public class ScaleAnimationTests : BaseAnimationTests<ScaleAnimation> | ||
{ | ||
} |
8 changes: 8 additions & 0 deletions
8
src/CommunityToolkit.Maui.UnitTests/Animations/ShakeAnimationTests.cs
This file contains hidden or 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
using CommunityToolkit.Maui.Animations; | ||
|
||
namespace CommunityToolkit.Maui.UnitTests.Animations; | ||
|
||
public class ShakeAnimationTests : BaseAnimationTests<ShakeAnimation> | ||
{ | ||
|
||
} |
This file contains hidden or 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
This file contains hidden or 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
31 changes: 31 additions & 0 deletions
31
src/CommunityToolkit.Maui/Animations/FlipHorizontalAnimation.shared.cs
This file contains hidden or 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
using Microsoft.Maui.Controls; | ||
|
||
namespace CommunityToolkit.Maui.Animations; | ||
|
||
/// <summary> | ||
/// Animation that will flip the supplied view horizontally. | ||
/// </summary> | ||
public class FlipHorizontalAnimation : RotateAnimation | ||
{ | ||
/// <summary> | ||
/// Initializes a new instance of <see cref="FlipHorizontalAnimation"/>. | ||
/// </summary> | ||
public FlipHorizontalAnimation() : base(600) | ||
{ | ||
|
||
} | ||
|
||
/// <inheritdoc /> | ||
protected override double DefaultRotation { get; set; } = 90; | ||
|
||
/// <inheritdoc /> | ||
public override async Task Animate(VisualElement view) | ||
{ | ||
ArgumentNullException.ThrowIfNull(view); | ||
|
||
var duration = Length / 2; | ||
|
||
await view.RotateYTo(Rotation, duration, Easing); | ||
await view.RotateYTo(0, duration, Easing); | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
src/CommunityToolkit.Maui/Animations/FlipVerticalAnimation.shared.cs
This file contains hidden or 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
namespace CommunityToolkit.Maui.Animations; | ||
|
||
/// <summary> | ||
/// Animation that will flip the supplied view vertically. | ||
/// </summary> | ||
public class FlipVerticalAnimation : RotateAnimation | ||
{ | ||
/// <summary> | ||
/// Initializes a new instance of <see cref="FlipVerticalAnimation"/>. | ||
/// </summary> | ||
public FlipVerticalAnimation() : base(600) | ||
{ | ||
|
||
} | ||
|
||
/// <inheritdoc /> | ||
protected override double DefaultRotation { get; set; } = 90; | ||
|
||
/// <inheritdoc /> | ||
public override async Task Animate(VisualElement view) | ||
{ | ||
ArgumentNullException.ThrowIfNull(view); | ||
|
||
var duration = Length / 2; | ||
|
||
await view.RotateXTo(Rotation, duration, Easing); | ||
await view.RotateXTo(0, duration, Easing); | ||
} | ||
} |
61 changes: 61 additions & 0 deletions
61
src/CommunityToolkit.Maui/Animations/RotateAnimation.shared.cs
This file contains hidden or 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
namespace CommunityToolkit.Maui.Animations; | ||
|
||
/// <summary> | ||
/// Animation that will rotate the supplied view by the specified <see cref="Rotation"/>. | ||
/// </summary> | ||
public class RotateAnimation : BaseAnimation | ||
{ | ||
/// <summary> | ||
/// Backing BindableProperty for the <see cref="Rotation"/> property. | ||
/// </summary> | ||
public static readonly BindableProperty RotationProperty = | ||
BindableProperty.Create( | ||
nameof(Rotation), | ||
typeof(double), | ||
typeof(RotateAnimation), | ||
180.0, | ||
BindingMode.TwoWay, | ||
defaultValueCreator: GetDefaultRotationProperty); | ||
|
||
/// <summary> | ||
/// Gets or sets the rotation used by the animation. | ||
/// </summary> | ||
public double Rotation | ||
VladislavAntonyuk marked this conversation as resolved.
Show resolved
Hide resolved
|
||
{ | ||
get => (double)GetValue(RotationProperty); | ||
set => SetValue(RotationProperty, value); | ||
} | ||
|
||
static object GetDefaultRotationProperty(BindableObject bindable) | ||
=> ((RotateAnimation)bindable).DefaultRotation; | ||
|
||
/// <summary> | ||
/// Initializes a new instance of <see cref="RotateAnimation"/>. | ||
/// </summary> | ||
public RotateAnimation() : base(200) | ||
{ | ||
} | ||
|
||
/// <summary> | ||
/// Initializes a new instance of <see cref="RotateAnimation"/>. | ||
/// </summary> | ||
/// <param name="defaultLength">The default length of the animation.</param> | ||
protected RotateAnimation(uint defaultLength) : base(defaultLength) | ||
{ | ||
} | ||
|
||
/// <summary> | ||
/// Gets or sets the default rotation used by the animation. | ||
/// </summary> | ||
protected virtual double DefaultRotation { get; set; } = 180.0; | ||
|
||
/// <inheritdoc /> | ||
public override async Task Animate(VisualElement view) | ||
{ | ||
ArgumentNullException.ThrowIfNull(view); | ||
|
||
await view.RotateTo(Rotation, Length, Easing); | ||
view.Rotation = 0; | ||
} | ||
} | ||
|
48 changes: 48 additions & 0 deletions
48
src/CommunityToolkit.Maui/Animations/ScaleAnimation.shared.cs
This file contains hidden or 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
namespace CommunityToolkit.Maui.Animations; | ||
|
||
/// <summary> | ||
/// Animation that will scale the supplied view to the specified <see cref="Scale"/> and then back down to its original scale. | ||
/// </summary> | ||
public class ScaleAnimation : BaseAnimation | ||
{ | ||
/// <summary> | ||
/// Backing BindableProperty for the <see cref="Scale"/> property. | ||
/// </summary> | ||
public static readonly BindableProperty ScaleProperty = | ||
BindableProperty.Create( | ||
nameof(Scale), | ||
typeof(double), | ||
typeof(ScaleAnimation), | ||
1.2, | ||
BindingMode.TwoWay); | ||
|
||
/// <summary> | ||
/// Gets or sets the scale to animate to before returning to the element's current scale. | ||
/// </summary> | ||
public double Scale | ||
{ | ||
get => (double)GetValue(ScaleProperty); | ||
set => SetValue(ScaleProperty, value); | ||
} | ||
|
||
/// <summary> | ||
/// Initializes a new instance of <see cref="ScaleAnimation"/>. | ||
/// </summary> | ||
public ScaleAnimation() : base(340) | ||
bijington marked this conversation as resolved.
Show resolved
Hide resolved
|
||
{ | ||
|
||
} | ||
|
||
/// <inheritdoc /> | ||
public override async Task Animate(VisualElement view) | ||
{ | ||
ArgumentNullException.ThrowIfNull(view); | ||
bijington marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
var originalScale = view.Scale; | ||
|
||
var duration = Length / 2; | ||
|
||
await view.ScaleTo(Scale, duration, Easing); | ||
await view.ScaleTo(originalScale, duration, Easing); | ||
} | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.