-
Notifications
You must be signed in to change notification settings - Fork 84
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Toolbar: icon from one view A gets added to view B #58
Comments
Hi @mattevigo, I am trying to solve this but still did not find a way around... Did you also experience this? |
Hi @alelordelo, would you be able to provide us with a code snippet to help you debug the issue? Maybe the .toolbar modifier is attached to the wrong view, but it's just a guess. Thanks. |
Hi @matteopuc , there you go! Note that the view B gets toolbar icons also from view A.
|
Hi @alelordelo, thanks for the code snippet. Here is the solution: you have to move the .toolbar {
ToolbarItem(placement: .status) {
Image(systemName: "a.circle.fill")
}
} of the import SwiftUI
import NavigationStack
struct SidebarView: View {
var body: some View {
NavigationView {
List {
NavigationLink(destination: ViewA()) {
Label("Message", systemImage: "message")
}
}
.listStyle(SidebarListStyle())
.navigationTitle("Explore")
.frame(minWidth: 150, idealWidth: 250, maxWidth: 300)
ViewA()
}
}
}
struct ViewA: View {
var body: some View {
NavigationStackView {
VStack {
PushView(destination: ViewB()) {
Text("A -> B Push")
}
.toolbar {
ToolbarItem(placement: .status) {
Image(systemName: "a.circle.fill")
}
}
}
}
.navigationTitle("A")
}
}
struct ViewB: View {
var body: some View {
VStack(alignment: .leading) {
PopView {
Image(systemName: "chevron.backward")
}
Text("B")
}
.navigationTitle("B")
.toolbar {
ToolbarItem(placement: .confirmationAction) {
Image(systemName: "b.circle.fill")
}
}
}
} |
ahhh, it was that simple! thanks a ton again Matteo! |
When used on MacOS, on PushView the toolbar icon from one view A gets added to view B.
Did anyone else experience this?
The text was updated successfully, but these errors were encountered: