Skip to content

Commit bed0d01

Browse files
committed
Add readme
1 parent dd830a5 commit bed0d01

File tree

3 files changed

+49
-1
lines changed

3 files changed

+49
-1
lines changed

LayoutInspector.xcodeproj/project.pbxproj

+2
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
5D2245F728D8FDB500E84C7D /* Preview Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = "Preview Assets.xcassets"; sourceTree = "<group>"; };
2525
5D2245FE28D9015300E84C7D /* DebugLayout.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DebugLayout.swift; sourceTree = "<group>"; };
2626
5D22463828DA2E7500E84C7D /* DebugLayoutLog.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DebugLayoutLog.swift; sourceTree = "<group>"; };
27+
5DB6BE4F28DE4D4E00280F5E /* README.md */ = {isa = PBXFileReference; lastKnownFileType = net.daringfireball.markdown; path = README.md; sourceTree = "<group>"; };
2728
/* End PBXFileReference section */
2829

2930
/* Begin PBXFrameworksBuildPhase section */
@@ -40,6 +41,7 @@
4041
5D2245E328D8FDB400E84C7D = {
4142
isa = PBXGroup;
4243
children = (
44+
5DB6BE4F28DE4D4E00280F5E /* README.md */,
4345
5D2245EE28D8FDB400E84C7D /* LayoutInspector */,
4446
5D2245ED28D8FDB400E84C7D /* Products */,
4547
);

LayoutInspector/ContentView.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ struct ContentView: View {
77
@State private var generation: Int = 0
88

99
var subject: some View {
10-
Text("Hello")
10+
Text("Hello world")
1111
.debugLayout("Text")
1212
.padding()
1313
.debugLayout("padding")

README.md

+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
# SwiftUI Layout Inspector
2+
3+
Ole Begemann, 2022-09
4+
5+
Based on: [objc.io, Swift Talk episode 318, Inspecting SwiftUI's Layout Process (2022-08)](https://talk.objc.io/episodes/S01E318-inspecting-swiftui-s-layout-process)
6+
7+
Inspect the layout algorithm of SwiftUI views, i.e. what sizes views propose to
8+
their children and what sizes they return to their parents.
9+
10+
## Requirements
11+
12+
iOS 16.0 or macOS 13.0 (requires the `Layout` protocol).
13+
14+
## Instructions
15+
16+
1. Edit the `subject: some View` property in `ContentView`. It should contain
17+
the view tree you want to inspect.
18+
19+
2. Add `.debugLayout()` to each view in the view tree whose layout algorithm
20+
you want to inspect.
21+
22+
Example of a `subject` property with a few `debugLayout` inspection points:
23+
24+
```swift
25+
var subject: some View {
26+
Text("Hello world")
27+
.debugLayout("Text")
28+
.padding()
29+
.debugLayout("padding")
30+
.background {
31+
Color.yellow
32+
.debugLayout("yellow")
33+
}
34+
.debugLayout("background")
35+
}
36+
```
37+
38+
4. Build and run the app.
39+
40+
- The subject view is displayed on top.
41+
- The table on the bottom displays the sizes that are being proposed at each
42+
inspection point in the subject view ("Proposal", and the resulting view
43+
sizes ("Response").
44+
- You can use the sliders to modify the size proposed to the subject view.
45+
- Some views cache certain layout information. Press "Reset layout cache"
46+
after modifying the sliders to reset the caches.

0 commit comments

Comments
 (0)