forked from ole/swiftui-layout-inspector
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathDebugLayout.swift
30 lines (28 loc) · 903 Bytes
/
DebugLayout.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import SwiftUI
@available(macOS 13.0, iOS 16.0, tvOS 16.0, watchOS 9.0, *)
extension View {
/// Start debugging the layout algorithm for this subtree.
///
/// This clears the debug layout log.
public func startDebugLayout(selection: String? = nil) -> some View {
ClearDebugLayoutLog {
self
}
.environment(\.debugLayoutSelectedViewID, selection)
}
/// Monitor the layout proposals and responses for this view and add them
/// to the log.
public func debugLayout(
_ label: String,
file: StaticString = #fileID,
line: UInt = #line
) -> some View {
DebugLayout(label: label) {
self
}
.onAppear {
LogStore.shared.registerViewLabelAndWarnIfNotUnique(label, file: file, line: line)
}
.modifier(DebugLayoutSelectionHighlight(viewID: label))
}
}