Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

151
Vistas
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
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda