I have code with NavigationView and some NavigationLinks so one of them has toolbar modifier.
My problem is that when I select first NavigationLink toolbar button act normally, but when I go to second NavigationLink, resize window size to smallest possible, go back to first NavigationLink toolbar buttons under >> buttons seems to be disabled and I need to resize window to fullsize to make them enabled again
Please share any ideas on this bug. Is it possible to fix this? Or maybe it’s possible to implement what I need another way. I need to implement UI where sidebar contains multiple tabs so I can switch between them and open different Views for user
My code:
enum TabItems: String, CaseIterable, Identifiable {
case first
case second
case third
var id: String {
return rawValue
}
}
struct ContentView: View {
@State private var selection: TabItems? = TabItems.first
var body: some View {
NavigationView {
List {
ForEach(TabItems.allCases) { item in
NavigationLink(
destination: tabView(tab: item),
tag: item,
selection: $selection,
label: {
Text(item.id)}
)
}
}
}
}
@ViewBuilder
private func tabView(tab: TabItems) -> some View {
switch tab {
case .first:
Text(tab.id)
.toolbar {
ForEach(0 ..< 10) { _ in
Button(
action: {
print("button pressed")
},
label: {
Label(
title: {
Text("Button")
},
icon: {
Image(systemName: "plus")
}
)
}
)
}
}
case .second:
Text(tab.id)
case .third:
Text(tab.id)
}
}
}
How to produce this bug:
- Run code
- Go to second Tab
- Resize window to smallest size
- Go back to first Tab
- Click on toolbar >> button to show hidden buttons
TimParker is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.