Skip to content

Commit

Permalink
Abort animation start if the properties are already being animated
Browse files Browse the repository at this point in the history
  • Loading branch information
koenbok committed Sep 26, 2014
1 parent e13feb4 commit 9a04efe
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 3 deletions.
13 changes: 10 additions & 3 deletions framer/Animation.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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, @)
Expand Down
19 changes: 19 additions & 0 deletions test/tests/LayerAnimationTest.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -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", ->
Expand Down

0 comments on commit 9a04efe

Please sign in to comment.