/PrivacyPickerSwiftUI

Custom half-modal in SwiftUI

Primary LanguageSwift

Description

Based on this post I've created a custom privacy picker in SwiftUI. The functionality is the following: the button triggers the half modal and based on the choice ("Private", "Public", "Friends") the button label is updated through @State and @Binding variables.

Since there is no native half modal in SwiftUI I've used UIViewRepresentable protocol to create a wrapper of the UIKit view. I've used @ViewBuilder to to pass the SwiftUI content without creating it in Storyboard. Then I have used the recently introduced UISheetPresentationController to create the half modal experience in UIKit. To present the modal I've used an UIButton.

Simulator Screen Recording - iPhone 8 Plus - 2022-04-04 at 11 12 18

Simulator Screen Recording - iPhone 8 Plus - 2022-04-04 at 11 47 28