Skip to content
This repository was archived by the owner on May 1, 2024. It is now read-only.

Conversation

@bijington
Copy link
Contributor

@bijington bijington commented Jul 21, 2021

Description of Change

This is very much a work in progress but it is here to show some progress on the pre-built animations along with a samples section.

Screen.Recording.2021-07-21.at.21.34.56.mov

Bugs Fixed

API Changes

Behavioral Changes

PR Checklist

  • Has a linked Issue, and the Issue has been approved
  • Has tests (if omitted, state reason in description)
  • Has samples (if omitted, state reason in description)
  • Rebased on top of main at time of PR
  • Changes adhere to coding standard

@bijington bijington mentioned this pull request Jul 21, 2021
6 tasks

namespace Xamarin.CommunityToolkit.Animations
{
public class TadaAnimation : AnimationBase
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If happy with the approach in TadaAnimationType this entire class and folder can disappear

Copy link
Contributor

@pictos pictos left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bijington sorry for the delay

Comment on lines 54 to 57
protected virtual Animation CreateAnimation(params View[] views)
{
return new Animation();
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shouldn't this be abstract?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes good spot!

return taskCompletionSource.Task;
}

protected override Animation CreateAnimation(params View[] views) => Create(RotationAngle, MinimumScale, MaximumScale, views);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here we have a situation. If you do something like

		public Test()
		{
			var tada = new TadaAnimationType();
			tada.IsRepeated = true;
			tada.MaximumScale = 1;
			var lbl = new Label();
			var entry = new Entry();

			// This works with more than one view
			var animation = tada.CreateAnimation(16, null, null, lbl, entry);
			animation.Commit();
			animation.Abort();

			// This just works with one view
			tada.Animate(lbl); // Task
		}

This can lead to confusion about which method should I call? Just Animate or CreateAnimation?
Also, if I call Animate I can't Abort it.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So, if we want to use the BehaviorAnimation API, we need to make those animations simpler and drop the CreateAnimation, Commit, and Abort methods, which works for me.

If you see that those methods, at least Commit, and Abort, we can :

  1. Try to add those methods in BehaviorAnimation API;
  2. Create another API, to hold those animations.

Just to point out, that these animations are more complex than the animations that we have, so makes sense to be another implementation if the existing one doesn't fit well.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I completely agree on the confusion this creates. What do you think to keeping the BehaviorAnimation support but creating a second underlying type that BehaviorAnimation can use?

Currently we have AnimationBase, could this stay but then we create 2 abstract classes inheriting from this; SimpleAnimation and ComplexAnimation (or possibly AsyncAnimation and Animation). Then the BehaviorAnimation class could call them based on which is supplied.

Or an alternative could be to bend the complex to work in the existing approach by allowing a CancellationToken to be passed in for the aborting. This all feels a bit wrong considering non of the animations are actually async.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess there are good use cases for both async and non async still. I was going to suggest we could replace the async parts with implementing these directly in an on async manner: https://github.com/xamarin/Xamarin.Forms/blob/master/Xamarin.Forms.Core/ViewExtensions.cs but I am not sure that is a good idea now

# Conflicts:
#	src/CommunityToolkit/Xamarin.CommunityToolkit/Animations/AnimationBase.shared.cs
#	src/CommunityToolkit/Xamarin.CommunityToolkit/Behaviors/Animations/AnimationTypes/TadaAnimationType.shared.cs
@bijington bijington marked this pull request as ready for review August 12, 2021 21:23
@bijington
Copy link
Contributor Author

This PR now covers:

