'Replicating the underlying code of the fullScreenCover view modifier to use UIKit presentation
The fullScreenCover
view modifier doesn't seem to really "modify" the view, it just presents a view on top. So I'm wondering what the underlying code looks like. This is the function:
func fullScreenCover<Content>(isPresented: Binding<Bool>, onDismiss: (() -> Void)? = nil, content: @escaping () -> Content) -> some View where Content : View
I want to try making a similar custom view modifier that takes an isPresented
binding and runs some UIKit
code to present a view.
Currently I am listening to a @Published
value and then presenting the view like this:
.onReceive(controller.$showMyView) { showingMyView in
if showingMyView {
MyUIKitComponent.present(
onDismiss: {
controller.showMyView = false
// Do some other stuff here
}
)
}
}
But I'd like to turn it into a view modifier like this:
.showMyView(
isPresented: $controller.showMyView,
onDismiss: {
// Do some other stuff here
}
)
How can I do this?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|