Skip to content

Instantly share code, notes, and snippets.

@chriseidhof
Created February 8, 2024 07:00
Show Gist options
  • Save chriseidhof/68b2cf3a993f6f5771c821db38d3c79e to your computer and use it in GitHub Desktop.
Save chriseidhof/68b2cf3a993f6f5771c821db38d3c79e to your computer and use it in GitHub Desktop.
import SwiftUI
extension View {
func debugLog(_ name: String) -> some View {
MyLayout(name: name) { self }
}
}
struct MyLayout: Layout {
var name: String
func sizeThatFits(proposal: ProposedViewSize, subviews: Subviews, cache: inout ()) -> CGSize {
assert(subviews.count == 1)
let result = subviews[0].sizeThatFits(proposal)
print(name, proposal, result)
return result
}
func placeSubviews(in bounds: CGRect, proposal: ProposedViewSize, subviews: Subviews, cache: inout ()) {
subviews[0].place(at: bounds.origin, proposal: proposal)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment