22// Transaction.swift
33// OpenSwiftUICore
44//
5- // Audited for iOS 18.0
5+ // Audited for 6.0.87
66// Status: Complete
77// ID: B2543BCA257433E04979186A1DC2B6BC (SwiftUICore)
88
@@ -51,6 +51,7 @@ import OpenSwiftUI_SPI
5151/// transaction.animation = .default.repeatCount(3)
5252/// }
5353/// }
54+ @available ( OpenSwiftUI_v5_0, * )
5455public protocol TransactionKey {
5556 /// The associated type representing the type of the transaction key's
5657 /// value.
@@ -62,12 +63,14 @@ public protocol TransactionKey {
6263 static func _valuesEqual( _ lhs: Value , _ rhs: Value ) -> Swift . Bool
6364}
6465
66+ @available ( OpenSwiftUI_v5_0, * )
6567extension TransactionKey {
6668 public static func _valuesEqual( _ lhs: Value , _ rhs: Value ) -> Bool {
6769 compareValues ( lhs, rhs)
6870 }
6971}
7072
73+ @available ( OpenSwiftUI_v5_0, * )
7174extension TransactionKey where Value: Equatable {
7275 public static func _valuesEqual( _ lhs: Value , _ rhs: Value ) -> Bool {
7376 lhs == rhs
@@ -95,6 +98,7 @@ private struct TransactionPropertyKey<Key>: PropertyKey where Key: TransactionKe
9598/// The root transaction for a state change comes from the binding that changed,
9699/// plus any global values set by calling ``withTransaction(_:_:)`` or
97100/// ``withAnimation(_:_:)``
101+ @available ( OpenSwiftUI_v1_0, * )
98102@frozen
99103public struct Transaction {
100104 @usableFromInline
@@ -189,6 +193,7 @@ extension Transaction: Sendable {}
189193///
190194/// - Returns: The result of executing the closure with the specified
191195/// transaction.
196+ @available ( OpenSwiftUI_v1_0, * )
192197public func withTransaction< Result> (
193198 _ transaction: Transaction ,
194199 _ body: ( ) throws -> Result
@@ -218,6 +223,7 @@ public func withTransaction<Result>(
218223///
219224/// - Returns: The result of executing the closure with the specified
220225/// transaction value.
226+ @available ( OpenSwiftUI_v1_0, * )
221227@_alwaysEmitIntoClient
222228public func withTransaction< R, V> (
223229 _ keyPath: WritableKeyPath < Transaction , V > ,
@@ -240,3 +246,18 @@ private var threadTransactionData: AnyObject? {
240246 )
241247 }
242248}
249+
250+ /// Returns the result of recomputing the view's body with the provided
251+ /// animation.
252+ ///
253+ /// This function sets the given ``Animation`` as the ``Transaction/animation``
254+ /// property of the thread's current ``Transaction``.
255+ @available ( OpenSwiftUI_v1_0, * )
256+ public func withAnimation< Result> (
257+ _ animation: Animation ? = . default,
258+ _ body: ( ) throws -> Result
259+ ) rethrows -> Result {
260+ var transaction = Transaction ( )
261+ transaction. animation = animation
262+ return try withTransaction ( transaction, body)
263+ }
0 commit comments