Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SwiftUI - NavigationLink Content loaded too early

Tags:

I have a basic list in my first View as Follows:

func buildList(sections: [Client]) -> some View {
    let list = List {
        ForEach(sections) { client in
            Section(header: Text(client.name)) {
                ForEach(client.projects) { project in
                    NavigationLink(destination: BuildsRouter.build(forProject: project)) {
                        HStack {
                            Text("Test \(project.id)").fontWeight(.ultraLight)
                        }
                    }
                }
            }
        }
    }
    return  list
}

I'm using NavigationLink to provide the details view for my Project object.

Thing is, when I make a Memory analysis graph I can see that BuildsView ( created from BuildsRouter.build(forProject: project) are created before I actually tap the navigation Link.

Question: Is there any way to create the details View once the link is tapped?

like image 915
CZ54 Avatar asked Feb 04 '20 10:02

CZ54


1 Answers

True, I wrote a blog post on this. You can wrap the destination views in a Lazy Container as a workaround. Update: From Xcode 11.4.1 NavigationLinks are lazy by default.

like image 124
AnupamChugh Avatar answered Sep 18 '22 22:09

AnupamChugh