I'm setting up an SwiftUI app with TabView-navigation and individual NavigationStacks (to preserve individual navigation state per stack).
One thing that buggles my mind is that I want to have the same profile button in the top right navigationbar on every View. Adding the navigationbar item as below requires me to have the exact same code/addition in every View.
.navigationDestination(isPresented: $presentProfilePage) {
ProfileView()
}
.toolbar {
Button {
presentProfilePage = true
} label: {
if let img = user.displayImg {
Image(uiImage: img)
.resizable()
.frame(width: 48, height: 48)
} else {
Image.defaultProfileImage
}
}
}
Is there a way to set the navigationbar items once and then they are visible on all views?