Lazy-View-SwiftUI icon indicating copy to clipboard operation
Lazy-View-SwiftUI copied to clipboard

Destination loaded only once

Open andrei1152 opened this issue 3 years ago • 4 comments

Is there any way of making LazyView load the wrapped view each time a navigationLink is tapped? Currently it loads only once and reuses that view on subsequent navigations

andrei1152 avatar Mar 12 '21 07:03 andrei1152

you could try combining it with this technique https://github.com/joehinkle11/AutoRerenderingView

joehinkle11 avatar Mar 12 '21 15:03 joehinkle11

probably better if you rely on onAppear though

joehinkle11 avatar Mar 12 '21 15:03 joehinkle11

Thanks, I'll have a look into the AutoRenderingView. The problem that I see with onAppear() is that if I'm in a navigation stack and do a network call on appear, it will be done both when the view is pushed, as well as popped. An event hook similar to viewDidLoad would be best

andrei1152 avatar Mar 12 '21 18:03 andrei1152

you can always use this janky hack I use...make a static variable and put a "didLoad" flag there. Then check if it's already flipped on onAppear.

ahhh SwiftUI...

joehinkle11 avatar Mar 12 '21 20:03 joehinkle11