0

Suppose we have a view in NavigationView stack. This view has a onDisappear handler. The system calls this handler when the view is being covered by another view in stack, and when our view is popped from the stack.

Is there a way to obtain a real reason - is it covered or is it popped?

OK, some code:

var body: some View {
    NavigationView 
    {
        NavigationLink(destination: DetailView()) 
        {
            Text("View details")
        }
    }
    .onAppear 
    {
        if <NavigationView was recently created?>  // the essence of the question
        {
            print("NavigationView was recently created")
        } 
        else 
        {
            print("DetailView popped and disappeared")
        }
    }
}
Alexey
  • 79
  • 7
  • You just have to call the actions you need on the `.onAppear` of the View that will cover or pop on top of the NavigationView stack. It should work the way you want it. Feel free to share some code with what you are trying to do. – Roland Lariotte Apr 13 '21 at 18:34
  • OK, suppose, I'll do it in .onAppear. How cat I differ the cases - when this view was pushed or child view was popped? – Alexey Apr 16 '21 at 12:41
  • Sorry, but I don't understand what you are trying to do here. Can you show some code of what, exactly, you want to achieve? – Roland Lariotte Apr 16 '21 at 12:50

0 Answers0