Thursday, September 11, 2025
HomeiOS Developmentios - How can I dismiss a sheet and have it load...

ios – How can I dismiss a sheet and have it load a brand new view as soon as a sheet is dismissed?


So I’m making a sport and on the finish, need the sheet to look to finish the sport. Ultimately, it’s going to have a number of extra choices, however have to get this primary. That is the primary app I’m creating, so undecided that is one of the simplest ways to deal with it.

So I added this code and it’s working for essentially the most half. Nonetheless, when I discovered that nothing modifications after I hit New Recreation. If I take away the sheet dismissal, I discovered that the view is loading within the sheet that’s being dismissed. What can I alter to have it so that after a sheet is dismissed, it’s going to load the brand new view as a substitute of the present sport view?

import SwiftUI

struct GameEndCustomSheet: View {
    @Surroundings(.presentationMode) var presentationMode
    @State non-public var navigateToNewGame = false
    
    var physique: some View {
        NavigationStack {
            VStack {
                Textual content("Recreation Ended")
                
                Button(motion: {
                    // Dismiss the sheet first
                    presentationMode.wrappedValue.dismiss()
                    
                    // After dismissal, navigate to the brand new view
                    DispatchQueue.primary.asyncAfter(deadline: .now() + 0.1) {
                        navigateToNewGame = true
                    }
                }) {
                    Textual content("New Recreation")
                }
            }
            .navigationDestination(isPresented: $navigateToNewGame) {
                ContentView()
            }
        }
    }
}

struct GameEndCustomSheet_Previews: PreviewProvider {
    static var previews: some View {
        GameEndCustomSheet()
    }
}

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments