diff --git a/Sources/FadeInText/FadeInTextController.swift b/Sources/FadeInText/FadeInTextController.swift index a2c45d6..3c3fc04 100644 --- a/Sources/FadeInText/FadeInTextController.swift +++ b/Sources/FadeInText/FadeInTextController.swift @@ -38,6 +38,7 @@ public class FadeInTextController: ObservableObject { @objc private func onFrameUpdate(_ displayLink: CADisplayLink) { guard let startTime, !self.chunks.isEmpty else { + self.tearDownDisplayLink() return } let time = CACurrentMediaTime() - startTime @@ -52,8 +53,12 @@ public class FadeInTextController: ObservableObject { } self.text = updatedString if newResult.shouldAnimationFinish { - self.displayLink?.invalidate() - self.displayLink = nil + self.tearDownDisplayLink() } } + + private func tearDownDisplayLink() { + self.displayLink?.invalidate() + self.displayLink = nil + } } diff --git a/Sources/FadeInText/Interpolator/LinearInterpolator.swift b/Sources/FadeInText/Interpolator/LinearInterpolator.swift index db86869..852214f 100644 --- a/Sources/FadeInText/Interpolator/LinearInterpolator.swift +++ b/Sources/FadeInText/Interpolator/LinearInterpolator.swift @@ -18,7 +18,7 @@ public final class LinearInterpolator: Interpolator { var newOpacities = [Double]() for i in 0.. 0) + XCTAssertTrue(result.opacities.filter { $0 == 0.0 }.count == 4) + + } +}