@@ -10,10 +10,17 @@ package import OpenGraphShims
10
10
11
11
// MARK: - TransactionModifier
12
12
13
+ /// Modifier to set a transaction adjustment.
13
14
@frozen
14
15
public struct _TransactionModifier : ViewModifier , _GraphInputsModifier , PrimitiveViewModifier {
16
+ /// A closure that transforms the current transaction.
17
+ ///
18
+ /// This closure receives the current transaction and can modify it in place.
15
19
public var transform : ( inout Transaction ) -> ( )
16
20
21
+ /// Creates a transaction modifier with the specified transform closure.
22
+ ///
23
+ /// - Parameter transform: A closure that modifies the transaction in place.
17
24
public init ( transform: @escaping ( inout Transaction ) -> ( ) ) {
18
25
self . transform = transform
19
26
}
@@ -42,12 +49,25 @@ private struct ChildTransaction: Rule, AsyncAttribute {
42
49
43
50
// MARK: - ValueTransactionModifier
44
51
52
+ /// Modifier to set a transaction adjustment with a value constraint.
45
53
@frozen
46
54
public struct _ValueTransactionModifier < Value> : ViewModifier , _GraphInputsModifier , PrimitiveViewModifier where Value: Equatable {
55
+ /// The value to monitor for changes.
56
+ ///
57
+ /// When this value changes (as determined by `Equatable` conformance),
58
+ /// the transaction modifier will be applied.
47
59
public var value : Value
48
60
61
+ /// A closure that transforms the current transaction.
62
+ ///
63
+ /// This closure receives the current transaction and can modify it in place.
49
64
public var transform : ( inout Transaction ) -> ( )
50
65
66
+ /// Creates a value transaction modifier with the specified value and transform closure.
67
+ ///
68
+ /// - Parameters:
69
+ /// - value: The value to monitor for changes.
70
+ /// - transform: A closure that modifies the transaction in place.
51
71
public init ( value: Value , transform: @escaping ( inout Transaction ) -> Void ) {
52
72
self . value = value
53
73
self . transform = transform
@@ -76,6 +96,10 @@ public struct _ValueTransactionModifier<Value>: ViewModifier, _GraphInputsModifi
76
96
@available ( * , unavailable)
77
97
extension _ValueTransactionModifier : Sendable { }
78
98
99
+ /// A stateful rule that tracks value changes to determine when to update transactions.
100
+ ///
101
+ /// This structure maintains state about a value being monitored, comparing new values
102
+ /// with the previous ones to detect changes.
79
103
struct ValueTransactionSeed < V> : StatefulRule , AsyncAttribute where V: Equatable {
80
104
var _value : Attribute < V >
81
105
var _transactionSeed : Attribute < UInt32 >
@@ -123,13 +147,19 @@ private struct ChildValueTransaction: Rule, AsyncAttribute {
123
147
}
124
148
125
149
// MARK: - PushPopTransactionModifier
126
-
127
150
@frozen
128
151
public struct _PushPopTransactionModifier < Content> : ViewModifier , MultiViewModifier , PrimitiveViewModifier where Content: ViewModifier {
152
+ /// The content to which the transaction modification applies.
129
153
public var content : Content
130
154
155
+ /// The base transaction modifier to apply.
131
156
public var base : _TransactionModifier
132
157
158
+ /// Creates a push-pop transaction modifier with the specified content and transform closure.
159
+ ///
160
+ /// - Parameters:
161
+ /// - content: The content to which the transaction modification applies.
162
+ /// - transform: A closure that modifies the transaction in place.
133
163
public init ( content: Content , transform: @escaping ( inout Transaction ) -> Void ) {
134
164
self . content = content
135
165
self . base = . init( transform: transform)
@@ -164,21 +194,35 @@ extension _PushPopTransactionModifier: Sendable {}
164
194
165
195
extension _GraphInputs {
166
196
private struct SavedTransactionKey : ViewInput {
197
+ /// The default value for saved transactions.
167
198
static let defaultValue : [ Attribute < Transaction > ] = [ ]
168
199
}
169
200
201
+ /// The stack of saved transactions.
202
+ ///
203
+ /// This property maintains a stack of transaction contexts that can be restored
204
+ /// after temporary modifications.
170
205
package var savedTransactions : [ Attribute < Transaction > ] {
171
206
get { self [ SavedTransactionKey . self] }
172
207
set { self [ SavedTransactionKey . self] = newValue }
173
208
}
174
209
}
175
210
176
211
extension _ViewInputs {
212
+ /// The stack of saved transactions.
213
+ ///
214
+ /// This property provides access to the transaction stack from view inputs.
177
215
package var savedTransactions : [ Attribute < Transaction > ] {
178
216
get { base. savedTransactions }
179
217
set { base. savedTransactions = newValue }
180
218
}
181
219
220
+ /// Gets the transaction to use for geometry calculations.
221
+ ///
222
+ /// This method returns the first saved transaction if available, or the current
223
+ /// transaction otherwise.
224
+ ///
225
+ /// - Returns: The transaction attribute to use for geometry calculations.
182
226
package func geometryTransaction( ) -> Attribute < Transaction > {
183
227
savedTransactions. first ?? transaction
184
228
}
0 commit comments