import SwiftUI
struct DashboardTabBarView: View {
@State private var selection: String = "home"
var body: some View {
TabView(selection: $selection) {
Color.red
.onTapGesture {
selection = "cart"
}
.tabItem {
Image(icon: .camera)
Text("cart")
}
Color.green
.onTapGesture {
selection = "home"
}
.tabItem {
Image(icon: .cart)
Text("home")
}
Color.blue
.onTapGesture {
selection = "noti"
}
.tabItem {
Image(icon: .drawer)
Text("noti")
}
}
}
}
struct DashboardTabBarView_Previews: PreviewProvider {
static var previews: some View {
DashboardTabBarView()
}
}
This is my code I just want to swap the position of the tab items on click from example, lets say i have three tab items one in center and other two in left and right:
A B C
When i click A, the tab should look like this:
B A C
Rest of the cases are: A C B
C A B
C B A
B A C
Note: The item should swap with its content (containing view), not just the name/image.