Protocol Requirements
sizeThatFits(proposal:subviews:cache:)
reports the size of the composite layout view.- i.e. decides where this view will appear
placeSubviews(in:proposal:subviews:cache:)
assigns positions to the container’s subviews.- i.e. tells the subviews where to appear
- Note: this method proposes positions to the subviews. The subviews can choose to comply or ignore.
Known Limitations
- Layout protocol cannot be lazy
Docs
- Compose custom layouts with SwiftUI - WWDC22 - Videos - Apple Developer
- Layout | Apple Developer Documentation
Helpful Resources
- SwiftUI Lab Deep Dive
- The Layout Protocol - Swift Talk - objc.io
- SwiftUI Layout: The Mystery of Size | Fatbobman’s Blog
- SwiftUI Field Guide