diff --git a/Example/HostingExample/ViewController.swift b/Example/HostingExample/ViewController.swift index 794a58140..f7b8e69b4 100644 --- a/Example/HostingExample/ViewController.swift +++ b/Example/HostingExample/ViewController.swift @@ -66,6 +66,6 @@ class ViewController: NSViewController { struct ContentView: View { var body: some View { - ColorViewControllerRepresentableExample() + ColorAnimationExample() } } diff --git a/Example/SharedExample/Animation/ColorAnimationExample.swift b/Example/SharedExample/Animation/ColorAnimationExample.swift index 9075fb5c1..cb23fe87a 100644 --- a/Example/SharedExample/Animation/ColorAnimationExample.swift +++ b/Example/SharedExample/Animation/ColorAnimationExample.swift @@ -15,9 +15,9 @@ struct ColorAnimationExample: View { Color(platformColor: showRed ? .red : .blue) .frame(width: showRed ? 200 : 400, height: showRed ? 200 : 400) } - .animation(.easeInOut(duration: 2), value: showRed) + .animation(.easeInOut(duration: 5), value: showRed) .onAppear { - DispatchQueue.main.asyncAfter(deadline: .now() + 2) { + DispatchQueue.main.asyncAfter(deadline: .now() + 1) { showRed.toggle() } } diff --git a/Sources/OpenSwiftUICore/Animation/Animatable/AnimatablePair.swift b/Sources/OpenSwiftUICore/Animation/Animatable/AnimatablePair.swift index 59a6f4bd9..4472fffb1 100644 --- a/Sources/OpenSwiftUICore/Animation/Animatable/AnimatablePair.swift +++ b/Sources/OpenSwiftUICore/Animation/Animatable/AnimatablePair.swift @@ -76,6 +76,6 @@ extension AnimatablePair: Sendable where First: Sendable, Second: Sendable {} extension AnimatablePair: CustomDebugStringConvertible { public var debugDescription: String { - "\(first), \(second)" + "(\(first), \(second))" } } diff --git a/Sources/OpenSwiftUICore/Animation/Animation/BezierAnimation.swift b/Sources/OpenSwiftUICore/Animation/Animation/BezierAnimation.swift index 45b17f133..eed0e19f6 100644 --- a/Sources/OpenSwiftUICore/Animation/Animation/BezierAnimation.swift +++ b/Sources/OpenSwiftUICore/Animation/Animation/BezierAnimation.swift @@ -489,7 +489,7 @@ package struct BezierAnimation: InternalCustomAnimation { guard duration > 0, duration >= elapsed else { return nil } - return curve.value(at: elapsed.clamp(min: 0.0, max: 1.0)) + return curve.value(at: (elapsed / duration).clamp(min: 0.0, max: 1.0)) } package var function: Animation.Function { diff --git a/Tests/OpenSwiftUICoreTests/Animation/Animation/BezierAnimationTests.swift b/Tests/OpenSwiftUICoreTests/Animation/Animation/BezierAnimationTests.swift new file mode 100644 index 000000000..5cff9c959 --- /dev/null +++ b/Tests/OpenSwiftUICoreTests/Animation/Animation/BezierAnimationTests.swift @@ -0,0 +1,32 @@ +// +// BezierAnimationTests.swift +// OpenSwiftUICoreTests + +import OpenSwiftUICore +import Testing +import Numerics + +// MARK: - BezierAnimationTests + +struct BezierAnimationTests { + @Test( + .bug( + "https://github.com/OpenSwiftUIProject/OpenSwiftUI/issues/459", + id: "459", + "BezierAnimation's fraction is behavior like a fixed 1 time duration animation" + ) + ) + func fraction() throws { + let animation = BezierAnimation( + curve: .init( + startControlPoint: .topLeading, + endControlPoint: .bottomTrailing + ), + duration: 100 + ) + let f1 = try #require(animation.fraction(for: 10.0)) + let f2 = try #require(animation.fraction(for: 50.0)) + #expect(f1.isApproximatelyEqual(to: 0.1, absoluteTolerance: 0.01)) + #expect(f2.isApproximatelyEqual(to: 0.5, absoluteTolerance: 0.01)) + } +}