Skip to content

Commit 9cceeb8

Browse files
committed
Add button to reset layout caches
By giving views a new ID
1 parent d80ad69 commit 9cceeb8

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

LayoutInspector/ContentView.swift

+10-3
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
import SwiftUI
22

33
struct ContentView: View {
4-
@State var width: CGFloat = 300
5-
@State var selectedView: String? = nil
4+
@State private var width: CGFloat = 300
5+
@State private var selectedView: String? = nil
6+
@State private var generation: Int = 0
67

78
var body: some View {
89
VStack {
9-
VStack(spacing: 50) {
10+
VStack(spacing: 24) {
1011
HStack(spacing: 0) {
1112
Rectangle().fill(.green)
1213
.debugLayout("green")
@@ -19,13 +20,19 @@ struct ContentView: View {
1920
.clearConsole()
2021
.environment(\.debugLayoutSelection, selectedView)
2122
.frame(width: width, height: 80)
23+
.id(generation)
2224

2325
LabeledContent {
2426
Slider(value: $width, in: 100...500, step: 1)
2527
} label: {
2628
Text("Width: \(width, format: .number.precision(.fractionLength(0)))")
2729
.monospacedDigit()
2830
}
31+
32+
Button("Reset layout cache") {
33+
generation += 1
34+
}
35+
.buttonStyle(.bordered)
2936
}
3037
.padding()
3138

0 commit comments

Comments
 (0)