Skip to content
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

[Proposal] Compound Animations #182

Open
1 of 10 tasks
bijington opened this issue Nov 3, 2021 · 4 comments
Open
1 of 10 tasks

[Proposal] Compound Animations #182

bijington opened this issue Nov 3, 2021 · 4 comments
Assignees
Labels
approved This Proposal has been approved and is ready to be added to the Toolkit champion A member of the .NET MAUI Toolkit core team has chosen to champion this feature help wanted This proposal has been approved and is ready to be implemented proposal A fully fleshed out proposal describing a new feature in syntactic and semantic detail

Comments

@bijington
Copy link
Contributor

bijington commented Nov 3, 2021

Compound Animations

  • Proposed
  • Prototype: Not Started
  • Implementation: Not Started
    • iOS Support
    • Android Support
    • macOS Support
    • Windows Support
  • Unit Tests: Not Started
  • Sample: Not Started
  • Documentation: Not Started

Summary

A comprehensive set of complex animations based on https://animate.style

Motivation

To provide a feature rich set of animations that users can just use.

Detailed Design

The implementation will extend the existing AnimationBehavior and AnimationBase functionality in order to reduce any additional API footprint increase.

CompoundAnimationBase.shared.cs

public abstract class CompoundAnimationBase : AnimationBase
{
  public static readonly BindableProperty IsRepeatedProperty;

  public bool IsRepeated { get; set; }

  // Extension from AnimationBase
  public override Task Animate(View? view);

  public Task Animate(CancellationToken? cancellationToken, params View[]? views);

  protected abstract Animation CreateAnimation(params View[] views);
}

RubberBandAnimation.shared.cs

public class RubberBandAnimation : CompoundAnimationBase
{
  protected override Animation CreateAnimation(params View[] views);
}

TadaAnimation.shared.cs

public class TadaAnimation : CompoundAnimationBase
{
  protected override Animation CreateAnimation(params View[] views);
}

Usage Syntax

XAML Usage

<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             xmlns:xct="http://xamarin.com/schemas/2020/toolkit"
             x:Class="MyLittleApp.MainPage">

  <Label>
    <Label.Behaviors>
      <xct:AnimationBehavior EventName="Clicked">
        <xct:AnimationBehavior.AnimationType>
          <xct:RubberBandAnimation
            Easing="{x:Static Easing.Linear}"
            Duration="100" 
            IsRepeating="{Binding IsBusy}"
          />
        </xct:AnimationBehavior.AnimationType>
      </xct:AnimationBehavior>
    </Label.Behaviors>
  </Label>

</ContentPage>

C# Usage

var cancelAnimationTokenSource = new CancellationTokenSource();

var animation = RubberBandAnimation
{
    Easing = Easing.Linear,
    Duration = 100
};

await animation.Animate(cancelAnimationTokenSource.Token, myView, myView2);

Drawbacks

Alternatives

Unresolved Questions

I have left this only covering publicly exposed parts of the toolkit. Is this fine?

Dependent on #35

@bijington bijington added new proposal A fully fleshed out proposal describing a new feature in syntactic and semantic detail labels Nov 3, 2021
@TheCodeTraveler
Copy link
Collaborator

TheCodeTraveler commented Nov 3, 2021

What are your thoughts on creating a new folder + namespace for animations? E.g. Something like this:

namespace CommunityToolkit.Maui.Animations;

In Xamarin.CommunityToolkit, all of the animation classes like CompoundAnimationBase.shared.cs, AnimationBase.shared.cs, RotateAnimation.shared.cs, etc., are in the Xamarin.CommunityToolkit.Behaviors namespace which is a bit strange. I think they ended up there because they are commonly used by the AnimationBehavior, but that Behavior is not required in order to use them, as demonstrated in the C# Usage example.

@bijington
Copy link
Contributor Author

@brminnick I really like that separation! As you have pointed out we don't need the behavior in order to use the animations. It would also reduce the noise if someone is looking for a behavior as it wouldn't include all the animations which aren't actual behaviors.

I guess the only slight annoyance in the XAML side would be that one would have to declare 2 namespaces in order to use the AnimationBehavior and the inner Animation.

@bijington bijington self-assigned this Nov 4, 2021
@TheCodeTraveler TheCodeTraveler added champion A member of the .NET MAUI Toolkit core team has chosen to champion this feature and removed new labels Nov 4, 2021
@ghost ghost added approved This Proposal has been approved and is ready to be added to the Toolkit help wanted This proposal has been approved and is ready to be implemented labels Nov 4, 2021
@TheCodeTraveler
Copy link
Collaborator

TheCodeTraveler commented Nov 9, 2021

FYI - BaseAnimation is added in the Animation Behaviors PR: #185

@bijington
Copy link
Contributor Author

Based on the discussion #203 we also discussed the idea of being able to compound existing animations together. Nothing has been fleshed out but it would be worth investigating whether we could provide the ability to combine the new XColorTo animations and potentially others in to this mechanism.

I think it would be nice to avoid having to write something like this:

var label = new Label();
await Task.WhenAll(
    label.TextColorTo(Colors.Red, 16, 1500, Easing.SinIn),
    label.BackgroundColorTo(Colors.Orange, 16, 1000, Easing.SpringIn));

And instead being able to combine the 2 together and commit as a single animation.

@TheCodeTraveler TheCodeTraveler added this to the v1.0.0 milestone Dec 6, 2021
@TheCodeTraveler TheCodeTraveler removed this from the v1.0.0 milestone Apr 15, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved This Proposal has been approved and is ready to be added to the Toolkit champion A member of the .NET MAUI Toolkit core team has chosen to champion this feature help wanted This proposal has been approved and is ready to be implemented proposal A fully fleshed out proposal describing a new feature in syntactic and semantic detail
Projects
None yet
Development

No branches or pull requests

2 participants