Skip to content

Commit 5e08999

Browse files
committed
Fix makeDebuggableView/makeDebuggableViewList
1 parent e9b3227 commit 5e08999

File tree

1 file changed

+56
-26
lines changed

1 file changed

+56
-26
lines changed

Sources/OpenSwiftUICore/View/ViewDebug.swift

Lines changed: 56 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -134,20 +134,28 @@ extension ViewModifier {
134134
inputs: _ViewInputs,
135135
body: @escaping (_Graph, _ViewInputs) -> _ViewOutputs
136136
) -> _ViewOutputs {
137-
Subgraph.beginTreeElement(value: modifier.value, flags: 0)
138-
var inputs = inputs
139-
inputs.changedDebugProperties = []
137+
let shouldRecordTree = Subgraph.shouldRecordTree
138+
if shouldRecordTree {
139+
Subgraph.beginTreeElement(value: modifier.value, flags: 0)
140+
}
141+
142+
var inouts = inputs
143+
let prev = inouts.changedDebugProperties
144+
inouts.changedDebugProperties = []
145+
140146
var outputs = _makeView(
141147
modifier: modifier,
142148
inputs: inputs,
143149
body: body
144150
)
145-
if Subgraph.shouldRecordTree {
146-
withUnsafePointer(to: inputs) { pointer in
147-
_ViewDebug.reallyWrap(&outputs, value: modifier, inputs: pointer)
148-
}
151+
152+
inouts.changedDebugProperties = prev
153+
154+
if shouldRecordTree {
155+
_ViewDebug.reallyWrap(&outputs, value: modifier, inputs: &inouts)
156+
Subgraph.endTreeElement(value: modifier.value)
149157
}
150-
Subgraph.endTreeElement(value: modifier.value)
158+
151159
return outputs
152160
}
153161

@@ -157,9 +165,18 @@ extension ViewModifier {
157165
inputs: _ViewListInputs,
158166
body: @escaping (_Graph, _ViewListInputs) -> _ViewListOutputs
159167
) -> _ViewListOutputs {
160-
Subgraph.beginTreeElement(value: modifier.value, flags: 1)
161-
defer { Subgraph.endTreeElement(value: modifier.value) }
162-
return _makeViewList(modifier: modifier, inputs: inputs, body: body)
168+
let shouldRecordTree = Subgraph.shouldRecordTree
169+
if shouldRecordTree {
170+
Subgraph.beginTreeElement(value: modifier.value, flags: 1)
171+
}
172+
173+
let outputs = _makeViewList(modifier: modifier, inputs: inputs, body: body)
174+
175+
if shouldRecordTree {
176+
Subgraph.endTreeElement(value: modifier.value)
177+
}
178+
179+
return outputs
163180
}
164181
}
165182

@@ -169,19 +186,23 @@ extension View {
169186
view: _GraphValue<Self>,
170187
inputs: _ViewInputs
171188
) -> _ViewOutputs {
172-
Subgraph.beginTreeElement(value: view.value, flags: 0)
173-
var inputs = inputs
174-
inputs.changedDebugProperties = []
175-
var outputs = _makeView(
176-
view: view,
177-
inputs: inputs
178-
)
179-
if Subgraph.shouldRecordTree {
180-
withUnsafePointer(to: inputs) { pointer in
181-
_ViewDebug.reallyWrap(&outputs, value: view, inputs: pointer)
182-
}
189+
let shouldRecordTree = Subgraph.shouldRecordTree
190+
if shouldRecordTree {
191+
Subgraph.beginTreeElement(value: view.value, flags: 0)
183192
}
184-
Subgraph.endTreeElement(value: view.value)
193+
194+
var inouts = inputs
195+
let prev = inouts.changedDebugProperties
196+
inouts.changedDebugProperties = []
197+
198+
var outputs = Self._makeView(view: view, inputs: inouts)
199+
inouts.changedDebugProperties = prev
200+
201+
if shouldRecordTree {
202+
_ViewDebug.reallyWrap(&outputs, value: view, inputs: &inouts)
203+
Subgraph.endTreeElement(value: view.value)
204+
}
205+
185206
return outputs
186207
}
187208

@@ -190,9 +211,18 @@ extension View {
190211
view: _GraphValue<Self>,
191212
inputs: _ViewListInputs
192213
) -> _ViewListOutputs {
193-
Subgraph.beginTreeElement(value: view.value, flags: 1)
194-
defer { Subgraph.endTreeElement(value: view.value) }
195-
return _makeViewList(view: view, inputs: inputs)
214+
let shouldRecordTree = Subgraph.shouldRecordTree
215+
if shouldRecordTree {
216+
Subgraph.beginTreeElement(value: view.value, flags: 1)
217+
}
218+
219+
let outputs = _makeViewList(view: view, inputs: inputs)
220+
221+
if shouldRecordTree {
222+
Subgraph.endTreeElement(value: view.value)
223+
}
224+
225+
return outputs
196226
}
197227
}
198228

0 commit comments

Comments
 (0)