Permalink
Browse files

Update use of animation arguments

  • Loading branch information...
nvh committed Jul 31, 2016
1 parent c8c0361 commit 49366206c3ffc8920d08ff8a40cef37fa4853293
Showing with 106 additions and 84 deletions.
  1. +20 −15 framer/Animation.coffee
  2. +5 −5 framer/Layer.coffee
  3. +1 −1 framer/LayerDraggable.coffee
  4. +80 −63 test/tests/LayerAnimationTest.coffee
View
@@ -56,17 +56,17 @@ class exports.Animation extends BaseClass
@_repeatCounter = @options.repeat
@define "isAnimating",
get: -> @ in @options.layer.context.animations
get: -> @ in @layer.context.animations
@define "looping",
get: -> @options.looping
set: (value) ->
@options?.looping = value
if @options?.looping and @options?.layer? and !@isAnimating
if @options?.looping and @layer? and !@isAnimating
@restart()
start: =>
if @options.layer is null
if @layer is null
console.error "Animation: missing layer"
AnimatorClass = @_animatorClass()
@@ -76,15 +76,15 @@ class exports.Animation extends BaseClass
@_animator = new AnimatorClass @options.curveOptions
@_target = @options.layer
@_target = @layer
@_stateA = @_currentState()
@_stateB = {}
for k, v of @options.properties
for k, v of @properties
# Evaluate function properties
if _.isFunction(v)
v = v(@options.layer, k)
v = v(@layer, k)
# Evaluate relative properties
else if isRelativeProperty(v)
@@ -148,16 +148,17 @@ class exports.Animation extends BaseClass
if @_delayTimer?
Framer.CurrentContext.removeTimer(@_delayTimer)
@_delayTimer = null
@options.layer.context.removeAnimation(@)
@layer.context.removeAnimation(@)
@emit("stop") if emit
Framer.Loop.off("update", @_update)
reverse: ->
# TODO: Add some tests
options = _.clone(@options)
options.properties = @_originalState
animation = new Animation options
properties = _.clone(@_originalState)
properties.options = _.clone(@options)
properties.layer = @layer
animation = new Animation properties
animation
reset: ->
@@ -168,7 +169,11 @@ class exports.Animation extends BaseClass
@reset()
@start()
copy: -> new Animation(_.clone(@options))
copy: ->
properties = _.clone(@properties)
properties.options = _.clone(@options)
properties.layer = @layer
new Animation(properties)
# A bunch of common aliases to minimize frustration
revert: -> @reverse()
@@ -178,7 +183,7 @@ class exports.Animation extends BaseClass
emit: (event) ->
super
# Also emit this to the layer with self as argument
@options.layer.emit(event, @)
@layer.emit(event, @)
animatingProperties: ->
_.keys(@_stateA)
@@ -191,7 +196,7 @@ class exports.Animation extends BaseClass
@emit("stop")
_start: =>
@options.layer.context.addAnimation(@)
@layer.context.addAnimation(@)
@emit("start")
Framer.Loop.on("update", @_update)
@@ -229,7 +234,7 @@ class exports.Animation extends BaseClass
@_target[key] = Color.mix(@_stateA[key], @_stateB[key], value, false, @options.colorModel)
_currentState: ->
return _.pick(@options.layer, _.keys(@options.properties))
return _.pick(@layer, _.keys(@properties))
_animatorClass: ->
@@ -303,7 +308,7 @@ class exports.Animation extends BaseClass
return animatableProperties
toInspect: ->
return "<#{@constructor.name} id:#{@id} isAnimating:#{@isAnimating} [#{_.keys(@options.properties)}]>"
return "<#{@constructor.name} id:#{@id} isAnimating:#{@isAnimating} [#{_.keys(@properties)}]>"
##############################################################
View
@@ -902,17 +902,15 @@ class exports.Layer extends BaseClass
@animateTo properties, options
animateTo: (properties,options={}) ->
if typeof properties == 'string'
stateName = properties
return @animateToState stateName, options
_.defaults(options,properties.options,@options)
delete properties.options
animatableProperties = Animation.filterAnimatableProperties(properties)
nonAnimatableProperties = _.omit(_.clone(properties),_.keys(animatableProperties))
options.properties = animatableProperties
options.layer = @
start = options.start
start ?= true
@@ -921,8 +919,10 @@ class exports.Layer extends BaseClass
if instant
options.animate = false
delete options.instant
parameters = animatableProperties
parameters.layer = @
animation = new Animation options
animation = new Animation parameters, options
animationFinished = =>
for k, v of nonAnimatableProperties
@[k] = v
@@ -953,7 +953,7 @@ class exports.Layer extends BaseClass
animations: ->
# Current running animations on this layer
_.filter @_context.animations, (animation) =>
animation.options.layer is @
animation.layer is @
animatingProperties: ->
@@ -145,7 +145,7 @@ class exports.LayerDraggable extends BaseClass
# Stop any animations influencing the position, but no others.
for animation in @layer.animations()
properties = animation.options.properties
properties = animation.properties
if properties.hasOwnProperty("x") or properties.hasOwnProperty("y")
animation.stop()
Oops, something went wrong.

0 comments on commit 4936620

Please sign in to comment.