NavigationLink needs a constructed destination to work, as opposed to modals (.sheet/.fullScreenCover) where the destination is lazy.
Creating views in SwiftUI is very light, but it's not the same when you're working with hundreds of entries on a list and each row creates its own NavigationLink(s), plus those views also create (on init or through a factory) their dependencies (ViewModel, DataModel, Logic, etc).
This means every time the view is updated all the displayed NavigationLinks will be recreated, consuming a lot of resources that are not needed since those destination views could not ever be used if the user doesn't navigate there.
Should we have a NavigationLink that takes a destination lazily, or is there something else I'm missing?
In this regard, there's another issue which is views "popping" on a NavigationView don't get deallocated. This works just fine with modals, views presented modally deallocate as soon as the user go back, but it's not the case for views loaded using NavigationLink. I think it's related to the issue I described above. Is this intended behaviour?
Thank you.
Creating views in SwiftUI is very light, but it's not the same when you're working with hundreds of entries on a list and each row creates its own NavigationLink(s), plus those views also create (on init or through a factory) their dependencies (ViewModel, DataModel, Logic, etc).
This means every time the view is updated all the displayed NavigationLinks will be recreated, consuming a lot of resources that are not needed since those destination views could not ever be used if the user doesn't navigate there.
Should we have a NavigationLink that takes a destination lazily, or is there something else I'm missing?
In this regard, there's another issue which is views "popping" on a NavigationView don't get deallocated. This works just fine with modals, views presented modally deallocate as soon as the user go back, but it's not the case for views loaded using NavigationLink. I think it's related to the issue I described above. Is this intended behaviour?
Thank you.