swift – Dynamic size bottom sheet based on it’s content in SwiftUI for iOS 14+


I am experimenting with SwiftUI. I got stuck with an implementation approach to achieving a height-adjusting bottom sheet in SwiftUI for iOS 14+. The generic bottom sheet should have configurable characteristics such as setting the left and right bottom sheet corner radius, background color, and opacity, handle bar on top of the bottom sheet, animation type, and animation duration(i.e. open and dismiss), etc. The bottom sheet should provide dismiss functionality such as drag and close. The bottom sheet height should be calculated based on the content it holds. The minimum height of the bottom sheet should be equal to its content view and the maximum should be 80% of the screen. If the bottom sheet reaches 80% then the internal content should scroll within the bottom sheet.

I have tried a few things but completely failed. My approach was to use Gemotry reader to calculate the sizes of content view inside the bottom sheet but I couldn’t get the desired output in terms of sizes and UI.

I request to please suggest a correct approach to achieve the same with all the configurations.

Latest articles

spot_imgspot_img

Related articles

Leave a reply

Please enter your comment!
Please enter your name here

spot_imgspot_img