0

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?

Tometoyou
  • 7,792
  • 12
  • 62
  • 108
  • Does this answer your question https://stackoverflow.com/a/61811749/12299030? – Asperi Feb 12 '22 at 19:38
  • Does this answer your question? [SwiftUI - Half modal?](https://stackoverflow.com/questions/56700752/swiftui-half-modal) – lorem ipsum Feb 12 '22 at 20:33
  • The question I linked above has an adaptiveSheet modifier that goes through the steps of creating your own. The adaptive part is iOS 15 which is just a small portion of code – lorem ipsum Feb 12 '22 at 20:34

0 Answers0