Skip to content

Commit bc5561b

Browse files
committed
Explicitly recreate LogStore on Reset Layout Cache
This fixes many (but not all) issues described in #10, particularly on iOS: - On iOS, the padding, background, and HStack examples work correctly now, except that the initial proposed size to the root view of the subtree is equal to the eventual actual size, not the available size of the container view. I don't understand this yet. - On iOS, the fixedSize example is still weirdly broken: the Text child of the .fixedSize() doesn't appear in the layout log. A caching thing? - On macOS it’s still very broken. I don't understand why macOS behaves so differently.
1 parent 64ce4b1 commit bc5561b

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed

Sources/LayoutInspector/DebugLayout.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import SwiftUI
44
extension View {
55
/// Inspect the layout for this subtree.
66
@MainActor public func inspectLayout() -> some View {
7-
modifier(InspectLayout(logStore: LogStore()))
7+
modifier(InspectLayout())
88
}
99

1010
/// Monitor the layout proposals and responses for this view and add them

Sources/LayoutInspector/DebugLayoutImpl.swift

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ import SwiftUI
33
@available(macOS 13.0, iOS 16.0, tvOS 16.0, watchOS 9.0, *)
44
@MainActor
55
struct InspectLayout: ViewModifier {
6-
// Don't observe LogStore. Avoids an infinite update loop.
7-
var logStore: LogStore
6+
// Don't observe LogStore. Avoids an infinite update loop when store publishes changes.
7+
@State private var logStore: LogStore = .init()
88
@State private var selectedView: String? = nil
99
@State private var generation: Int = 0
1010
@State private var inspectorFrame: CGRect = CGRect(x: 0, y: 0, width: 300, height: 300)
@@ -34,6 +34,9 @@ struct InspectLayout: ViewModifier {
3434
.coordinateSpace(name: Self.coordSpaceName)
3535
}
3636
.environment(\.debugLayoutActions, logStore.actions)
37+
.onChange(of: generation) { newValue in
38+
logStore = LogStore()
39+
}
3740
}
3841

3942
@ViewBuilder private var inspectorUI: some View {

0 commit comments

Comments
 (0)