Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

158
Visualizações
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 à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda