I have set a .refreshable modifier on one of my views (attached to a VStack). This view has NavigationLinks to other pages, but unexpectedly the refreshable still works in the next pages on the NavigationStack.
i.e. I can still pull to refresh in any page that was linked from the first page where I declared the .refreshable...
I would like this .refreshable to apply only to the first page, and not to the rest of the pages.
How do I do that, and why does it behave like that in the first place?
The code on the first View/page looks like this:
VStack {
NavigationStack {
List {
//Some code with list elements
}
}
}
.refreshable {
await vm.loadUserStories(getUrl: url)
From the
.refreshabledocumentation:So the modifier puts your closure into the SwiftUI environment. That's why all your pages use it.
Reading on:
So the answer is, put the modifier directly on the
Listinstead of on theNavigationStack. Then only the environment of theList(and its subviews) will contain theRefreshAction, and it won't be visible to your other pages.