2
2
// Transaction.swift
3
3
// OpenSwiftUICore
4
4
//
5
- // Audited for iOS 18.0
5
+ // Audited for 6.0.87
6
6
// Status: Complete
7
7
// ID: B2543BCA257433E04979186A1DC2B6BC (SwiftUICore)
8
8
@@ -51,6 +51,7 @@ import OpenSwiftUI_SPI
51
51
/// transaction.animation = .default.repeatCount(3)
52
52
/// }
53
53
/// }
54
+ @available ( OpenSwiftUI_v5_0, * )
54
55
public protocol TransactionKey {
55
56
/// The associated type representing the type of the transaction key's
56
57
/// value.
@@ -62,12 +63,14 @@ public protocol TransactionKey {
62
63
static func _valuesEqual( _ lhs: Value , _ rhs: Value ) -> Swift . Bool
63
64
}
64
65
66
+ @available ( OpenSwiftUI_v5_0, * )
65
67
extension TransactionKey {
66
68
public static func _valuesEqual( _ lhs: Value , _ rhs: Value ) -> Bool {
67
69
compareValues ( lhs, rhs)
68
70
}
69
71
}
70
72
73
+ @available ( OpenSwiftUI_v5_0, * )
71
74
extension TransactionKey where Value: Equatable {
72
75
public static func _valuesEqual( _ lhs: Value , _ rhs: Value ) -> Bool {
73
76
lhs == rhs
@@ -95,6 +98,7 @@ private struct TransactionPropertyKey<Key>: PropertyKey where Key: TransactionKe
95
98
/// The root transaction for a state change comes from the binding that changed,
96
99
/// plus any global values set by calling ``withTransaction(_:_:)`` or
97
100
/// ``withAnimation(_:_:)``
101
+ @available ( OpenSwiftUI_v1_0, * )
98
102
@frozen
99
103
public struct Transaction {
100
104
@usableFromInline
@@ -189,6 +193,7 @@ extension Transaction: Sendable {}
189
193
///
190
194
/// - Returns: The result of executing the closure with the specified
191
195
/// transaction.
196
+ @available ( OpenSwiftUI_v1_0, * )
192
197
public func withTransaction< Result> (
193
198
_ transaction: Transaction ,
194
199
_ body: ( ) throws -> Result
@@ -218,6 +223,7 @@ public func withTransaction<Result>(
218
223
///
219
224
/// - Returns: The result of executing the closure with the specified
220
225
/// transaction value.
226
+ @available ( OpenSwiftUI_v1_0, * )
221
227
@_alwaysEmitIntoClient
222
228
public func withTransaction< R, V> (
223
229
_ keyPath: WritableKeyPath < Transaction , V > ,
@@ -240,3 +246,18 @@ private var threadTransactionData: AnyObject? {
240
246
)
241
247
}
242
248
}
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