Set Variable when Navigate pages

12 views Asked by At

I need set a variable when I move between pages to hide or show a custom NavBar. I made in this way, but I'm not convinced. There is a better solution?

@Binding var navVisibility: Bool

var body: some View {
    
    List {
        NavigationLink {
            View()
                .navigationTitle("View1")
                .onAppear(perform: {
                    navVisibility = false
                })
        } label: {
            Label("View", systemImage: "folder.fill")
        }
    }
    .listStyle(.inset)
    .onAppear(perform: {
        navVisibility = true
    })
}
0

There are 0 answers