-
-
Notifications
You must be signed in to change notification settings - Fork 3.5k
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
feat(animation): animations registry #7528
Conversation
ready |
call `removeFromRegistry();` after logic to fit all calls
@asturur regarding |
I have added current state to animation context so now it enables even more freedom of use |
I remembered you mentioned there's a need to cleanup |
No memory leaks should exist |
src/util/animate.js
Outdated
if (cancel) { | ||
return; | ||
} | ||
if (abort(current, valuePerc, timePerc)) { | ||
// remove this in 4.0 | ||
// remove this in 5.0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what about this??
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is good to remove because then the option to pause an animation comes to play.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
to support pausing of animations
There's something important! fabric.js/src/mixins/animation.mixin.js Line 154 in 7a406e8
There are a few more places such as this 865be3c, made it a single commit to easily revert |
broke a few other to maintain standard
@@ -1200,6 +1200,7 @@ | |||
*/ | |||
dispose: function () { | |||
var wrapper = this.wrapperEl; | |||
fabric.runningAnimations.cancelAll(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this needs to be executed per canvas.
EIther you pass in the canvas as argument and cancelAll becomes a cancelAll by canvas, or in an application with 2 canvases this would stop everything.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point.
When an objects animates does it have to be attached to a canvas? I guess not. So I'm not sure how to do what you suggest.
I can add a canvas property to the animation context object but what if there's no canvas set to the object??
Or maybe we should iterate over all running animations and check at that moment who is attached to the canvas arg and cancel that?
@@ -13,8 +13,7 @@ fabric.util.object.extend(fabric.StaticCanvas.prototype, /** @lends fabric.Stati | |||
* @param {Object} [callbacks] Callbacks object with optional "onComplete" and/or "onChange" properties | |||
* @param {Function} [callbacks.onComplete] Invoked on completion | |||
* @param {Function} [callbacks.onChange] Invoked on every step of animation | |||
* @return {fabric.Canvas} thisArg | |||
* @chainable |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe i m wrong, but is chainability still cool to do?
I understand it saves typing and as a result bits in the final bundle.
But i find having half methods chainable and half not is weird. Maybe is something we should drop in the rewrite.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree. Chaining is not worth the weirdness.
I say we drop it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And it is less breaking to have void return values that change (for future impl)
*/ | ||
_centerObject: function(object, center) { | ||
object.setPositionByOrigin(center, 'center', 'center'); | ||
object.setCoords(); | ||
this.renderOnAddRemove && this.requestRenderAll(); | ||
return this; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i would like to limit breaking changes in 5. Those are not part of the animation changes. What is the reason to remove chainability now?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's as you said. I thought it's too weird to have the animated version not chainable while the regular one is.
i m going to merge this and open a following PR to restore some extra changes that are for now not needed and complicate the release note of 5.0 |
BTW should I push a small commit for the delay option (#1719 ) or leave it for another PR? |
If you think it's better to release v5 without this that's alright. We'll make it part of v6. |
i m fine adding this now, i just don't want to remove the chaining operators that do not return animations. |
I don't see a start option. Or anything resembling a delay option |
Motivation
Currently the dev needs to implement something by themselves.
For example in react while developing when react does a hot reload or whatever and fabric is animating an error raises because the canvas is trying to access the context which react just disposed.
In general, knowing what is animating is crucial information for good UX/UI.
I think this should be handled by fabric.
gist
Exposed
fabric.runningAnimations
(is this a good name? is fabric the right level to hold this ref?It is an array containing the options object passed to
animate
and thecancel
function. This means that it can contain additional context if such is passed to animate allowing the dev freedom.Exposed the following methods:
cancelAll
, findersFor example we could pass the object/canvas as context, this will make it very simple to cancel relevant animations.
IMO It makes sense that an object holds a ref to all it's running animations and that it's
dispose
method should cancel them.What do you think?