I have a custom tab bar. In each view, I load some data for the database.
With 4 different views, whenever I click a view, the color will change, to easily know what view we are present on. However, for the view that loads more data than the other, the color change will take more time to be changed. How can I avoid this lag of changing the color?
My tab bar implementation:
VStack(spacing: 0){
ZStack{
switch selectedIndex{
case 0:
AllRestaurantsView()
case 1:
ActiveUserOrders()
case 2:
LiveOrdersView()
default:
ProfileUserView()
}
}
Divider()
HStack{
ForEach(0..<4, id: \.self){number in
Spacer()
Button(action: {
self.selectedIndex=number
}, label: {
VStack(spacing: 3){
Image(systemName: icons[number])
.font(.system(size: 25,
weight: .regular,
design: .default))
.foregroundColor(selectedIndex == number ? Color(.label) : Color(UIColor.lightGray))
Text(iconsNames[number])
.font(.system(size:12,
weight: .regular,
design: .default))
.foregroundColor(selectedIndex == number ? Color(.label) : Color(UIColor.lightGray))
}
})
Spacer()
}
}
}
How can I change the color faster?
Here you can see how changing to tab 2 takes time: