Permalink
Browse files

Some more fixes to shadow animation

  • Loading branch information...
nvh committed Sep 28, 2017
1 parent 6e1d21b commit f057af6c5c2f7084d5b37467eeb52d609cd843a0
Showing with 28 additions and 20 deletions.
  1. +15 −9 framer/Animation.coffee
  2. +9 −3 framer/Layer.coffee
  3. +1 −1 framer/LayerStates.coffee
  4. +2 −1 framer/LayerStyle.coffee
  5. +1 −6 test/tests/LayerAnimationTest.coffee
View
@@ -349,18 +349,24 @@ class exports.Animation extends BaseClass
)
_updateShadows: (key, value) =>
if value is 1
@_target[key] = @_stateB[key]
return
result = []
for toShadow, index in @_stateB[key]
numShadows = Math.max(@_stateA[key]?.length ? 0, @_stateB[key]?.length ? 0)
for index in [0...numShadows]
fromShadow = @_stateA[key]?[index]
toShadow = @_stateB[key]?[index]
if not toShadow? and not fromShadow?
continue
fromShadow ?= _.defaults {color: null, type: toShadow.type}, Framer.Defaults.Shadow
if toShadow? and fromShadow?
result[index] = @_interpolateNumericObjectValues(["x", "y", "blur", "spread"], fromShadow, toShadow, value, false)
result[index].color = Color.mix(fromShadow.color, toShadow.color, value, false, @options.colorModel)
result[index].type = toShadow.type ? fromShadow.type
else
result[index] = toShadow
type = toShadow?.type ? fromShadow?.type ? Framer.Defaults.Shadow.type
fromShadow ?= _.defaults {color: null, type: type}, Framer.Defaults.Shadow
toShadow ?= _.defaults {color: null, type: type}, Framer.Defaults.Shadow
result[index] = @_interpolateNumericObjectValues(["x", "y", "blur", "spread"], fromShadow, toShadow, value, false)
result[index].color = Color.mix(fromShadow.color, toShadow.color, value, false, @options.colorModel)
result[index].type = type
@_target[key] = result
@@ -428,7 +434,7 @@ class exports.Animation extends BaseClass
shadowIndex = parseInt(matches[1]) - 1
if animatableProperties.shadows[shadowIndex]?
_.defaults v, animatableProperties.shadows[shadowIndex]
animatableProperties.shadows[shadowIndex] = _.defaults v, {color: null, type: null}, Framer.Defaults.Shadow
animatableProperties.shadows[shadowIndex] = v
return animatableProperties
toInspect: ->
View
@@ -141,7 +141,8 @@ parentOrContext = (layerOrContext) ->
proxiedShadowValue = (layer, value, index = 0) ->
v = _.defaults _.clone(value), Framer.Defaults.Shadow
v?.color = new Color(v.color)
if v.color isnt null
v?.color = new Color(v.color)
layerProxiedValue(v, layer, "shadow#{index+1}")
class exports.Layer extends BaseClass
@@ -354,6 +355,7 @@ class exports.Layer extends BaseClass
for i in [0..8]
do (i) =>
@define "shadow#{i+1}",
exportable: false
depends: ["shadowX", "shadowY", "shadowBlur", "shadowSpread", "shadowColor", "shadowType"]
get: ->
@shadows ?= []
@@ -379,7 +381,7 @@ class exports.Layer extends BaseClass
exportable: false
get: ->
return null if not @shadows? or @shadows.length is 0
@shadow1[shadowProp.toLowerCase()]
@shadows[0][shadowProp.toLowerCase()]
set: (value) ->
@updateShadowsProperty(shadowProp.toLowerCase(), value)
@@ -388,9 +390,13 @@ class exports.Layer extends BaseClass
get: ->
@_getPropertyValue("shadows")
set: (value) ->
value ?= []
shadows = []
for shadow, index in value
shadows.push proxiedShadowValue(@, shadow, index)
if shadow is null
shadows.push null
else
shadows.push proxiedShadowValue(@, shadow, index)
@_setPropertyValue("shadows", shadows)
@updateShadowStyle()
@@ -80,7 +80,7 @@ class LayerStates
return true if Gradient.isGradient(v)
return true if v is null
return true if v?.constructor?.name is "Layer"
return true if k is "template"
return true if k in ["template", "shadows"]
return false
#################################################################
View
@@ -59,6 +59,8 @@ getShadowStrings = (layer, types, createString) ->
shadow.type = "box"
if not (shadow.type in types) or (shadow.x is 0 and shadow.y is 0 and shadow.blur is 0 and shadow.spread is 0)
continue
if shadow.color is null
shadow.color = new Color(null)
shadowString = createString(shadow, layer.context.pixelMultiplier)
result.push(shadowString)
return result
@@ -226,7 +228,6 @@ exports.LayerStyle =
"#{insetString}#{shadow.x * pixelMultiplier}px #{shadow.y * pixelMultiplier}px #{shadow.blur * pixelMultiplier}px #{shadow.spread * pixelMultiplier}px #{shadow.color}"
)
return shadowStrings.join(", ")
textShadow: (layer) ->
@@ -280,12 +280,7 @@ describe "LayerAnimation", ->
a = layerA.animate
shadow1: null
a.onAnimationEnd ->
layerA.shadow1.x.should.equal 0
layerA.shadow1.y.should.equal 0
layerA.shadow1.blur.should.equal 0
layerA.shadow1.type.should.equal "inset"
transparentBlue = (new Color("blue")).alpha(0)
Color.equal(transparentBlue, layerA.shadow1.color).should.be.true
expect(layerA.shadows[0]).to.be.null
done()
it "should animate from null shadow nicely", (done) ->

0 comments on commit f057af6

Please sign in to comment.