Permalink
Browse files

Change handling animations for the same property

If you fire multiple animations for the same property on the same layer, we now cancel the previous animation animating that property.
  • Loading branch information...
koenbok committed Oct 27, 2014
1 parent 8d4b1bd commit ecfa572bfe74ceaf5adc6f0e593219ee9029bf67
Showing with 15 additions and 10 deletions.
  1. +8 −6 framer/Animation.coffee
  2. +7 −2 test/tests/LayerAnimationTest.coffee
  3. +0 −2 test/tests/LayerTest.coffee
@@ -112,12 +112,14 @@ class exports.Animation extends EventEmitter
console.warn "Animation: nothing to animate, all properties are equal to what it is now"
return false
# See if another animation targeting the same layer is animating the same properties
for runningAnimation in @_target.animations()
for key in _.keys(runningAnimation._stateA)
if @_stateA.hasOwnProperty(key)
console.warn "Animation: property #{key} is already being animated for this layer by another animation, so we bail"
return false
for property, animation of @_target.animatingProperties()
console.log(@_target.animatingProperties())
if @_stateA.hasOwnProperty(property)
# We used to ignore animations that tried animation already animating properties
# console.warn "Animation: property #{property} is already being animated for this layer by another animation, so we bail"
# But after some consideration, we actually just stop the animation that is animation those properties for this one
animation.stop()
if @options.debug
console.log "Animation.start"
@@ -118,7 +118,7 @@ describe "LayerAnimation", ->
layer.x.should.be.within(10, 40)
done()
it "should not start animating the same property", ->
it "should cancel previous animation for the same property", ->
layer = new Layer()
@@ -134,8 +134,13 @@ describe "LayerAnimation", ->
curve: "linear"
time: 0.5
stopped = false
animationA.on "stop", -> stopped = true
animationA.start().should.equal true
animationB.start().should.equal false
animationB.start().should.equal true
stopped.should.equal true
describe "Context", ->
@@ -356,8 +356,6 @@ describe "Layer", ->
layer.on "click", "tap", handler
console.log layer._eventListeners
layer.emit "click"
layer.emit "tap"

0 comments on commit ecfa572

Please sign in to comment.