79420040

Date: 2025-02-07 07:25:53
Score: 1.5
Natty:
Report link

why can't you use @Environment(.presentationMode) var presentationMode this it's easy to navigate using Environment variables

not much complex and just need to add one variable rather than passing it to all along

this is the very simple example to use @Environment variable to navigate

struct HomeView: View {
    var body: some View {
        NavigationStack {
            NavigationLink("Go to Detail", destination: DetailView())
        }
    }
}

struct DetailView: View {
    @Environment(\.presentationMode) var presentationMode
    
    var body: some View {
        Button("Go Back") {
            presentationMode.wrappedValue.dismiss()
        }
    }
}
Reasons:
  • Long answer (-0.5):
  • Has code block (-0.5):
  • User mentioned (1): @Environment
  • Starts with a question (0.5): why can't you use
  • Low reputation (1):
Posted by: HeWhoRemains