1

I present a modal view with fullScreenCover by pressing "present my modal" button:

struct ContentView: View {

    @State var presentMyModal = false

    var body: some View {
        Text("Hello, world!")
            .fullScreenCover(isPresented: $presentMyModal) {
                    MyModalView()
            }
        Button(action: { presentMyModal = true },
               label: { Text("present my modal")})
    }
}

Then I want to push a new view with NavigationLink from this modal:

struct MyAlertView: View {

    @State var pushNavigationLinkedView = false

    var body: some View {
        Text("MyAlertView")
            .padding()
        Button(action: { pushNavigationLinkedView = true },
               label: { Text("push navigation linked view")})

        NavigationLink(destination: NavigationLinkedView(),
                       isActive: $pushNavigationLinkedView) {
            EmptyView()
        }
    }
}

And here is my NavigationLinkedView :

struct NavigationLinkedView: View {
    var body: some View {
        Text("NavigationLinkedView")
            .padding()
    }
}

But nothing happens when I press "push navigation linked view" button.

So is it allowed by apple guideline to push a view with NavigationLink from a modal view ? If yes, what is the best way to do it ?

Tested on iOS15 and XCode 13

1 Answer 1

1

So is it allowed by Apple guideline to push a view with NavigationLink from a modal view?

Yes. Just make sure you have a NavigationView at the base of MyAlertView. The modal sheet creates a new view hierarchy, and NavigationLink only works when there’s a NavigationView somewhere in the hierarchy above.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.