Modifiers and Layout Negotiation
Modifiers wrap views in order, and layout negotiates sizes by propose, choose and place. Expect padding then background puzzles, frame questions and GeometryReader traps in every loop.
on this pageshowhide
explore
- Ordering and Propagation4 questions
- Size Proposals and Frames6 questions
- Stacks and Alignment5 questions
- Grids and Adaptive Arrangement5 questions
- Geometry and Preferences6 questions
- Flow and Radial Containers6 questions
questions
page 2 of 2In a custom SwiftUI Layout, when do makeCache and updateCache run, and what is safe to keep in the layout cache?
level: seniorimportance: nice to knowfreq 20%
basics
~10 smakeCache(subviews:) builds storage that a layout's methods receive inout; SwiftUI calls updateCache(_:subviews:) when the subviews change, and its default rebuilds through makeCache. Keep subview-derived measurements there and key anything that depends on the proposal.
In SwiftUI, how would you build a tab indicator that slides to match the width and position of the selected tab label?
level: seniorimportance: nice to knowfreq 25%
basics
~20 sHave the selected label publish its bounds with anchorPreference(key:value:transform:) as an Anchor<CGRect>, then in the tab row's overlayPreferenceValue add a GeometryReader that resolves it with proxy[anchor] and draws the indicator there, animated on the selection.
showing 31–32 of 32