Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Swift 5.6 support added #788

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions Source/animation/Animation.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,34 +20,34 @@ public class Animation {
}

public func state() -> AnimationState {
return .initial
.initial
}

public func easing(_ easing: Easing) -> Animation {
return self
self
}

public func delay(_ delay: Double) -> Animation {
return self
self
}

public func cycle(_ count: Double) -> Animation {
return self
self
}

public func cycle() -> Animation {
return self
self
}

public func reverse() -> Animation {
return self
self
}

public func autoreversed() -> Animation {
return self
self
}

@discardableResult public func onComplete(_: @escaping (() -> Void)) -> Animation {
return self
self
}
}
10 changes: 5 additions & 5 deletions Source/animation/AnimationImpl.swift
Original file line number Diff line number Diff line change
Expand Up @@ -136,10 +136,10 @@ class BasicAnimation: Animation {
}

override open func reverse() -> Animation {
return self
self
}

func getDuration() -> Double { return 0 }
func getDuration() -> Double { 0 }
}

// MARK: - Hashable
Expand All @@ -150,14 +150,14 @@ extension BasicAnimation: Hashable {
}

public static func == (lhs: BasicAnimation, rhs: BasicAnimation) -> Bool {
return lhs.ID == rhs.ID
lhs.ID == rhs.ID
}
}

// MARK: - Activity
extension BasicAnimation {
func isActive() -> Bool {
return progress > 0.0 && progress < 1.0
progress > 0.0 && progress < 1.0
}
}

Expand Down Expand Up @@ -284,6 +284,6 @@ open class AnimationDescription <T> {
}