  • a new samples section in the XCT.Samples app for Animations that will allow a user to test out the animations
  • switched to only using a TPL based approach for invoking an animation (e.g. await new TadaAnimation().Animate(myView))
  • 2 animations; Tada and Rubber band as per https://animate.style
  • xml documentation for the new animation parts

I need to think on how to test this stuff and I am also keen to write up the docs for this stuff which I think should be fairly safe now given the approach?

@bijington
Copy link
Contributor Author

@pictos i have noticed that the other CI builds aren't running against this PR. I assume it is because it isn't going in to develop or main. Is this ok? I guess it will be run when we eventually merge to develop

@pictos
Copy link
Contributor

pictos commented Aug 14, 2021

@bijington you're correct. The CI will just run when we do a merge to main or develop

@bijington
Copy link
Contributor Author

@pictos what do you think to adding a CancelCommand to the new PreBuildAnimation base class to allow for a developer to cancel a repeating animation? I can't decide if it covers any extra scenarios or is cleaner than just setting IsRepeating = false.

@pictos
Copy link
Contributor

pictos commented Aug 19, 2021

@pictos what do you think to adding a CancelCommand to the new PreBuildAnimation base class to allow for a developer to cancel a repeating animation? I can't decide if it covers any extra scenarios or is cleaner than just setting IsRepeating = false.

I would say that use the IsRepeating will be cleaner. Because that BP can be used in triggers, Bindings, converters, etc

@bijington
Copy link
Contributor Author

@pictos is there anything you need from me in order to get this PR in? I need to write up some documentation but I assumed I could do this when we eventually merge in to develop?

@pictos pictos merged commit fbdaa90 into xamarin:pj/pre-built-animation Sep 15, 2021
@pictos
Copy link
Contributor

pictos commented Sep 15, 2021

@bijington thanks for you hard work, I'll update this branch and open the official PR ASAP.

@bijington
Copy link
Contributor Author

@bijington thanks for you hard work, I'll update this branch and open the official PR ASAP.

Awesome. Thank you for this

bijington added a commit that referenced this pull request Oct 28, 2021
* Initial attempt at an Animations sample section

* Move all responsibility to AnimationTypes

* Code tidy up

* changed the null and empty verification to be more performant

* Inverted `if` to make the code more readable

* An attempt at async with cancellation

* Remove the need for Task.Delay

* Removed the Type suffix

* Code tidy up and xml docs

Co-authored-by: Pedro Jesus <pedrojesus.cefet@gmail.com>
TheCodeTraveler added a commit that referenced this pull request Nov 2, 2021
* Add tada animation (#1468)

* Base class implementation for pre-built animations

* TADA! Added the first animation

* Max and Min scales for Tada

* Added the RubberBand animation

Co-authored-by: Pedro Jesus <pedrojesus.cefet@gmail.com>

* Feature/animation samples (#1527)

* Initial attempt at an Animations sample section

* Move all responsibility to AnimationTypes

* Code tidy up

* changed the null and empty verification to be more performant

* Inverted `if` to make the code more readable

* An attempt at async with cancellation

* Remove the need for Task.Delay

* Removed the Type suffix

* Code tidy up and xml docs

Co-authored-by: Pedro Jesus <pedrojesus.cefet@gmail.com>

* Consolidate AnimationViewModel, Remove Unnecessary Nullables

* TaskExtensions tidy up

* AnimationWrapper tidy up

Remove default parameters

* Rename to CompoundAnimationBase

* Unit tests added around animations

* Reversed the >= check to keep the constant on the right

* Switched to TimeSpan

* Disabled/removed inconsistent tests

* No longer share a ticker instance

* Clear PlatformServices after each animation test

* Code tidy up

* Remove the inconsistent asserts

* Further test ticker changes

- only use AsyncTicker when really needed.
- extra protection around enabling
- set and clear default ticker before/after each test

* Add Missing Asserts

* Update Unit Test NuGet Packages

* Update for Nullable

Co-authored-by: Shaun Lawrence <shaunrlawrence@gmail.com>
Co-authored-by: Brandon Minnick <13558917+brminnick@users.noreply.github.com>
Co-authored-by: Gerald Versluis <gerald.versluis@microsoft.com>
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants