Skip to content

Commit

Permalink
fix existential any
Browse files Browse the repository at this point in the history
  • Loading branch information
kitwtnb committed Jul 15, 2024
1 parent 12d01a8 commit 71225b8
Show file tree
Hide file tree
Showing 125 changed files with 399 additions and 399 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ final class CombinedShapeItem: ShapeItem {
super.init(name: name, type: .shape, hidden: false)
}

required init(from _: Decoder) throws {
required init(from _: any Decoder) throws {
fatalError("init(from:) has not been implemented")
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ extension CALayer {
/// Adds drop shadow animations from the given `DropShadowModel` to this layer
@nonobjc
func addDropShadowAnimations(
for dropShadowModel: DropShadowModel,
for dropShadowModel: any DropShadowModel,
context: LayerAnimationContext)
throws
{
Expand All @@ -96,7 +96,7 @@ extension CALayer {

// MARK: Private

private func addShadowOpacityAnimation(from model: DropShadowModel, context: LayerAnimationContext) throws {
private func addShadowOpacityAnimation(from model: any DropShadowModel, context: LayerAnimationContext) throws {
guard let opacityKeyframes = model._opacity else { return }

try addAnimation(
Expand All @@ -111,7 +111,7 @@ extension CALayer {
context: context)
}

private func addShadowColorAnimation(from model: DropShadowModel, context: LayerAnimationContext) throws {
private func addShadowColorAnimation(from model: any DropShadowModel, context: LayerAnimationContext) throws {
guard let shadowColorKeyframes = model._color else { return }

try addAnimation(
Expand All @@ -121,7 +121,7 @@ extension CALayer {
context: context)
}

private func addShadowRadiusAnimation(from model: DropShadowModel, context: LayerAnimationContext) throws {
private func addShadowRadiusAnimation(from model: any DropShadowModel, context: LayerAnimationContext) throws {
guard let shadowSizeKeyframes = model._radius else { return }

try addAnimation(
Expand All @@ -131,7 +131,7 @@ extension CALayer {
context: context)
}

private func addShadowOffsetAnimation(from model: DropShadowModel, context: LayerAnimationContext) throws {
private func addShadowOffsetAnimation(from model: any DropShadowModel, context: LayerAnimationContext) throws {
guard
let angleKeyframes = model._angle,
let distanceKeyframes = model._distance
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ extension GradientRenderLayer {
/// - The RGB components and alpha components can have different color stops / locations,
/// so have to be rendered in separate `CAGradientLayer`s.
func addGradientAnimations(
for gradient: GradientShapeItem,
for gradient: any GradientShapeItem,
type: GradientContentType,
context: LayerAnimationContext)
throws
Expand Down Expand Up @@ -86,7 +86,7 @@ extension GradientRenderLayer {
// MARK: Private

private func addLinearGradientAnimations(
for gradient: GradientShapeItem,
for gradient: any GradientShapeItem,
context: LayerAnimationContext)
throws
{
Expand All @@ -109,7 +109,7 @@ extension GradientRenderLayer {
context: context)
}

private func addRadialGradientAnimations(for gradient: GradientShapeItem, context: LayerAnimationContext) throws {
private func addRadialGradientAnimations(for gradient: any GradientShapeItem, context: LayerAnimationContext) throws {
type = .radial

let combinedKeyframes = Keyframes.combined(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ struct CustomizableProperty<ValueRepresentation> {
/// - `value` is the value for the current frame that should be converted,
/// as returned by `AnyValueProvider.typeErasedStorage`.
/// - `valueProvider` is the `AnyValueProvider` that returned the type-erased value.
let conversion: (_ value: Any, _ valueProvider: AnyValueProvider) -> ValueRepresentation?
let conversion: (_ value: Any, _ valueProvider: any AnyValueProvider) -> ValueRepresentation?
}

// MARK: - PropertyName
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ extension GradientStroke: OpacityAnimationModel { }
extension CALayer {
/// Adds the opacity animation from the given `OpacityAnimationModel` to this layer
@nonobjc
func addOpacityAnimation(for opacity: OpacityAnimationModel, context: LayerAnimationContext) throws {
func addOpacityAnimation(for opacity: any OpacityAnimationModel, context: LayerAnimationContext) throws {
try addAnimation(
for: .opacity,
keyframes: opacity.opacity,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@ protocol StrokeShapeItem: ShapeItem, OpacityAnimationModel {
var lineJoin: LineJoin { get }
var miterLimit: Double { get }
var dashPattern: [DashElement]? { get }
func copy(width: KeyframeGroup<LottieVector1D>) -> StrokeShapeItem
func copy(width: KeyframeGroup<LottieVector1D>) -> any StrokeShapeItem
}

// MARK: - Stroke + StrokeShapeItem

extension Stroke: StrokeShapeItem {
var strokeColor: KeyframeGroup<LottieColor>? { color }

func copy(width: KeyframeGroup<LottieVector1D>) -> StrokeShapeItem {
func copy(width: KeyframeGroup<LottieVector1D>) -> any StrokeShapeItem {
// Type-erase the copy from `Stroke` to `StrokeShapeItem`
let copy: Stroke = copy(width: width)
return copy
Expand All @@ -33,7 +33,7 @@ extension Stroke: StrokeShapeItem {
extension GradientStroke: StrokeShapeItem {
var strokeColor: KeyframeGroup<LottieColor>? { nil }

func copy(width: KeyframeGroup<LottieVector1D>) -> StrokeShapeItem {
func copy(width: KeyframeGroup<LottieVector1D>) -> any StrokeShapeItem {
// Type-erase the copy from `GradientStroke` to `StrokeShapeItem`
let copy: GradientStroke = copy(width: width)
return copy
Expand All @@ -45,7 +45,7 @@ extension GradientStroke: StrokeShapeItem {
extension CAShapeLayer {
/// Adds animations for properties related to the given `Stroke` object (`strokeColor`, `lineWidth`, etc)
@nonobjc
func addStrokeAnimations(for stroke: StrokeShapeItem, context: LayerAnimationContext) throws {
func addStrokeAnimations(for stroke: any StrokeShapeItem, context: LayerAnimationContext) throws {
lineJoin = stroke.lineJoin.caLineJoin
lineCap = stroke.lineCap.caLineCap
miterLimit = CGFloat(stroke.miterLimit)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ extension CALayer {
/// since child layers don't inherit the `opacity` of their parent.
@nonobjc
func addTransformAnimations(
for transformModel: TransformModel,
for transformModel: any TransformModel,
context: LayerAnimationContext)
throws
{
Expand Down Expand Up @@ -102,7 +102,7 @@ extension CALayer {

@nonobjc
private func addPositionAnimations(
from transformModel: TransformModel,
from transformModel: any TransformModel,
context: LayerAnimationContext)
throws
{
Expand Down Expand Up @@ -136,7 +136,7 @@ extension CALayer {

@nonobjc
private func addAnchorPointAnimation(
from transformModel: TransformModel,
from transformModel: any TransformModel,
context: LayerAnimationContext)
throws
{
Expand All @@ -161,7 +161,7 @@ extension CALayer {

@nonobjc
private func addScaleAnimations(
from transformModel: TransformModel,
from transformModel: any TransformModel,
context: LayerAnimationContext)
throws
{
Expand Down Expand Up @@ -189,7 +189,7 @@ extension CALayer {
}

private func addRotationAnimations(
from transformModel: TransformModel,
from transformModel: any TransformModel,
context: LayerAnimationContext)
throws
{
Expand Down Expand Up @@ -249,7 +249,7 @@ extension CALayer {
/// This is more expensive that animating each component separately, since
/// it may require manually interpolating the keyframes at each frame.
private func addCombinedTransformAnimation(
for transformModel: TransformModel,
for transformModel: any TransformModel,
context: LayerAnimationContext)
throws
{
Expand Down
20 changes: 10 additions & 10 deletions Sources/Private/CoreAnimation/CoreAnimationLayer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ final class CoreAnimationLayer: BaseAnimationLayer {
/// `CompatibilityTracker.Mode.abort`.
init(
animation: LottieAnimation,
imageProvider: AnimationImageProvider,
textProvider: AnimationKeypathTextProvider,
fontProvider: AnimationFontProvider,
imageProvider: any AnimationImageProvider,
textProvider: any AnimationKeypathTextProvider,
fontProvider: any AnimationFontProvider,
maskAnimationToBounds: Bool,
compatibilityTrackerMode: CompatibilityTracker.Mode,
logger: LottieLogger)
Expand Down Expand Up @@ -103,13 +103,13 @@ final class CoreAnimationLayer: BaseAnimationLayer {

/// The `AnimationImageProvider` that `ImageLayer`s use to retrieve images,
/// referenced by name in the animation json.
var imageProvider: AnimationImageProvider {
var imageProvider: any AnimationImageProvider {
didSet { reloadImages() }
}

/// The `AnimationKeypathTextProvider` that `TextLayer`'s use to retrieve texts,
/// that they should use to render their text context
var textProvider: AnimationKeypathTextProvider {
var textProvider: any AnimationKeypathTextProvider {
didSet {
// We need to rebuild the current animation after updating the text provider,
// since this is used in `TextLayer.setupAnimations(context:)`
Expand All @@ -119,7 +119,7 @@ final class CoreAnimationLayer: BaseAnimationLayer {

/// The `FontProvider` that `TextLayer`s use to retrieve the `CTFont`
/// that they should use to render their text content
var fontProvider: AnimationFontProvider {
var fontProvider: any AnimationFontProvider {
didSet { reloadFonts() }
}

Expand Down Expand Up @@ -286,7 +286,7 @@ final class CoreAnimationLayer: BaseAnimationLayer {

// Set up the new animations with the current `TimingConfiguration`
for animationLayer in sublayers ?? [] {
try (animationLayer as? AnimationLayer)?.setupAnimations(context: layerContext)
try (animationLayer as? (any AnimationLayer))?.setupAnimations(context: layerContext)
}
}

Expand Down Expand Up @@ -431,7 +431,7 @@ extension CoreAnimationLayer: RootAnimationLayer {
}

var _animationLayers: [CALayer] {
(sublayers ?? []).filter { $0 is AnimationLayer }
(sublayers ?? []).filter { $0 is any AnimationLayer }
}

func reloadImages() {
Expand Down Expand Up @@ -487,7 +487,7 @@ extension CoreAnimationLayer: RootAnimationLayer {
return allAnimationKeypaths
}

func setValueProvider(_ valueProvider: AnyValueProvider, keypath: AnimationKeypath) {
func setValueProvider(_ valueProvider: any AnyValueProvider, keypath: AnimationKeypath) {
valueProviderStore.setValueProvider(valueProvider, keypath: keypath)

// We need to rebuild the current animation after registering a value provider,
Expand Down Expand Up @@ -516,7 +516,7 @@ extension CoreAnimationLayer: RootAnimationLayer {
return nil
}

func animatorNodes(for _: AnimationKeypath) -> [AnimatorNode]? {
func animatorNodes(for _: AnimationKeypath) -> [any AnimatorNode]? {
logger.assertionFailure("""
The Core Animation rendering engine does not use `AnimatorNode`s
""")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ extension CALayer {
func fillBoundsOfSuperlayer() {
guard let superlayer else { return }

if let customLayerLayer = self as? CustomLayoutLayer {
if let customLayerLayer = self as? any CustomLayoutLayer {
customLayerLayer.layout(superlayerBounds: superlayer.bounds)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ extension KeyframeGroup {
/// support animating a given property (e.g. if Core Animation itself doesn't
/// support the property).
func exactlyOneKeyframe(
context: CompatibilityTrackerProviding,
context: any CompatibilityTrackerProviding,
description: String,
fileID _: StaticString = #fileID,
line _: UInt = #line)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ enum Keyframes {
/// `requiresManualInterpolation` determines whether the keyframes must be computed using `Keyframes.manuallyInterpolated`,
/// which interpolates the value at each frame, or if the keyframes can simply be combined.
private static func combined<CombinedResult>(
_ allGroups: [AnyKeyframeGroup],
_ allGroups: [any AnyKeyframeGroup],
requiresManualInterpolation: Bool,
makeCombinedResult: ([Any]) throws -> CombinedResult?)
rethrows
Expand Down Expand Up @@ -244,7 +244,7 @@ enum Keyframes {
}

private static func manuallyInterpolated<CombinedResult>(
_ allGroups: [AnyKeyframeGroup],
_ allGroups: [any AnyKeyframeGroup],
makeCombinedResult: ([Any]) throws -> CombinedResult?)
rethrows
-> KeyframeGroup<CombinedResult>
Expand Down
2 changes: 1 addition & 1 deletion Sources/Private/CoreAnimation/Layers/AnimationLayer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ struct LayerAnimationContext {
var currentKeypath: AnimationKeypath

/// The `AnimationKeypathTextProvider`
var textProvider: AnimationKeypathTextProvider
var textProvider: any AnimationKeypathTextProvider

/// Records the given animation keypath so it can be logged or collected into a list
/// - Used for `CoreAnimationLayer.logHierarchyKeypaths()` and `allHierarchyKeypaths()`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class BaseAnimationLayer: CALayer, AnimationLayer {

func setupAnimations(context: LayerAnimationContext) throws {
for childAnimationLayer in managedSublayers {
try (childAnimationLayer as? AnimationLayer)?.setupAnimations(context: context)
try (childAnimationLayer as? any AnimationLayer)?.setupAnimations(context: context)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,8 @@ class BaseCompositionLayer: BaseAnimationLayer {
// There are two different drop shadow schemas, either using `DropShadowEffect` or `DropShadowStyle`.
// If both happen to be present, prefer the `DropShadowEffect` (which is the drop shadow schema
// supported on other platforms).
let dropShadowEffect = baseLayerModel.effects.first(where: { $0 is DropShadowEffect }) as? DropShadowModel
let dropShadowStyle = baseLayerModel.styles.first(where: { $0 is DropShadowStyle }) as? DropShadowModel
let dropShadowEffect = baseLayerModel.effects.first(where: { $0 is DropShadowEffect }) as? any DropShadowModel
let dropShadowStyle = baseLayerModel.styles.first(where: { $0 is DropShadowStyle }) as? any DropShadowModel
if let dropShadowModel = dropShadowEffect ?? dropShadowStyle {
try contentsLayer.addDropShadowAnimations(for: dropShadowModel, context: context)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
/// Context available when constructing an `AnimationLayer`
struct LayerContext {
let animation: LottieAnimation
let imageProvider: AnimationImageProvider
let textProvider: AnimationKeypathTextProvider
let fontProvider: AnimationFontProvider
let imageProvider: any AnimationImageProvider
let textProvider: any AnimationKeypathTextProvider
let fontProvider: any AnimationFontProvider
let compatibilityTracker: CompatibilityTracker
var layerName: String

Expand Down
6 changes: 3 additions & 3 deletions Sources/Private/CoreAnimation/Layers/ShapeLayer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,7 @@ extension ShapeItem {
!drawsCGPath,
// Stroke widths are affected by scaling, but fill colors aren't.
// We can expand this to other types of items in the future if necessary.
let stroke = self as? StrokeShapeItem,
let stroke = self as? any StrokeShapeItem,
// We only need to handle scaling if there's a `ShapeTransform` present
let transform = childGroup.items.first(where: { $0 is ShapeTransform }) as? ShapeTransform
else { return self }
Expand Down Expand Up @@ -517,8 +517,8 @@ extension [ShapeItemLayer.Item] {
// when the items have the same `alpha` animations.
let allAlphaAnimationsAreIdentical = {
strokesAndFills.allSatisfy { item in
(item.item as? OpacityAnimationModel)?.opacity
== (strokesAndFills.first?.item as? OpacityAnimationModel)?.opacity
(item.item as? any OpacityAnimationModel)?.opacity
== (strokesAndFills.first?.item as? any OpacityAnimationModel)?.opacity
}
}

Expand Down
2 changes: 1 addition & 1 deletion Sources/Private/CoreAnimation/Layers/TextLayer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ final class TextLayer: BaseCompositionLayer {
// instead if implemented.
if let keypathTextValue = context.textProvider.text(for: textAnimationContext.currentKeypath, sourceText: sourceText.text) {
renderLayer.text = keypathTextValue
} else if let legacyTextProvider = context.textProvider as? LegacyAnimationTextProvider {
} else if let legacyTextProvider = context.textProvider as? any LegacyAnimationTextProvider {
renderLayer.text = legacyTextProvider.textFor(
keypathName: textAnimationContext.currentKeypath.fullPath,
sourceText: sourceText.text)
Expand Down
6 changes: 3 additions & 3 deletions Sources/Private/CoreAnimation/ValueProviderStore.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ final class ValueProviderStore {
// MARK: Internal

/// Registers an `AnyValueProvider` for the given `AnimationKeypath`
func setValueProvider(_ valueProvider: AnyValueProvider, keypath: AnimationKeypath) {
func setValueProvider(_ valueProvider: any AnyValueProvider, keypath: AnimationKeypath) {
logger.assert(
valueProvider.typeErasedStorage.isSupportedByCoreAnimationRenderingEngine,
"""
Expand Down Expand Up @@ -96,10 +96,10 @@ final class ValueProviderStore {
// MARK: Private

private let logger: LottieLogger
private var valueProviders = [(keypath: AnimationKeypath, valueProvider: AnyValueProvider)]()
private var valueProviders = [(keypath: AnimationKeypath, valueProvider: any AnyValueProvider)]()

/// Retrieves the most-recently-registered Value Provider that matches the given keypath.
private func valueProvider(for keypath: AnimationKeypath) -> AnyValueProvider? {
private func valueProvider(for keypath: AnimationKeypath) -> (any AnyValueProvider)? {
// Find the last keypath matching the given keypath,
// so we return the value provider that was registered most-recently
valueProviders.last(where: { registeredKeypath, _ in
Expand Down
Loading

0 comments on commit 71225b8

Please sign in to comment.