From bfdce941d9eed0b56e90c1043380c247d837a7f5 Mon Sep 17 00:00:00 2001 From: Kyle Date: Mon, 18 Aug 2025 00:22:54 +0800 Subject: [PATCH 1/3] Optimize AnimatablePair debugDescription --- .../OpenSwiftUICore/Animation/Animatable/AnimatablePair.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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))" } } From eaaf14d6f542d133858ad8af9c8726945be69846 Mon Sep 17 00:00:00 2001 From: Kyle Date: Mon, 18 Aug 2025 00:36:13 +0800 Subject: [PATCH 2/3] Fix BezierAnimation fraction issue --- .../Animation/Animation/BezierAnimation.swift | 2 +- .../Animation/BezierAnimationTests.swift | 32 +++++++++++++++++++ 2 files changed, 33 insertions(+), 1 deletion(-) create mode 100644 Tests/OpenSwiftUICoreTests/Animation/Animation/BezierAnimationTests.swift 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)) + } +} From 8ed136b706268381df736edd356466ab42740597 Mon Sep 17 00:00:00 2001 From: Kyle Date: Mon, 18 Aug 2025 00:36:35 +0800 Subject: [PATCH 3/3] Update ColorAnimationExample --- Example/HostingExample/ViewController.swift | 2 +- Example/SharedExample/Animation/ColorAnimationExample.swift | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) 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() } }