Skip to content

Commit bc5cba4

Browse files
committed
Fix over-eager layout size caching
Certain conditions caused the current size to get reused when it should've been recomputed. This led to children sometimes only realizing that they wanted to resize once the non dry run update came around, leading to some very strange and incorrect layouts.
1 parent 23f92c1 commit bc5cba4

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

Sources/SwiftCrossUI/ViewGraph/ViewGraphNode.swift

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,13 @@ public class ViewGraphNode<NodeView: View, Backend: AppBackend> {
169169
return cachedSize
170170
}
171171

172-
if dryRun, let currentSize,
172+
// Attempt to cleverly reuse the current size if we can know that it
173+
// won't change. We must of course be in a dry run, have a known
174+
// current size, and must've run at least one proper dry run update
175+
// since the last update cycle (checked via`!sizeCache.isEmpty`) to
176+
// ensure that the view has been updated at least once with the
177+
// current view state.
178+
if dryRun, let currentSize, !sizeCache.isEmpty,
173179
((Double(lastProposedSize.x) >= currentSize.maximumWidth
174180
&& Double(proposedSize.x) >= currentSize.maximumWidth)
175181
|| proposedSize.x == lastProposedSize.x)

0 commit comments

Comments
 (0)