Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

160
Views
How to activate a NavigationLink in a List when the row is not yet visible?

Consider the following view code:

struct ContentView: View {

    @State var activeLink: Int? = 45

    var body: some View {
        NavigationView {
            VStack {
                Text("Hello, world!")
                    .padding()
                List(0..<100, id: \.self) { i in
                    NavigationLink(
                        tag: i,
                        selection: $activeLink,
                        destination: { MyNextView() }
                    ) {
                        Text("Row nr \(i)")
                    }
                }
            }
        }
    }
}

If the value of activeLink is the same as the tag of a NavigationLink that is currently visible in the UI, the NavigationLink will activate and MyNextView will be presented as expected. However if activeLink has a value equal to a tag of a NavigationLink outside of the visible UI, nothing happens. This became a problem in my project since I have an ObservableObject representing a "routing state"-model in my app that contains the value of every active NavigationLink in the view hierarchy. The reason for this is that I want to be able to recreate a view hierarchy on app start. However if my routing state wants to activate a NavigationLink outside of the visible UI, as in the example above, it does not work.

I have tried to scroll the list to the NavigationLink-element I want to activate in order to get it to appear but I have not found a smooth way to do this. I tried using the ScrollViewProxy.scrollTo(... in .onAppear(perform: ... of my view but it does not work without a DispatchQueue.main.asyncAfter(deadline: ... which seems very unreliable imo.

Has anyone else come across this problem?

over 4 years ago · Santiago Trujillo
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!