Skip to content
Merged
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
//
// CodableAnimation.swift
// OpenSwiftUICore
//
// Audited for 6.5.4
// Status: Complete

// MARK: - CodableAnimation

package struct CodableAnimation: ProtobufMessage {
package struct Tag: ProtobufTag {
package let rawValue: UInt

package init(rawValue: UInt) {
self.rawValue = rawValue
}
}

var base: Animation

init(base: Animation) {
self.base = base
}

package func encode(to encoder: inout ProtobufEncoder) throws {
let animation = base.codableValue as? any EncodableAnimation ?? DefaultAnimation()
try animation.encodeAnimation(to: &encoder)
}

package init(from decoder: inout ProtobufDecoder) throws {
var animation: Animation?
while let field = try decoder.nextField() {
switch field.tag {
case 1:
animation = Animation(try decoder.messageField(field) as BezierAnimation)
case 2:
animation = Animation(try decoder.messageField(field) as SpringAnimation)
case 3:
animation = Animation(try decoder.messageField(field) as FluidSpringAnimation)
case 4:
guard let existing = animation else { continue }
let delay = try decoder.doubleField(field)
animation = existing.modifier(DelayAnimation(delay: delay))
case 5:
let (repeatCount, autoreverses) = try decoder.messageField(field) { decoder in
try Animation.decodeRepeatMessage(from: &decoder)
}
guard let existing = animation else { continue }
animation = existing.modifier(
RepeatAnimation(repeatCount: repeatCount, autoreverses: autoreverses)
)
case 6:
guard let existing = animation else { continue }
let speed = try decoder.doubleField(field)
animation = existing.modifier(SpeedAnimation(speed: speed))
case 7:
animation = try decoder.messageField(field) { _ in
Animation(DefaultAnimation())
}
default:
try decoder.skipField(field)
}
}
guard let animation else {
throw ProtobufDecoder.DecodingError.failed
}
self.base = animation
}
}

// MARK: - Animation + decodeRepeatMessage

