Files
divkit/client/ios/DivKit/Animators/ProgressInterpolator.swift
T
morevsavva 60062e637e supported animators.
commit_hash:81368398970aed31520e08d5ece3385ba8a1bb07
2024-10-15 16:29:06 +03:00

44 lines
1.1 KiB
Swift

import Foundation
protocol ProgressInterpolator {
func interpolate(progress: CGFloat) -> CGFloat
}
struct LinearInterpolator: ProgressInterpolator {
func interpolate(progress: CGFloat) -> CGFloat {
progress
}
}
struct EaseInOutInterpolator: ProgressInterpolator {
func interpolate(progress: CGFloat) -> CGFloat {
progress < 0.5 ? 2 * progress * progress : -1 + (4 - 2 * progress) * progress
}
}
struct EaseInterpolator: ProgressInterpolator {
func interpolate(progress: CGFloat) -> CGFloat {
progress * progress * (3 - 2 * progress)
}
}
struct EaseInInterpolator: ProgressInterpolator {
func interpolate(progress: CGFloat) -> CGFloat {
progress * progress
}
}
struct EaseOutInterpolator: ProgressInterpolator {
func interpolate(progress: CGFloat) -> CGFloat {
progress * (2 - progress)
}
}
struct SpringInterpolator: ProgressInterpolator {
func interpolate(progress: CGFloat) -> CGFloat {
let dampingRatio: CGFloat = 0.5
let response: CGFloat = 0.5
return 1 - (pow(2, -10 * progress) * cos(progress * .pi * (response / dampingRatio)))
}
}