1
1
mirror of https://github.com/exyte/Macaw.git synced 2024-10-05 16:57:12 +03:00

Merge pull request #727 from f3dm76/fix/animation-api

Fix #713: Restrict animation api
This commit is contained in:
Yuri Strot 2020-08-06 18:06:57 +07:00 committed by GitHub
commit 578939b317
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -65,86 +65,39 @@ class ShapeAnimation: AnimationImpl<Shape> {
}
}
public extension AnimatableVariable {
func animate<T: Stroke>(from: T? = nil, to: T, during: Double = 1.0, delay: Double = 0.0) {
public extension AnimatableVariable where T == Stroke? {
func animate(from: Stroke? = nil, to: Stroke, during: Double = 1.0, delay: Double = 0.0) {
let shape = node as! Shape
var safeFrom = from
if safeFrom == nil {
if let shapeStroke = shape.stroke as? T {
safeFrom = shapeStroke
} else {
safeFrom = Stroke(width: 1.0) as? T
}
}
shape.stroke = safeFrom
shape.stroke = from ?? (shape.stroke ?? Stroke(width: 1.0))
let finalShape = SceneUtils.shapeCopy(from: shape)
finalShape.stroke = to
_ = ShapeAnimation(animatedNode: shape, finalValue: finalShape, animationDuration: during, delay: delay, autostart: true)
}
func animation<T: Stroke>(from: T? = nil, to: T, during: Double = 1.0, delay: Double = 0.0) -> Animation {
func animation(from: Stroke? = nil, to: Stroke, during: Double = 1.0, delay: Double = 0.0) -> Animation {
let shape = node as! Shape
var safeFrom = from
if safeFrom == nil {
if let shapeStroke = shape.stroke as? T {
safeFrom = shapeStroke
} else {
safeFrom = Stroke(width: 1.0) as? T
}
}
shape.stroke = safeFrom
shape.stroke = from ?? (shape.stroke ?? Stroke(width: 1.0))
let finalShape = SceneUtils.shapeCopy(from: shape)
finalShape.stroke = to
return ShapeAnimation(animatedNode: shape, finalValue: finalShape, animationDuration: during, delay: delay, autostart: false)
}
}
public extension AnimatableVariable where T == Fill? {
public extension AnimatableVariable {
func animate<T: Fill>(from: T? = nil, to: T, during: Double = 1.0, delay: Double = 0.0) {
func animate(from: Fill? = nil, to: Fill, during: Double = 1.0, delay: Double = 0.0) {
let shape = node as! Shape
var safeFrom = from
if safeFrom == nil {
if let shapeFill = shape.fill as? T {
safeFrom = shapeFill
} else {
safeFrom = Color.clear as? T
}
}
shape.fill = safeFrom
shape.fill = from ?? (shape.fill ?? Color.clear)
let finalShape = SceneUtils.shapeCopy(from: shape)
finalShape.fill = to
_ = ShapeAnimation(animatedNode: shape, finalValue: finalShape, animationDuration: during, delay: delay, autostart: true)
}
func animation<T: Fill>(from: T? = nil, to: T, during: Double = 1.0, delay: Double = 0.0) -> Animation {
func animation(from: Fill? = nil, to: Fill, during: Double = 1.0, delay: Double = 0.0) -> Animation {
let shape = node as! Shape
var safeFrom = from
if safeFrom == nil {
if let shapeFill = shape.fill as? T {
safeFrom = shapeFill
} else {
safeFrom = Color.clear as? T
}
}
shape.fill = safeFrom
shape.fill = from ?? (shape.fill ?? Color.clear)
let finalShape = SceneUtils.shapeCopy(from: shape)
finalShape.fill = to
return ShapeAnimation(animatedNode: shape, finalValue: finalShape, animationDuration: during, delay: delay, autostart: false)
}
}