Skip to content

Commit

Permalink
Some more fixes to shadow animation
Browse files Browse the repository at this point in the history
  • Loading branch information
nvh committed Sep 28, 2017
1 parent 6e1d21b commit f057af6
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 20 deletions.
24 changes: 15 additions & 9 deletions framer/Animation.coffee
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -349,18 +349,24 @@ class exports.Animation extends BaseClass
) )


_updateShadows: (key, value) => _updateShadows: (key, value) =>
if value is 1
@_target[key] = @_stateB[key]
return

result = [] 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] fromShadow = @_stateA[key]?[index]
toShadow = @_stateB[key]?[index]
if not toShadow? and not fromShadow? if not toShadow? and not fromShadow?
continue continue
fromShadow ?= _.defaults {color: null, type: toShadow.type}, Framer.Defaults.Shadow type = toShadow?.type ? fromShadow?.type ? Framer.Defaults.Shadow.type
if toShadow? and fromShadow? fromShadow ?= _.defaults {color: null, type: type}, Framer.Defaults.Shadow
result[index] = @_interpolateNumericObjectValues(["x", "y", "blur", "spread"], fromShadow, toShadow, value, false) toShadow ?= _.defaults {color: null, type: type}, Framer.Defaults.Shadow
result[index].color = Color.mix(fromShadow.color, toShadow.color, value, false, @options.colorModel) result[index] = @_interpolateNumericObjectValues(["x", "y", "blur", "spread"], fromShadow, toShadow, value, false)
result[index].type = toShadow.type ? fromShadow.type result[index].color = Color.mix(fromShadow.color, toShadow.color, value, false, @options.colorModel)
else result[index].type = type
result[index] = toShadow
@_target[key] = result @_target[key] = result




Expand Down Expand Up @@ -428,7 +434,7 @@ class exports.Animation extends BaseClass
shadowIndex = parseInt(matches[1]) - 1 shadowIndex = parseInt(matches[1]) - 1
if animatableProperties.shadows[shadowIndex]? if animatableProperties.shadows[shadowIndex]?
_.defaults v, 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 return animatableProperties


toInspect: -> toInspect: ->
Expand Down
12 changes: 9 additions & 3 deletions framer/Layer.coffee
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -141,7 +141,8 @@ parentOrContext = (layerOrContext) ->


proxiedShadowValue = (layer, value, index = 0) -> proxiedShadowValue = (layer, value, index = 0) ->
v = _.defaults _.clone(value), Framer.Defaults.Shadow 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}") layerProxiedValue(v, layer, "shadow#{index+1}")


class exports.Layer extends BaseClass class exports.Layer extends BaseClass
Expand Down Expand Up @@ -354,6 +355,7 @@ class exports.Layer extends BaseClass
for i in [0..8] for i in [0..8]
do (i) => do (i) =>
@define "shadow#{i+1}", @define "shadow#{i+1}",
exportable: false
depends: ["shadowX", "shadowY", "shadowBlur", "shadowSpread", "shadowColor", "shadowType"] depends: ["shadowX", "shadowY", "shadowBlur", "shadowSpread", "shadowColor", "shadowType"]
get: -> get: ->
@shadows ?= [] @shadows ?= []
Expand All @@ -379,7 +381,7 @@ class exports.Layer extends BaseClass
exportable: false exportable: false
get: -> get: ->
return null if not @shadows? or @shadows.length is 0 return null if not @shadows? or @shadows.length is 0
@shadow1[shadowProp.toLowerCase()] @shadows[0][shadowProp.toLowerCase()]
set: (value) -> set: (value) ->
@updateShadowsProperty(shadowProp.toLowerCase(), value) @updateShadowsProperty(shadowProp.toLowerCase(), value)


Expand All @@ -388,9 +390,13 @@ class exports.Layer extends BaseClass
get: -> get: ->
@_getPropertyValue("shadows") @_getPropertyValue("shadows")
set: (value) -> set: (value) ->
value ?= []
shadows = [] shadows = []
for shadow, index in value 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) @_setPropertyValue("shadows", shadows)
@updateShadowStyle() @updateShadowStyle()


Expand Down
2 changes: 1 addition & 1 deletion framer/LayerStates.coffee
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ class LayerStates
return true if Gradient.isGradient(v) return true if Gradient.isGradient(v)
return true if v is null return true if v is null
return true if v?.constructor?.name is "Layer" return true if v?.constructor?.name is "Layer"
return true if k is "template" return true if k in ["template", "shadows"]
return false return false


################################################################# #################################################################
Expand Down
3 changes: 2 additions & 1 deletion framer/LayerStyle.coffee
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ getShadowStrings = (layer, types, createString) ->
shadow.type = "box" 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) 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 continue
if shadow.color is null
shadow.color = new Color(null)
shadowString = createString(shadow, layer.context.pixelMultiplier) shadowString = createString(shadow, layer.context.pixelMultiplier)
result.push(shadowString) result.push(shadowString)
return result return result
Expand Down Expand Up @@ -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}" "#{insetString}#{shadow.x * pixelMultiplier}px #{shadow.y * pixelMultiplier}px #{shadow.blur * pixelMultiplier}px #{shadow.spread * pixelMultiplier}px #{shadow.color}"
) )



return shadowStrings.join(", ") return shadowStrings.join(", ")


textShadow: (layer) -> textShadow: (layer) ->
Expand Down
7 changes: 1 addition & 6 deletions test/tests/LayerAnimationTest.coffee
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -280,12 +280,7 @@ describe "LayerAnimation", ->
a = layerA.animate a = layerA.animate
shadow1: null shadow1: null
a.onAnimationEnd -> a.onAnimationEnd ->
layerA.shadow1.x.should.equal 0 expect(layerA.shadows[0]).to.be.null
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
done() done()


it "should animate from null shadow nicely", (done) -> it "should animate from null shadow nicely", (done) ->
Expand Down

0 comments on commit f057af6

Please sign in to comment.