Skip to content
Permalink
Browse files

LinearGradient -> Gradient

  • Loading branch information
eelco authored and Jonas Treub committed Jun 28, 2017
1 parent 0d40d08 commit ae0b628de7b77cf34a38b4a2558c6b459fa127e0
@@ -278,7 +278,7 @@ class exports.Animation extends BaseClass
for k, v of @_stateB
if Color.isColorObject(v) or Color.isColorObject(@_stateA[k])
@_valueUpdaters[k] = @_updateColorValue
else if LinearGradient.isLinearGradient(v) or LinearGradient.isLinearGradient(@_stateA[k])
else if Gradient.isGradient(v) or Gradient.isGradient(@_stateA[k])
@_valueUpdaters[k] = @_updateGradientValue
else
@_valueUpdaters[k] = @_updateNumberValue
@@ -294,9 +294,9 @@ class exports.Animation extends BaseClass
@_target[key] = Color.mix(@_stateA[key], @_stateB[key], value, false, @options.colorModel)

_updateGradientValue: (key, value) =>
gradientA = LinearGradient._asPlainObject(@_stateA[key])
gradientB = LinearGradient._asPlainObject(@_stateB[key])
@_target[key] = LinearGradient.mix(
gradientA = Gradient._asPlainObject(@_stateA[key])
gradientB = Gradient._asPlainObject(@_stateB[key])
@_target[key] = Gradient.mix(
_.defaults(gradientA, gradientB)
_.defaults(gradientB, gradientA)
value
@@ -307,7 +307,7 @@ class exports.Animation extends BaseClass
return _.pick(@layer, _.keys(@properties))

@isAnimatable = (v) ->
_.isNumber(v) or _.isFunction(v) or isRelativeProperty(v) or Color.isColorObject(v) or LinearGradient.isLinearGradient(v)
_.isNumber(v) or _.isFunction(v) or isRelativeProperty(v) or Color.isColorObject(v) or Gradient.isGradient(v)

@filterAnimatableProperties = (properties) ->
# Function to filter only animatable properties out of a given set
@@ -330,7 +330,7 @@ class exports.Animation extends BaseClass
animatableProperties[k] = v
else if Color.isValidColorProperty(k, v)
animatableProperties[k] = new Color(v)
else if k is "gradient" and not _.isEmpty(LinearGradient._asPlainObject(v))
else if k is "gradient" and not _.isEmpty(Gradient._asPlainObject(v))
animatableProperties[k] = v

return animatableProperties
@@ -6,7 +6,7 @@ Framer = {}
Framer._ = _
Framer.Utils = (require "./Utils")
Framer.Color = (require "./Color").Color
Framer.LinearGradient = (require "./LinearGradient").LinearGradient
Framer.Gradient = (require "./Gradient").Gradient
Framer.Layer = (require "./Layer").Layer
Framer._Layer = Framer.Layer # So it won't be overridden by MobileScrollFix
Framer.BackgroundLayer = (require "./BackgroundLayer").BackgroundLayer
@@ -2,7 +2,7 @@
{BaseClass} = require "./BaseClass"
{Color} = require "./Color"

class exports.LinearGradient extends BaseClass
class exports.Gradient extends BaseClass
constructor: (options = {}) ->
options.start ?= "black"
options.end ?= "white"
@@ -28,10 +28,10 @@ class exports.LinearGradient extends BaseClass
return "linear-gradient(#{this.angle}deg, #{this.start}, #{this.end})"

mix: (gradientB, fraction, model) =>
return LinearGradient.mix(@, gradientB, fraction, model)
return Gradient.mix(@, gradientB, fraction, model)

isEqual: (gradientB) ->
return LinearGradient.equal(@, gradientB)
return Gradient.equal(@, gradientB)

toInspect: =>
return "<#{@constructor.name} start:#{@start} end:#{@end} angle:#{@angle}>"
@@ -51,7 +51,7 @@ class exports.LinearGradient extends BaseClass
endAngle = normalizer(endAngle)
angle = startAngle + (endAngle - startAngle) * fraction

return new LinearGradient
return new Gradient
start: start
end: end
angle: angle
@@ -60,16 +60,16 @@ class exports.LinearGradient extends BaseClass
hue = Math.random() * 360
colorA = new Color h: hue
colorB = new Color h: hue + 40
return new LinearGradient
return new Gradient
start: colorA
end: colorB
angle: Math.random() * 360

@isLinearGradient: (gradient) -> return gradient instanceof LinearGradient
@isGradient: (gradient) -> return gradient instanceof Gradient

@equal: (gradientA, gradientB) ->
return false unless LinearGradient.isLinearGradient(gradientA)
return false unless LinearGradient.isLinearGradient(gradientB)
return false unless Gradient.isGradient(gradientA)
return false unless Gradient.isGradient(gradientB)
equalAngle = Math.abs(gradientA.angle - gradientB.angle) % 360 is 0
equalStart = Color.equal(gradientA.start, gradientB.start)
equalEnd = Color.equal(gradientA.end, gradientB.end)
@@ -8,7 +8,7 @@ Utils = require "./Utils"
{BaseClass} = require "./BaseClass"
{EventEmitter} = require "./EventEmitter"
{Color} = require "./Color"
{LinearGradient} = require "./LinearGradient"
{Gradient} = require "./Gradient"
{Matrix} = require "./Matrix"
{Animation} = require "./Animation"
{LayerStyle} = require "./LayerStyle"
@@ -890,7 +890,7 @@ class exports.Layer extends BaseClass
defaults = Defaults.getDefaults "Layer", {}
isBackgroundColorDefault = @backgroundColor?.isEqual(defaults.backgroundColor)

if LinearGradient.isLinearGradient(value)
if Gradient.isGradient(value)
@emit("change:gradient", value, currentValue)
@emit("change:image", value, currentValue)
@_setPropertyValue("image", value)
@@ -958,15 +958,15 @@ class exports.Layer extends BaseClass

@define "gradient",
get: ->
return @image if LinearGradient.isLinearGradient(@image)
return @image if Gradient.isGradient(@image)
return null
set: (value) ->
if LinearGradient.isLinearGradient(value)
if Gradient.isGradient(value)
@image = value
else
gradientOptions = LinearGradient._asPlainObject(value)
gradientOptions = Gradient._asPlainObject(value)
if not _.isEmpty(gradientOptions)
@image = new LinearGradient(gradientOptions)
@image = new Gradient(gradientOptions)

##############################################################
## HIERARCHY
@@ -62,7 +62,7 @@ class LayerStates
stateProperties[k] = new Color(v)
continue

if LinearGradient.isLinearGradient(v)
if Gradient.isGradient(v)
stateProperties[k] = v
continue

@@ -77,7 +77,7 @@ class LayerStates
return true if _.isBoolean(v)
return true if _.isString(v)
return true if Color.isColorObject(v)
return true if LinearGradient.isLinearGradient(v)
return true if Gradient.isGradient(v)
return true if v is null
return true if v?.constructor?.name is "Layer"
return false
@@ -15,19 +15,19 @@ class exports.SVGLayer extends Layer
get: ->
return @_gradient
set: (value) ->
if LinearGradient.isLinearGradient(value)
if Gradient.isGradient(value)
@_gradient = value
else
gradientOptions = LinearGradient._asPlainObject(value)
gradientOptions = Gradient._asPlainObject(value)
if not _.isEmpty(gradientOptions)
@_gradient = new LinearGradient(gradientOptions)
@_gradient = new Gradient(gradientOptions)
else
@_gradient = null
@updateGradientSVG()

updateGradientSVG: =>

isGradient = LinearGradient.isLinearGradient @_gradient
isGradient = Gradient.isGradient @_gradient

if not @_elementGradientSVG and isGradient
@_elementGradientSVG = document.createElementNS("http://www.w3.org/2000/svg", "svg")
@@ -46,7 +46,7 @@ require "./tests/TextLayerTest"
require "./tests/PageComponentTest"
require "./tests/VersionTest"
require "./tests/ColorTest"
require "./tests/LinearGradientTest"
require "./tests/GradientTest"
require "./tests/DeviceComponentTest"
require "./tests/SliderComponentTest"
require "./tests/RangeSliderComponentTest"
@@ -6,7 +6,7 @@ describe "Linear Gradient", ->
end = "orange"
angle = 20

gradient = new LinearGradient
gradient = new Gradient
start: start
end: end
angle: angle
@@ -17,25 +17,25 @@ describe "Linear Gradient", ->

it "should compare for equality", ->

gradient = new LinearGradient
gradient = new Gradient
angle: 360
start: "red"
equalGradient = new LinearGradient
equalGradient = new Gradient
angle: 0
start: "red"
LinearGradient.equal(gradient, equalGradient).should.be.true
Gradient.equal(gradient, equalGradient).should.be.true

unequalGradient = new LinearGradient
unequalGradient = new Gradient
angle: 90
unequalGradient.isEqual(gradient).should.be.false

it "should mix gradients", ->

colorA = "red"
colorB = "yellow"
gradientA = new LinearGradient
gradientA = new Gradient
start: colorA
gradientB = new LinearGradient
gradientB = new Gradient
start: colorB
angle: 90
mixed = gradientA.mix(gradientB)
@@ -44,9 +44,9 @@ describe "Linear Gradient", ->

it "should take the shortest route when animating to a new angle", ->

gradientA = new LinearGradient
gradientA = new Gradient
angle: 0
gradientB = new LinearGradient
gradientB = new Gradient
angle: 405
mixed = LinearGradient.mix(gradientA, gradientB, 1)
mixed = Gradient.mix(gradientA, gradientB, 1)
mixed.angle.should.equal 45

0 comments on commit ae0b628

Please sign in to comment.
You can’t perform that action at this time.