The Challenge
We recently added the LayoutSizable protocol so that both views and view controllers can report their layout size to the bottom sheet controller and the sheet can be the correct height when presented.
But what happens if that view (or view controller) changes size? e.g. new data arrives and the table view now has 6 rows instead of 4? How can the table view let the sheet know that it should recalculate its ideal size?
A Suggestion
- Add an overridable method
invalidatesLayoutSize() to UIViewController. A table view controller could call this when its data changes.
- The default implementation of this method on
UIViewController is to call the same method on its parent, thus moving it up the view controller chain until it finds a suitable responder (or reaches the top-level view controller).
BottomSheetController override this method and instead of calling to its parent, it just calls updateChildView() which will then adjust the idealContentHeightAnchor by re-evaluating layoutSize on the child.
The Challenge
We recently added the
LayoutSizableprotocol so that both views and view controllers can report their layout size to the bottom sheet controller and the sheet can be the correct height when presented.But what happens if that view (or view controller) changes size? e.g. new data arrives and the table view now has 6 rows instead of 4? How can the table view let the sheet know that it should recalculate its ideal size?
A Suggestion
invalidatesLayoutSize()toUIViewController. A table view controller could call this when its data changes.UIViewControlleris to call the same method on itsparent, thus moving it up the view controller chain until it finds a suitable responder (or reaches the top-level view controller).BottomSheetControlleroverride this method and instead of calling to its parent, it just callsupdateChildView()which will then adjust theidealContentHeightAnchorby re-evaluatinglayoutSizeon the child.