I need to identify height of UIViewController in order to show it inside bottom sheet. For creating bottom sheet, I use FitterSheets
library. It accepts UIViewController that I want to display inside sheet and some height. Then, the library displays my view controller with the height I specified. It seems everything ok and makes sense, but how am I able to calculate height of my view controller? It can be dynamic (for instance, dynamic views inside stackview). I cannot calculate its height before displaying it. In other words, I don't know how what will be the size of the content in my screen, because I take that data from the server. If you didn't understand problem, here is snipped of code:
present(SheetViewController(myViewController, size: ?), animated: false);
What size I should pass there? Of course I can calculate it approximately (for instance, according to data I get from API, I can multiply the amount of data to height of some view in my screen). But, it will be approximately, not accurate.
I think my solution should be following: I don't specify any height when presenting SheetViewController. I just resize SheetViewController after my view controller's view is appeared fully. Pseudo code will be following:
override viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)
var contentSize = 0
view.subviews.forEach {
contentSize += $0.frame.height
}
sheetViewController?.resize(contentSize);
}
But I don't think it is right solution and it actually does not work. So, what is the best way to solve my problem? How to display bottom sheet with the height equals to the height of the content?