I ran into the same issue and found two solutions:
Use a switch statement to exhaust the conditions for TabContent. This unfortunately results in the tabViewBottomAccessory always showing in every tab though, and as an empty accessory, which is not ideal.
Create an extension to View that you can use to modify the conditions of that view:
extension View {
@ViewBuilder
func `if`<Content: View>(_ condition: Bool, transform: (Self) -> Content) -> some View {
if condition {
transform(self)
} else {
self
}
}
}
Then you can use it as follows:
TabView(selection: $selectedTab) {
...
}
.if(selectedTab == .storage) { this in
this.tabViewBottomAccessory {
Button {
// Action
} label: {
Label("Add Item", systemImage: "plus")
}
}
}
Topic:
UI Frameworks
SubTopic:
SwiftUI
Tags: