Skip to content

Commit

Permalink
Merge pull request #22 from p-x9/feature/animation
Browse files Browse the repository at this point in the history
CAAnimation
  • Loading branch information
p-x9 authored Apr 9, 2024
2 parents ba914d4 + f0bfdd4 commit f05643a
Show file tree
Hide file tree
Showing 33 changed files with 1,322 additions and 3 deletions.
146 changes: 146 additions & 0 deletions Example/json/anim.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
{
"class": "CAReplicatorLayer",
"layerModel": {
"sublayers": [
{
"layerModel": {
"position": [
100,
100
],
"bounds": [
[
0,
0
],
[
200,
200
]
],
"animations": {
"ripple": {
"class": "CAAnimationGroup",
"animationModel": {
"beginTime": 0,
"duration": 3,
"timeOffset": 0,
"autoreverses": false,
"fillMode": {
"rawValue": "removed"
},
"isRemovedOnCompletion": false,
"speed": 1,
"repeatDuration": 0,
"repeatCount": 3.4028235e+38,
"animations": [
{
"animationModel": {
"autoreverses": false,
"repeatDuration": 0,
"timeOffset": 0,
"fillMode": {
"rawValue": "forwards"
},
"isRemovedOnCompletion": false,
"fromValue": {
"type": "float",
"value": 0
},
"speed": 1,
"isAdditive": false,
"duration": 3,
"repeatCount": 0,
"isCumulative": false,
"toValue": {
"value": 1,
"type": "int"
},
"keyPath": "transform.scale.xy",
"beginTime": 0
},
"class": "CABasicAnimation"
},
{
"class": "CAKeyframeAnimation",
"animationModel": {
"repeatCount": 0,
"repeatDuration": 0,
"keyPath": "opacity",
"fillMode": {
"rawValue": "forwards"
},
"beginTime": 0,
"isCumulative": false,
"calculationMode": {
"rawValue": "linear"
},
"autoreverses": false,
"isRemovedOnCompletion": false,
"keyTimes": [
0,
0.5,
1
],
"values": [
{
"type": "float",
"value": 0.8
},
{
"type": "float",
"value": 0.4
},
{
"type": "float",
"value": 0
}
],
"isAdditive": false,
"speed": 1,
"timeOffset": 0,
"duration": 3
}
}
],
"timingFunction": "linear"
}
}
},
"backgroundColor": {
"code": "FF00FFFF"
},
"allowsEdgeAntialiasing": false,
"contentsFormat": {
"rawValue": "RGBA8"
},
"cornerRadius": 100,
"opacity": 0,
"allowsGroupOpacity": true
},
"class": "CALayer"
}
],
"instanceCount": 3,
"contentsFormat": {
"rawValue": "RGBA8"
},
"allowsEdgeAntialiasing": false,
"instanceDelay": 1,
"position": [
196.5,
426
],
"bounds": [
[
0,
0
],
[
200,
200
]
],
"allowsGroupOpacity": true
}
}
35 changes: 35 additions & 0 deletions Sources/SDCALayer/Extension/CAMediaTimingFunction+.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
//
// CAMediaTimingFunction+.swift
//
//
// Created by p-x9 on 2024/04/06.
//
//

import QuartzCore

extension CAMediaTimingFunction {
var controlPoints: [CGPoint] {
var controlPoints = [CGPoint]()
for index in 1..<3 {
let controlPoint = UnsafeMutablePointer<Float>.allocate(capacity: 2)
getControlPoint(at: Int(index), values: controlPoint)
let x: Float = controlPoint[0]
let y: Float = controlPoint[1]
controlPoint.deallocate()
controlPoints.append(CGPoint(x: CGFloat(x), y: CGFloat(y)))
}
return controlPoints
}

var name: CAMediaTimingFunctionName? {
switch description {
case "linear": .linear
case "easeIn": .easeIn
case "easeOut": .easeOut
case "easeInEaseOut": .easeInEaseOut
case "default": .default
default: nil
}
}
}
2 changes: 1 addition & 1 deletion Sources/SDCALayer/Extension/CGColor+.swift
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ extension CGColor {
}

private var rgbaComponents: [CGFloat] {
guard let colorSpace = CGColorSpace(name: CGColorSpace.extendedSRGB),
guard let colorSpace = CGColorSpace(name: CGColorSpace.sRGB),
let converted = self.converted(to: colorSpace, intent: .defaultIntent, options: nil),
let components = converted.components,
converted.numberOfComponents == 4 else {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
//
// CAAnimation+ICodable.swift
//
//
// Created by p-x9 on 2024/04/06.
//
//

import QuartzCore
import IndirectlyCodable

extension CAAnimation: IndirectlyCodable {
public typealias Model = JCAAnimation

public func codable() -> JCAAnimation? {
guard let animationClass = NSClassFromString(Self.codableTypeName) as? JCAAnimation.Type else {
return nil
}

return animationClass.init(with: self)
}

@objc
open class var codableTypeName: String {
String(reflecting: Model.self)
}
}

extension CAMediaTimingFillMode: RawIndirectlyCodable {
public typealias Model = JCAMediaTimingFillMode
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
//
// CAAnimationGroup+ICodable.swift
//
//
// Created by p-x9 on 2024/04/07.
//
//

import QuartzCore

extension CAAnimationGroup {
public typealias Model = JCAAnimationGroup

open override class var codableTypeName: String {
String(reflecting: Model.self)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
//
// CABasicAnimation+ICodable.swift
//
//
// Created by p-x9 on 2024/04/07.
//
//

import QuartzCore

extension CABasicAnimation {
public typealias Model = JCABasicAnimation

open override class var codableTypeName: String {
String(reflecting: Model.self)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
//
// CAKeyframeAnimation+ICodable.swift
//
//
// Created by p-x9 on 2024/04/07.
//
//

import QuartzCore

extension CAKeyframeAnimation {
public typealias Model = JCAKeyframeAnimation

open override class var codableTypeName: String {
String(reflecting: Model.self)
}
}

extension CAAnimationCalculationMode: RawIndirectlyCodable {
public typealias Model = JCAAnimationCalculationMode
}

extension CAAnimationRotationMode: RawIndirectlyCodable {
public typealias Model = JCAAnimationRotationMode
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
//
// CAPropertyAnimation+ICodable.swift
//
//
// Created by p-x9 on 2024/04/07.
//
//

import QuartzCore

extension CAPropertyAnimation {
public typealias Model = JCAPropertyAnimation

open override class var codableTypeName: String {
String(reflecting: Model.self)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
//
// CASpringAnimation+ICodable.swift
//
//
// Created by p-x9 on 2024/04/09.
//
//

import QuartzCore

extension CASpringAnimation {
public typealias Model = JCASpringAnimation

open override class var codableTypeName: String {
String(reflecting: Model.self)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
//
// CAMediaTimingFunction+ICodable.swift
//
//
// Created by p-x9 on 2024/04/07.
//
//

import QuartzCore
import IndirectlyCodable

extension CAMediaTimingFunction: IndirectlyCodable {
public typealias Model = JCAMediaTimingFunction

public func codable() -> Model? {
.init(with: self)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
//
// CAValueFunction+ICodable.swift
//
//
// Created by p-x9 on 2024/04/07.
//
//

import QuartzCore
import IndirectlyCodable

extension CAValueFunction: IndirectlyCodable {
public typealias Model = JCAValueFunction

public func codable() -> Model? {
.init(with: self)
}
}
Loading

0 comments on commit f05643a

Please sign in to comment.