I need to present a sheet containing SwiftUI view from UIViewController, but the height of the sheet has to fit the height of the content of the SwiftUI view.
I know that there is a possibility to specify custom detent for the height of the sheet, but I wonder whether it is possible to get the height of the content size of SwiftUI view when presenting it from the UIViewController?
So far I have tried getting the content size with the help of the GeometryReader in SwiftUI view, but did not get any result.
Here is my code where the SwiftUI view is presented for reference:
func presentSwiftUIPageSheet() {
let swiftUIView = SwiftUIView()
let hostingController = UIHostingController(rootView: swiftUIView)
hostingController.modalPresentationStyle = .pageSheet
hostingController.isModalInPresentation = false
hostingController.sheetPresentationController?.detents = [.medium(), .large()]
present(hostingController, animated: true)
}
Any advice would be much appreciated!