open func t(_ duration: Double, delay: Double = 0.0) -> AnimationDescription<T> {
return AnimationDescription(valueFunc: valueFunc, duration: duration, delay: delay)
AnimationDescription(valueFunc: valueFunc, duration: duration, delay: delay)
}
}
2 changes: 1 addition & 1 deletion Source/animation/AnimationUtils.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import Foundation
class AbsoluteUtils {

class func absolutePosition(_ nodeRenderer: NodeRenderer?, _ context: AnimationContext) -> Transform {
return AbsoluteUtils.absoluteTransform(nodeRenderer, context, pos: nodeRenderer?.node.place ?? .identity)
AbsoluteUtils.absoluteTransform(nodeRenderer, context, pos: nodeRenderer?.node.place ?? .identity)
}

class func absoluteTransform(_ nodeRenderer: NodeRenderer?, _ context: AnimationContext, pos: Transform) -> Transform {
Expand Down
10 changes: 5 additions & 5 deletions Source/animation/Easing.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,26 +23,26 @@ open class Easing {
public static let elasticInOut: Easing = ElasticInOut()

public static func elasticOut(elasticity: Double = 10.0) -> ElasticOut {
return ElasticOut(elasticity: elasticity)
ElasticOut(elasticity: elasticity)
}
public static func elasticInOut(elasticity: Double = 10.0) -> ElasticInOut {
return ElasticInOut(elasticity: elasticity)
ElasticInOut(elasticity: elasticity)
}

open func progressFor(time: Double) -> Double {
return time
time
}
}

private class EaseIn: Easing {
override open func progressFor(time t: Double) -> Double {
return t * t
t * t
}
}

private class EaseOut: Easing {
override open func progressFor(time t: Double) -> Double {
return -(t * (t - 2))
-(t * (t - 2))
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,19 @@ import Foundation

// swiftlint:disable trailing_closure
public func >> (a: Double, b: Double) -> OpacityAnimationDescription {
return OpacityAnimationDescription(valueFunc: { t in
OpacityAnimationDescription(valueFunc: { t in
a.interpolate(b, progress: t)
})
}

public func >> (a: Transform, b: Transform) -> TransformAnimationDescription {
return TransformAnimationDescription(valueFunc: { t in
TransformAnimationDescription(valueFunc: { t in
a.interpolate(b, progress: t)
})
}

public func >> (a: Locus, b: Locus) -> MorphingAnimationDescription {
return MorphingAnimationDescription(valueFunc: { t in
MorphingAnimationDescription(valueFunc: { t in
// return a.interpolate(b, progress: t)
if t == 0.0 {
return a
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ public protocol ContentsInterpolation: Interpolable {

extension Array: ContentsInterpolation {
public func interpolate(_ endValue: Array, progress: Double) -> Array {
return self
self
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ public protocol DoubleInterpolation: Interpolable {

extension Double: DoubleInterpolation {
public func interpolate(_ endValue: Double, progress: Double) -> Double {
return self + (endValue - self) * progress
self + (endValue - self) * progress
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@ public protocol FillInterpolation: Interpolable {

extension Fill: FillInterpolation {
public func interpolate(_ endValue: Fill, progress: Double) -> Self {
return self
self
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ public protocol LocusInterpolation: Interpolable {

extension Locus: LocusInterpolation {
public func interpolate(_ endValue: Locus, progress: Double) -> Self {
return self
self
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@ public protocol ShapeInterpolation: Interpolable {

extension Shape: ShapeInterpolation {
public func interpolate(_ endValue: Shape, progress: Double) -> Self {
return self
self
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@ public protocol StrokeInterpolation: Interpolable {

extension Stroke: StrokeInterpolation {
public func interpolate(_ endValue: Stroke, progress: Double) -> Self {
return self
self
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ public protocol TransformInterpolation: Interpolable {

extension Transform: TransformInterpolation {
public func interpolate(_ endValue: Transform, progress: Double) -> Transform {
return Transform(m11: self.m11.interpolate(endValue.m11, progress: progress),
m12: self.m12.interpolate(endValue.m12, progress: progress),
m21: self.m21.interpolate(endValue.m21, progress: progress),
m22: self.m22.interpolate(endValue.m22, progress: progress),
dx: self.dx.interpolate(endValue.dx, progress: progress),
dy: self.dy.interpolate(endValue.dy, progress: progress))
Transform(m11: self.m11.interpolate(endValue.m11, progress: progress),
m12: self.m12.interpolate(endValue.m12, progress: progress),
m21: self.m21.interpolate(endValue.m21, progress: progress),
m22: self.m22.interpolate(endValue.m22, progress: progress),
dx: self.dx.interpolate(endValue.dx, progress: progress),
dy: self.dy.interpolate(endValue.dy, progress: progress))
}
}
2 changes: 1 addition & 1 deletion Source/animation/layer_animation/PathFunctions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import Foundation
typealias Func2D = ((_ t: Double) -> (Point))

func BezierFunc2D(_ t: Double, p0: Point, p1: Point, p2: Point, p3: Point) -> Point {
return Point(
Point(
x: polynom3(t, p0: p0.x, p1: p1.x, p2: p2.x, p3: p3.x),
y: polynom3(t, p0: p0.y, p1: p1.y, p2: p2.y, p3: p3.y))
}
Expand Down
6 changes: 3 additions & 3 deletions Source/animation/types/MorphingAnimation.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ class MorphingAnimation: AnimationImpl<Locus> {

convenience init(animatedNode: Shape, startValue: Locus, finalValue: Locus, animationDuration: Double, delay: Double = 0.0, autostart: Bool = false, fps: UInt = 30) {

let interpolationFunc = { (t: Double) -> Locus in
let interpolationFunc = { (_: Double) -> Locus in
finalValue
}

Expand Down Expand Up @@ -43,7 +43,7 @@ public extension AnimatableVariable where T: LocusInterpolation {
}

func animation(_ desc: MorphingAnimationDescription) -> Animation {
return MorphingAnimation(animatedNode: node as! Shape, valueFunc: desc.valueFunc, animationDuration: desc.duration, delay: desc.delay, autostart: false)
MorphingAnimation(animatedNode: node as! Shape, valueFunc: desc.valueFunc, animationDuration: desc.duration, delay: desc.delay, autostart: false)
}

func animate(from: Locus? = nil, to: Locus, during: Double = 1.0, delay: Double = 0.0) {
Expand All @@ -68,7 +68,7 @@ public extension AnimatableVariable where T: LocusInterpolation {
}

func animation(_ f: @escaping (Double) -> Locus, during: Double, delay: Double = 0.0) -> Animation {
return MorphingAnimation(animatedNode: node as! Shape, valueFunc: f, animationDuration: during, delay: delay)
MorphingAnimation(animatedNode: node as! Shape, valueFunc: f, animationDuration: during, delay: delay)
}

}
Expand Down
4 changes: 2 additions & 2 deletions Source/animation/types/OpacityAnimation.swift
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public extension AnimatableVariable where T: DoubleInterpolation {
}

func animation(_ desc: OpacityAnimationDescription) -> Animation {
return OpacityAnimation(animatedNode: node!, valueFunc: desc.valueFunc, animationDuration: desc.duration, delay: desc.delay, autostart: false)
OpacityAnimation(animatedNode: node!, valueFunc: desc.valueFunc, animationDuration: desc.duration, delay: desc.delay, autostart: false)
}

func animate(from: Double? = nil, to: Double, during: Double = 1.0, delay: Double = 0.0) {
Expand All @@ -72,7 +72,7 @@ public extension AnimatableVariable where T: DoubleInterpolation {
}

func animation(_ f: @escaping ((Double) -> Double), during: Double = 1.0, delay: Double = 0.0) -> Animation {
return OpacityAnimation(animatedNode: node!, valueFunc: f, animationDuration: during, delay: delay)
OpacityAnimation(animatedNode: node!, valueFunc: f, animationDuration: during, delay: delay)
}

}
11 changes: 5 additions & 6 deletions Source/animation/types/PathAnimation.swift
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,11 @@ public typealias PathAnimationDescription = AnimationDescription<Double>
open class StrokeAnimatableVariable: AnimatableVariable<Stroke?> {

public var end: StrokeSideVariable {
return StrokeSideVariable(parentVar: self, isEnd: true)
StrokeSideVariable(parentVar: self, isEnd: true)
}

public var start: StrokeSideVariable {
return StrokeSideVariable(parentVar: self, isEnd: false)
StrokeSideVariable(parentVar: self, isEnd: false)
}
}

Expand All @@ -80,7 +80,7 @@ open class StrokeSideVariable {
}

public func animation(_ desc: PathAnimationDescription) -> Animation {
return PathAnimation(animatedNode: node as! Shape, isEnd: isEnd, valueFunc: desc.valueFunc, animationDuration: desc.duration, delay: desc.delay, autostart: false)
PathAnimation(animatedNode: node as! Shape, isEnd: isEnd, valueFunc: desc.valueFunc, animationDuration: desc.duration, delay: desc.delay, autostart: false)
}

public func animate(from: Double? = nil, to: Double = 1, during: Double = 1.0, delay: Double = 0.0) {
Expand All @@ -92,13 +92,12 @@ open class StrokeSideVariable {
return self.animation((safeFrom >> to).t(during, delay: delay))
}
let origin = Double(0)
let factory = { () -> (Double) -> Double in
{ (t: Double) in origin.interpolate(to, progress: t) }
let factory = { () -> (Double) -> Double in { (t: Double) in origin.interpolate(to, progress: t) }
}
return PathAnimation(animatedNode: node as! Shape, isEnd: isEnd, factory: factory, animationDuration: during, delay: delay)
}

public func animation(_ f: @escaping ((Double) -> Double), during: Double = 1.0, delay: Double = 0.0) -> Animation {
return PathAnimation(animatedNode: node as! Shape, isEnd: isEnd, valueFunc: f, animationDuration: during, delay: delay)
PathAnimation(animatedNode: node as! Shape, isEnd: isEnd, valueFunc: f, animationDuration: during, delay: delay)
}
}
2 changes: 1 addition & 1 deletion Source/animation/types/ShapeAnimation.swift
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ public extension AnimatableVariable where T == Fill? {
finalShape.fill = to
_ = ShapeAnimation(animatedNode: shape, finalValue: finalShape, animationDuration: during, delay: delay, autostart: true)
}

func animation(from: Fill? = nil, to: Fill, during: Double = 1.0, delay: Double = 0.0) -> Animation {
let shape = node as! Shape
shape.fill = from ?? (shape.fill ?? Color.clear)
Expand Down
6 changes: 3 additions & 3 deletions Source/animation/types/TransformAnimation.swift
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public extension AnimatableVariable where T: TransformInterpolation {
}

func animation(_ desc: TransformAnimationDescription) -> Animation {
return TransformAnimation(animatedNode: node!, valueFunc: desc.valueFunc, animationDuration: desc.duration, delay: desc.delay, autostart: false)
TransformAnimation(animatedNode: node!, valueFunc: desc.valueFunc, animationDuration: desc.duration, delay: desc.delay, autostart: false)
}

func animate(from: Transform? = nil, to: Transform, during: Double = 1.0, delay: Double = 0.0) {
Expand Down Expand Up @@ -99,7 +99,7 @@ public extension AnimatableVariable where T: TransformInterpolation {
}

func animation(_ f: @escaping ((Double) -> Transform), during: Double = 1.0, delay: Double = 0.0) -> Animation {
return TransformAnimation(animatedNode: node!, valueFunc: f, animationDuration: during, delay: delay)
TransformAnimation(animatedNode: node!, valueFunc: f, animationDuration: during, delay: delay)
}

func animation(angle: Double, x: Double? = .none, y: Double? = .none, during: Double = 1.0, delay: Double = 0.0) -> Animation {
Expand Down Expand Up @@ -128,7 +128,7 @@ public extension AnimatableVariable where T: TransformInterpolation {

func animation(along path: Path, during: Double = 1.0, delay: Double = 0.0) -> Animation {

let factory = { () -> (Double) -> Transform in { (t: Double) in self.node?.place ?? .identity }
let factory = { () -> (Double) -> Transform in { (_: Double) in self.node?.place ?? .identity }
}
return TransformAnimation(animatedNode: self.node!, factory: factory, along: path, animationDuration: during, delay: delay)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,25 +159,25 @@ class AnimationUtils {

extension Node {

func isAnimating() -> Bool {
return !animations.filter { $0.state() == AnimationState.running }.isEmpty
var isAnimating: Bool {
!animations.filter { $0.state() == AnimationState.running }.isEmpty
}

func needsLayer() -> Bool {
return !animations.filter { $0.state() == AnimationState.running || $0.state() == AnimationState.initial }.isEmpty
var needsLayer: Bool {
!animations.filter { $0.state() == AnimationState.running || $0.state() == AnimationState.initial }.isEmpty
}
}

extension NodeRenderer {

func isAnimating() -> Bool {
return layer != nil
var isAnimating: Bool {
layer != nil
}

func freeLayer() {

let nodeRenderer = self
guard let layer = nodeRenderer.layer, !node.needsLayer() else {
guard let layer = nodeRenderer.layer, !node.needsLayer else {
return
}
nodeRenderer.layer = nil
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// TODO: Implement better hash

public func == (lhs: Node, rhs: Node) -> Bool {
return lhs === rhs
lhs === rhs
}

extension NodeRenderer: Hashable {
Expand All @@ -11,5 +11,5 @@ extension NodeRenderer: Hashable {
}

func == (lhs: NodeRenderer, rhs: NodeRenderer) -> Bool {
return lhs === rhs
lhs === rhs
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ extension Transform: Hashable {
}

public func == (lhs: Transform, rhs: Transform) -> Bool {
return lhs.m11 == rhs.m11 &&
lhs.m11 == rhs.m11 &&
lhs.m12 == rhs.m12 &&
lhs.m21 == rhs.m21 &&
lhs.m22 == rhs.m22 &&
Expand Down
Loading