extension Animation {
package static func decodeRepeatMessage(
from decoder: inout ProtobufDecoder
) throws -> (Int?, Bool) {
var repeatCount: Int?
var autoreverses = false
while let field = try decoder.nextField() {
switch field.tag {
case 1:
repeatCount = try decoder.intField(field)
case 2:
autoreverses = try decoder.boolField(field)
default:
try decoder.skipField(field)
}
}
return (repeatCount, autoreverses)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
//
// CodableEffectAnimation.swift
// OpenSwiftUICore
//
// Audited for 6.5.4
// Status: Complete

// MARK: - CodableEffectAnimation

package struct CodableEffectAnimation: ProtobufMessage {
package struct Tag: ProtobufTag {
package let rawValue: UInt

package init(rawValue: UInt) {
self.rawValue = rawValue
}
}

var base: any _DisplayList_AnyEffectAnimation

init(base: any _DisplayList_AnyEffectAnimation) {
self.base = base
}

package func encode(to encoder: inout ProtobufEncoder) throws {
try base.encodeAnimation(to: &encoder)
}

package init(from decoder: inout ProtobufDecoder) throws {
var base: (any _DisplayList_AnyEffectAnimation)?
while let field = try decoder.nextField() {
switch field.tag {
case 1:
base = try decoder.messageField(field) as DisplayList.OffsetAnimation
case 2:
base = try decoder.messageField(field) as DisplayList.ScaleAnimation
case 3:
base = try decoder.messageField(field) as DisplayList.RotationAnimation
case 4:
base = try decoder.messageField(field) as DisplayList.OpacityAnimation
default:
try decoder.skipField(field)
}
}
guard let base else {
throw ProtobufDecoder.DecodingError.failed
}
self.base = base
}
}

// MARK: - _DisplayList_AnyEffectAnimation + Encode

extension _DisplayList_AnyEffectAnimation {
package func encodeAnimation(to encoder: inout ProtobufEncoder) throws {
if let leafTag = Self.leafProtobufTag {
try encoder.messageField(leafTag.rawValue, self)
} else {
try encode(to: &encoder)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -206,3 +206,66 @@ extension CustomAnimation {
false
}
}

// MARK: - EncodableAnimation

package protocol EncodableAnimation: ProtobufEncodableMessage {
static var leafProtobufTag: CodableAnimation.Tag? { get }
}

extension EncodableAnimation {
package func encodeAnimation(to encoder: inout ProtobufEncoder) throws {
if let leafTag = Self.leafProtobufTag {
try encoder.messageField(leafTag.rawValue, self)
} else {
try encode(to: &encoder)
}
}
}

extension BezierAnimation: EncodableAnimation {
package static var leafProtobufTag: CodableAnimation.Tag? {
.init(rawValue: 1)
}
}

extension SpringAnimation: EncodableAnimation {
package static var leafProtobufTag: CodableAnimation.Tag? {
.init(rawValue: 2)
}
}

extension FluidSpringAnimation: EncodableAnimation {
package static var leafProtobufTag: CodableAnimation.Tag? {
.init(rawValue: 3)
}
}

extension DelayAnimation: ProtobufEncodableMessage {
package func encode(to encoder: inout ProtobufEncoder) throws {
encoder.doubleField(4, delay)
}
}

extension RepeatAnimation: ProtobufEncodableMessage {
package func encode(to encoder: inout ProtobufEncoder) throws {
encoder.messageField(5) { encoder in
if let repeatCount {
encoder.intField(1, repeatCount, defaultValue: .min)
}
encoder.boolField(2, autoreverses)
}
}
}

extension SpeedAnimation: ProtobufEncodableMessage {
package func encode(to encoder: inout ProtobufEncoder) throws {
encoder.doubleField(6, speed)
}
}

extension DefaultAnimation: EncodableAnimation {
package static var leafProtobufTag: CodableAnimation.Tag? {
.init(rawValue: 7)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,8 @@ package struct CustomAnimationModifiedContent<Base, Modifier>: InternalCustomAni
}

extension CustomAnimationModifiedContent: EncodableAnimation {
package static var leafProtobufTag: CodableAnimation.Tag? { nil }

package func encode(to encoder: inout ProtobufEncoder) throws {
let encodableAnimation: any EncodableAnimation
if let encodableBase = base as? EncodableAnimation {
Expand Down Expand Up @@ -206,6 +208,8 @@ package struct InternalCustomAnimationModifiedContent<Base, Modifier>: InternalC
}

extension InternalCustomAnimationModifiedContent: EncodableAnimation {
package static var leafProtobufTag: CodableAnimation.Tag? { nil }

package func encode(to encoder: inout ProtobufEncoder) throws {
try _base.encode(to: &encoder)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,15 +47,15 @@ extension Animation {
}
}

struct DelayAnimation: CustomAnimationModifier {
var delay: TimeInterval
package struct DelayAnimation: CustomAnimationModifier {
package var delay: TimeInterval

@inline(__always)
private func delayedTime(_ time: TimeInterval) -> TimeInterval {
max(0, time - delay)
}

func animate<V, B>(
package func animate<V, B>(
base: B,
value: V,
time: TimeInterval,
Expand All @@ -68,7 +68,7 @@ struct DelayAnimation: CustomAnimationModifier {
)
}

func shouldMerge<V, B>(base: B, previous: DelayAnimation, previousBase: B, value: V, time: TimeInterval, context: inout AnimationContext<V>) -> Bool where V : VectorArithmetic, B : CustomAnimation {
package func shouldMerge<V, B>(base: B, previous: DelayAnimation, previousBase: B, value: V, time: TimeInterval, context: inout AnimationContext<V>) -> Bool where V : VectorArithmetic, B : CustomAnimation {
self == previous && base.shouldMerge(
previous: Animation(previousBase),
value: value,
Expand All @@ -77,7 +77,7 @@ struct DelayAnimation: CustomAnimationModifier {
)
}

func function(base: Animation.Function) -> Animation.Function {
package func function(base: Animation.Function) -> Animation.Function {
base
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
// Audited for 6.5.4
// Status: Complete

import Foundation
package import Foundation

// MARK: - View + speed Animation

Expand Down Expand Up @@ -83,15 +83,15 @@ extension Animation {

// MARK: - SpeedAnimation

struct SpeedAnimation: CustomAnimationModifier {
var speed: Double
package struct SpeedAnimation: CustomAnimationModifier {
package var speed: Double

@inline(__always)
private func speededTime(_ time: TimeInterval) -> TimeInterval {
time * speed
}

func animate<V, B>(
package func animate<V, B>(
base: B,
value: V,
time: TimeInterval,
Expand All @@ -104,7 +104,7 @@ struct SpeedAnimation: CustomAnimationModifier {
)
}

func shouldMerge<V, B>(
package func shouldMerge<V, B>(
base: B,
previous: SpeedAnimation,
previousBase: B,
Expand All @@ -120,7 +120,7 @@ struct SpeedAnimation: CustomAnimationModifier {
)
}

func function(base: Animation.Function) -> Animation.Function {
package func function(base: Animation.Function) -> Animation.Function {
.speed(speed, base)
}
}
Loading
Loading