So I have a Navigation View in SwiftUI and when I use Stack Navigation View Style, I have 2 views: the root Navigation View, then the navigationLink in which the view has a bottom toolbar, and when I dismiss this view and go back to the root view, the bottom tool bar remains and does not go away unless I refresh the view with the .id
, but I would not like to use this as when I refresh the root view on navigation link dismissal, I lose my place in the scroll view so I would like to know, is there a way I can only refresh the bottom tool bar of the root view to show that there is no bottom bar instead of refreshing the whole root view.
Here is a mockup of my view that works to prevent the bottom tool bar from appearing in the root view.
struct rootView: View {
@State var refresh: UUID()
var body: some View {
NavigationView{
Form{
NavigationLink(destination: View().onDisappear{refresh = UUID()}){
}
}
}
.toolbar(content: {
})
.id(refresh)
.navigationViewStyle(StackNavigationViewStyle())
}
}
In my view I use a foreach for the navigation links, so if you are testing make sure that the form can scroll down to see if your possible solution doesn't cause the scroll position to be reset.
Then in the navigation link view, i have the bottom tool bar that I use, without the .id(refresh)
, the bottom bar will remain but without any contents in my root view, which is why I use the id but what happens is the scroll position also gets refreshed and I would like to know is there a way to only refresh the tool bar.
This is what my tool bar in my destination view looks like:
.toolbar(content: {
ToolbarItem(placement: .bottomBar) {
Group {
if conditional == true {
Button(action: { self.activeSheet = .bottomBar }) {
HStack {
Image(systemName: "sparkles").renderingMode(.original)
Text("Bottom ToolBar")
}
}
}
}
}
})