Permalink
Browse files

Fixed animating single shadow properties

  • Loading branch information...
nvh committed Sep 18, 2017
1 parent 7f67e44 commit f14b32fdf7eb84ce076adf72fdb9fc2a67c6c025
Showing with 26 additions and 4 deletions.
  1. +7 −4 framer/Animation.coffee
  2. +19 −0 test/tests/LayerAnimationTest.coffee
View
@@ -79,7 +79,7 @@ class exports.Animation extends BaseClass
unless layer instanceof _Layer
throw Error("Animation: missing layer")
@properties = Animation.filterAnimatableProperties(properties)
@properties = Animation.filterAnimatableProperties(properties, layer)
if properties.origin
console.warn "Animation.origin: please use layer.originX and layer.originY"
@@ -351,7 +351,7 @@ class exports.Animation extends BaseClass
_updateShadows: (key, value) =>
result = []
for shadow, index in @_stateB[key]
if shadow is @_stateA[key][index]
if not shadow? and not @_stateA[key][index]?
continue
if shadow? and @_stateA[key][index]?
result[index] = @_interpolateNumericObjectValues(["x", "y", "blur", "spread"], @_stateA[key][index], shadow, value, false)
@@ -398,7 +398,7 @@ class exports.Animation extends BaseClass
@isAnimatableKey = (k) ->
k in ["gradient", "borderWidth", "borderRadius", "template", "shadows"]
@filterAnimatableProperties = (properties) ->
@filterAnimatableProperties = (properties, layer) ->
# Function to filter only animatable properties out of a given set
animatableProperties = {}
@@ -422,8 +422,11 @@ class exports.Animation extends BaseClass
else if @isAnimatableKey(k)
animatableProperties[k] = v
else if matches = k.match(/^shadow([1-9])$/)
animatableProperties.shadows ?= []
animatableProperties.shadows ?= _.clone(layer.shadows) ? []
shadowIndex = parseInt(matches[1]) - 1
if animatableProperties.shadows[shadowIndex]?
_.defaults v, animatableProperties.shadows[shadowIndex]
# else
animatableProperties.shadows[shadowIndex] = v
return animatableProperties
@@ -250,6 +250,25 @@ describe "LayerAnimation", ->
equalShadows(shadow, template.shadows[index]).should.be.true
done()
it "should keep other shadows intact when animating one shadow", (done) ->
layer = new Layer
shadows: template.shadows
a = layer.animate
shadow3:
blur: 200
a.onAnimationEnd ->
layer.shadows.length.should.eql template.shadows.length
layer.shadows.map (shadow, index) ->
if index is 2
shadow.x.should.equal template.shadows[index].x
shadow.y.should.equal template.shadows[index].y
shadow.type.should.equal template.shadows[index].type
Color.equal(shadow.color, template.shadows[index].color).should.be.true
shadow.blur.should.equal 200
else
equalShadows(shadow, template.shadows[index]).should.be.true
done()
describe "by setting shadow array", ->
it "should work when starting with no shadows", (done) ->
layer = new Layer

0 comments on commit f14b32f

Please sign in to comment.