Permalink
Browse files

Fix running animations

  • Loading branch information...
koenbok committed Sep 26, 2014
1 parent 1e64425 commit 82d933f2acf961dbc89c80711d66b70447955c18
Showing with 33 additions and 16 deletions.
  1. +16 −11 framer/Animation.coffee
  2. +5 −2 framer/Context.coffee
  3. +3 −3 framer/Layer.coffee
  4. +9 −0 test/tests/LayerAnimationTest.coffee
@@ -35,14 +35,14 @@ evaluateRelativeProperty = (target, k, v) ->
else
return +number
_runningAnimations = []
# _runningAnimations = []
# Todo: this would normally be BaseClass but the properties keyword
# is not compatible and causes problems.
class exports.Animation extends EventEmitter
@runningAnimations = ->
_runningAnimations
# @runningAnimations = ->
# _runningAnimations
constructor: (options={}) ->
@@ -78,11 +78,6 @@ class exports.Animation extends EventEmitter
if @options.layer is null
console.error "Animation: missing layer"
if @options.layer._animation
@options.layer._animation.stop()
@options.layer._animation = @
AnimatorClass = @_animatorClass()
if @options.debug
@@ -102,8 +97,12 @@ class exports.Animation extends EventEmitter
# Filter out the properties that are equal
@_stateB[k] = v if @_stateA[k] != v
if _.isEqual @_stateA, @_stateB
if _.isEqual(@_stateA, @_stateB)
console.warn "Nothing to animate"
return
# See if another animation targeting the same layer is animating the same properties
if @options.debug
console.log "Animation.start"
@@ -125,8 +124,13 @@ class exports.Animation extends EventEmitter
else
@_start()
stop: ->
@emit("stop")
stop: (emit=true)->
@options.layer._context._animationList = _.without(
@options.layer._context._animationList, @)
if emit
@emit("stop")
Framer.Loop.off("update", @_update)
# _runningAnimations = _.without _runningAnimations, @
@@ -148,6 +152,7 @@ class exports.Animation extends EventEmitter
@options.layer.emit(event, @)
_start: =>
@options.layer._context._animationList.push(@)
@emit("start")
Framer.Loop.on("update", @_update)
@@ -36,7 +36,12 @@ class exports.Context
@_delayTimers?.map (timer) -> window.clearTimeout(timer)
@_delayIntervals?.map (timer) -> window.clearInterval(timer)
if @_animationList
for animation in @_animationList
animation.stop(false)
@_layerList = []
@_animationList = []
@_delayTimers = []
@_delayIntervals = []
@@ -51,8 +56,6 @@ class exports.Context
element = document.createElement("div")
element.id = "FramerContextRoot-#{@_name}"
element.classList.add("framerContext")
# _.extend element.style, Config.rootBaseCSS
parentElement = @_parentLayer?._element
@@ -560,11 +560,11 @@ class exports.Layer extends BaseClass
animations: ->
# Current running animations on this layer
_.filter Animation.runningAnimations(), (a) =>
a.options.layer == @
_.filter @_context._animationList, (animation) =>
animation.options.layer == @
animateStop: ->
_.invoke @animations(), "stop"
_.invoke(@animations(), "stop")
##############################################################
## INDEX ORDERING
@@ -103,9 +103,18 @@ describe "LayerAnimation", ->
layer.x.should.be.within(10, 40)
done()
describe "Context", ->
it "should list running animations", ->
layer = new Layer()
animation = layer.animate
properties: {x: 100}
time: 0.5
layer.animations().should.contain(animation)
layer.animateStop()
layer.animations().should.not.contain(animation)
describe "Events", ->

0 comments on commit 82d933f

Please sign in to comment.