-
Notifications
You must be signed in to change notification settings - Fork 40
/
Copy pathAnimatable.swift
84 lines (70 loc) · 2.05 KB
/
Animatable.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
//
// Animatable.swift
// OpenSwiftUI
//
// Audited for RELEASE_2021
// Status: Blocked by Graph
// MARK: - Animatable
/// A type that describes how to animate a property of a view.
public protocol Animatable {
/// The type defining the data to animate.
associatedtype AnimatableData: VectorArithmetic
/// The data to animate.
var animatableData: AnimatableData { get set }
/// Replaces `value` with an animated version of the value, using
/// `inputs`.
static func _makeAnimatable(value: inout _GraphValue<Self>, inputs: _GraphInputs)
}
// MARK: - Animateble + Extension
extension Animatable {
public static func _makeAnimatable(value _: inout _GraphValue<Self>, inputs _: _GraphInputs) {
// TODO
}
}
extension Animatable where Self: VectorArithmetic {
public var animatableData: Self {
get { self }
set { self = newValue }
}
}
extension Animatable where AnimatableData == EmptyAnimatableData {
public var animatableData: EmptyAnimatableData {
@inlinable
get { EmptyAnimatableData() }
@inlinable
set {}
}
public static func _makeAnimatable(value _: inout _GraphValue<Self>, inputs _: _GraphInputs) {
// TODO
}
}
import Foundation
// MARK: - Animatable + CoreGraphics
extension CGPoint: Animatable {
public var animatableData: AnimatablePair<CGFloat, CGFloat> {
@inlinable
get { .init(x, y) }
@inlinable
set { (x, y) = newValue[] }
}
}
extension CGSize: Animatable {
public var animatableData: AnimatablePair<CGFloat, CGFloat> {
@inlinable
get { .init(width, height) }
@inlinable
set { (width, height) = newValue[] }
}
}
extension CGRect: Animatable {
public var animatableData: AnimatablePair<CGPoint.AnimatableData, CGSize.AnimatableData> {
@inlinable
get {
.init(origin.animatableData, size.animatableData)
}
@inlinable
set {
(origin.animatableData, size.animatableData) = newValue[]
}
}
}