Show a view on top of a Sheet - SwiftUI

1.6k views Asked by At

I want to show a Sheet, and then show a certain view (toast in my case) over all the NavigationView, including the Sheet, but it's showing behind the Sheet.

This is my Toast ViewModifier:

struct Toast: ViewModifier {

    //MARK: - PROPERTIES

    @ObservedObject var toastManager = SharedToastManager

    //MARK: - BODY

    func body(content: Content) -> some View {
        ZStack {
            content
            toastView
        }
    }

    private var toastView: some View {
        VStack {
            ...
        }
    }
}

extension View {

    /// Shows toast with configuration
    /// - Returns: Toast view
    func toast() -> some View {
        self.modifier(Toast())
    }
}

This is my AppMain:

@main
struct MyApp: App {

    @UIApplicationDelegateAdaptor(AppDelegate.self) var appDelegate

    var body: some Scene {
        WindowGroup {
            MainScreen()
                .toast()
        }
    }
}

And this is my MainScreen:

struct MainScreen: View {

    //MARK: - PROPERTIES

    @State var isShowing = false

    //MARK: - BODY

    var body: some View {
    
        NavigationView {
        
            VStack (spacing: 22) {
                
                Button {
                    
                    isShowing = true
                    
                } label: {
                    
                    Text("Show sheet")
                }
            }
        }
        .sheet(isPresented: $isShowing) {
            EmptyView()
        }
    }
}

I need please your help to show the toast over the sheet view.

0

There are 0 answers