Half/full sheet cover SwiftUI
SwiftUI uses a declarative syntax, so as to state what the user interface should do. SwiftUI is designed to work alongside UIKit, so we can adopt it incrementally in our existing apps.
- Half Sheet Cover: In order to do a half sheet cover, we can do the following steps to implement it;
Step 1: In the .swift file, import SwiftUI.
Step 2: Create a UIHostingController
object when you want to integrate SwiftUI views into a UIKit view hierarchy. Use the hosting controller like you would any other view controller, by presenting it or embedding it as a child view controller in your interface.
Step 3: Use a UIViewControllerRepresentable instance to create and manage a UIViewController object in SwiftUI interface. Adopt this protocol in one of your app’s custom instances and use its methods to create, update, and tear down your view controller.
Step 4: Create an extension to create custom views by declaring types that conform to the View
protocol.
Step 5: Using it in the SwiftUI view, declare the sheet cover with the above function name, “halfSheet” and declare the ViewController you would want to show up.
2. Full Screen Cover: To create a full screen cover, we can directly use the command “fullScreenCover(isPresented:Binding<Bool>, content: () -> View)” in the SwiftUI view page.
Note: This was my approach to implement the functioality. Any suggestions are welcome..
Like, share and follow to get more interesting content…!!