7

I'm watching the WWDC 2019 talk Building Custom Views with SwiftUI. Around 14:50 he's describing the algorithm for the layout, and he says "we divide the space into 3 equal parts and propose one of those for the size of the least flexible child".

enter image description here

How does the parent (the HStack) know which child is the "least flexible"?

Up to that point in the talk, the explanation of the layout algorithm in SwiftUI had been clear to me -- parent views propose a size to child views, and child views respond with their desired size. In this case it sounds like some other property of each child is consulted before the size is proposed to the children. But what is that property and how do you control it from code?

Rob N
  • 15,024
  • 17
  • 92
  • 165
  • I think that, but I can't find any documentation for this thought, the parent view actually proposes the size to all of its children. All the children answer to the parent, some children answer with a less flexible size (for instance a Text that is big as its content) and other children with a more flexible size. Then, the parent starts the actual sizing process from the least flexible child to the most flexible child. – superpuccio Aug 28 '19 at 21:35
  • @matteopuc , can u give a specific example of what size is flexble , and what size is less flexbile? thanks – ximmyxiao Mar 10 '22 at 03:17

1 Answers1

0

I also got the same problem of the true meaning of the word "least flexible", I guess it's may be something like intrinsic content size ?

ximmyxiao
  • 2,622
  • 3
  • 20
  • 35