-
-
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
Changes from all commits
c19b2c8
d9fb32d
3284141
6f88020
8b1d422
7e55962
5793ced
0466f25
809ff98
af7cdc3
456a360
9f4bbe6
2c5478f
16a4a40
e4aaa5b
f798f6b
d761584
d4c5606
d3595b6
3015a2d
54a4d0f
686f91f
a0f7e40
18f37ec
06c8243
7ec9c3a
d17e28f
0695460
7a406e8
865be3c
bbfd7b3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 commentThe reason will be displayed to describe this comment to others. Learn more. maybe i m wrong, but is chainability still cool to do? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I agree. Chaining is not worth the weirdness. There was a problem hiding this comment. Choose a reason for hiding this commentThe 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) |
||
* @return {fabric.AnimationContext} context | ||
*/ | ||
fxCenterObjectH: function (object, callbacks) { | ||
callbacks = callbacks || { }; | ||
|
@@ -24,7 +23,8 @@ fabric.util.object.extend(fabric.StaticCanvas.prototype, /** @lends fabric.Stati | |
onChange = callbacks.onChange || empty, | ||
_this = this; | ||
|
||
fabric.util.animate({ | ||
return fabric.util.animate({ | ||
target: this, | ||
startValue: object.left, | ||
endValue: this.getCenter().left, | ||
duration: this.FX_DURATION, | ||
|
@@ -38,8 +38,6 @@ fabric.util.object.extend(fabric.StaticCanvas.prototype, /** @lends fabric.Stati | |
onComplete(); | ||
} | ||
}); | ||
|
||
return this; | ||
}, | ||
|
||
/** | ||
|
@@ -48,8 +46,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 | ||
* @return {fabric.AnimationContext} context | ||
*/ | ||
fxCenterObjectV: function (object, callbacks) { | ||
callbacks = callbacks || { }; | ||
|
@@ -59,7 +56,8 @@ fabric.util.object.extend(fabric.StaticCanvas.prototype, /** @lends fabric.Stati | |
onChange = callbacks.onChange || empty, | ||
_this = this; | ||
|
||
fabric.util.animate({ | ||
return fabric.util.animate({ | ||
target: this, | ||
startValue: object.top, | ||
endValue: this.getCenter().top, | ||
duration: this.FX_DURATION, | ||
|
@@ -73,8 +71,6 @@ fabric.util.object.extend(fabric.StaticCanvas.prototype, /** @lends fabric.Stati | |
onComplete(); | ||
} | ||
}); | ||
|
||
return this; | ||
}, | ||
|
||
/** | ||
|
@@ -83,8 +79,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 | ||
* @return {fabric.AnimationContext} context | ||
*/ | ||
fxRemove: function (object, callbacks) { | ||
callbacks = callbacks || { }; | ||
|
@@ -94,7 +89,8 @@ fabric.util.object.extend(fabric.StaticCanvas.prototype, /** @lends fabric.Stati | |
onChange = callbacks.onChange || empty, | ||
_this = this; | ||
|
||
fabric.util.animate({ | ||
return fabric.util.animate({ | ||
target: this, | ||
startValue: object.opacity, | ||
endValue: 0, | ||
duration: this.FX_DURATION, | ||
|
@@ -108,8 +104,6 @@ fabric.util.object.extend(fabric.StaticCanvas.prototype, /** @lends fabric.Stati | |
onComplete(); | ||
} | ||
}); | ||
|
||
return this; | ||
} | ||
}); | ||
|
||
|
@@ -120,7 +114,7 @@ fabric.util.object.extend(fabric.Object.prototype, /** @lends fabric.Object.prot | |
* @param {Number|Object} value Value to animate property to (if string was given first) or options object | ||
* @return {fabric.Object} thisArg | ||
* @tutorial {@link http://fabricjs.com/fabric-intro-part-2#animation} | ||
* @chainable | ||
* @return {fabric.AnimationContext | fabric.AnimationContext[]} animation context (or an array if passed multiple properties) | ||
* | ||
* As object — multiple properties | ||
* | ||
|
@@ -133,22 +127,22 @@ fabric.util.object.extend(fabric.Object.prototype, /** @lends fabric.Object.prot | |
* object.animate('left', { duration: ... }); | ||
* | ||
*/ | ||
animate: function() { | ||
animate: function () { | ||
if (arguments[0] && typeof arguments[0] === 'object') { | ||
var propsToAnimate = [], prop, skipCallbacks; | ||
var propsToAnimate = [], prop, skipCallbacks, out = []; | ||
for (prop in arguments[0]) { | ||
propsToAnimate.push(prop); | ||
} | ||
for (var i = 0, len = propsToAnimate.length; i < len; i++) { | ||
prop = propsToAnimate[i]; | ||
skipCallbacks = i !== len - 1; | ||
this._animate(prop, arguments[0][prop], arguments[1], skipCallbacks); | ||
out.push(this._animate(prop, arguments[0][prop], arguments[1], skipCallbacks)); | ||
} | ||
return out; | ||
} | ||
else { | ||
this._animate.apply(this, arguments); | ||
return this._animate.apply(this, arguments); | ||
} | ||
return this; | ||
}, | ||
|
||
/** | ||
|
@@ -196,6 +190,7 @@ fabric.util.object.extend(fabric.Object.prototype, /** @lends fabric.Object.prot | |
} | ||
|
||
var _options = { | ||
target: this, | ||
startValue: options.from, | ||
endValue: to, | ||
byValue: options.by, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1038,7 +1038,6 @@ | |
/** | ||
* Centers object horizontally in the canvas | ||
* @param {fabric.Object} object Object to center horizontally | ||
* @return {fabric.Canvas} thisArg | ||
*/ | ||
centerObjectH: function (object) { | ||
return this._centerObject(object, new fabric.Point(this.getCenter().left, object.getCenterPoint().y)); | ||
|
@@ -1047,8 +1046,6 @@ | |
/** | ||
* Centers object vertically in the canvas | ||
* @param {fabric.Object} object Object to center vertically | ||
* @return {fabric.Canvas} thisArg | ||
* @chainable | ||
*/ | ||
centerObjectV: function (object) { | ||
return this._centerObject(object, new fabric.Point(object.getCenterPoint().x, this.getCenter().top)); | ||
|
@@ -1057,8 +1054,6 @@ | |
/** | ||
* Centers object vertically and horizontally in the canvas | ||
* @param {fabric.Object} object Object to center vertically and horizontally | ||
* @return {fabric.Canvas} thisArg | ||
* @chainable | ||
*/ | ||
centerObject: function(object) { | ||
var center = this.getCenter(); | ||
|
@@ -1069,8 +1064,6 @@ | |
/** | ||
* Centers object vertically and horizontally in the viewport | ||
* @param {fabric.Object} object Object to center vertically and horizontally | ||
* @return {fabric.Canvas} thisArg | ||
* @chainable | ||
*/ | ||
viewportCenterObject: function(object) { | ||
var vpCenter = this.getVpCenter(); | ||
|
@@ -1081,20 +1074,15 @@ | |
/** | ||
* Centers object horizontally in the viewport, object.top is unchanged | ||
* @param {fabric.Object} object Object to center vertically and horizontally | ||
* @return {fabric.Canvas} thisArg | ||
* @chainable | ||
*/ | ||
viewportCenterObjectH: function(object) { | ||
var vpCenter = this.getVpCenter(); | ||
this._centerObject(object, new fabric.Point(vpCenter.x, object.getCenterPoint().y)); | ||
return this; | ||
return this._centerObject(object, new fabric.Point(vpCenter.x, object.getCenterPoint().y)); | ||
}, | ||
|
||
/** | ||
* Centers object Vertically in the viewport, object.top is unchanged | ||
* @param {fabric.Object} object Object to center vertically and horizontally | ||
* @return {fabric.Canvas} thisArg | ||
* @chainable | ||
*/ | ||
viewportCenterObjectV: function(object) { | ||
var vpCenter = this.getVpCenter(); | ||
|
@@ -1105,7 +1093,6 @@ | |
/** | ||
* Calculate the point in canvas that correspond to the center of actual viewport. | ||
* @return {fabric.Point} vpCenter, viewport center | ||
* @chainable | ||
*/ | ||
getVpCenter: function() { | ||
var center = this.getCenter(), | ||
|
@@ -1117,14 +1104,11 @@ | |
* @private | ||
* @param {fabric.Object} object Object to center | ||
* @param {fabric.Point} center Center point | ||
* @return {fabric.Canvas} thisArg | ||
* @chainable | ||
*/ | ||
_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 commentThe 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 commentThe 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. |
||
}, | ||
|
||
/** | ||
|
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?