Permalink
Browse files

Abort animation start if the properties are already being animated

  • Loading branch information...
koenbok committed Sep 26, 2014
1 parent e13feb4 commit 9a04efe35ce0a32355e7b08f6039cf82ea9293aa
Showing with 29 additions and 3 deletions.
  1. +10 −3 framer/Animation.coffee
  2. +19 −0 test/tests/LayerAnimationTest.coffee
@@ -98,11 +98,16 @@ class exports.Animation extends EventEmitter
@_stateB[k] = v if @_stateA[k] != v
if _.isEqual(@_stateA, @_stateB)
console.warn "Nothing to animate"
return
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
if @options.debug
console.log "Animation.start"
@@ -124,6 +129,8 @@ class exports.Animation extends EventEmitter
else
@_start()
return true
stop: (emit=true)->
@options.layer._context._animationList = _.without(
@options.layer._context._animationList, @)
@@ -103,6 +103,25 @@ describe "LayerAnimation", ->
layer.x.should.be.within(10, 40)
done()
it "should not start animating the same property", ->
layer = new Layer()
animationA = new Animation
layer: layer
properties: {x:50}
curve: "linear"
time: 0.5
animationB = new Animation
layer: layer
properties: {x:50}
curve: "linear"
time: 0.5
animationA.start().should.equal true
animationB.start().should.equal false
describe "Context", ->
it "should list running animations", ->

0 comments on commit 9a04efe

Please sign in to comment.