I created this custom progress view with bars for the progress, how can I animate the the green color in the next bar when it's time to go to the next element? I am looking for it to fill the bar slowly from left to right
struct ContentView: View {
var body: some View {
ProgressBar(lastIndex: 8, currentIndex: 4)
.padding(.horizontal, 23)
.padding(.top, 10)
Spacer()
}
}
struct ProgressBar: View {
var lastIndex: Int
var currentIndex: Int
var body: some View {
HStack(alignment: .center, spacing: 4) {
ForEach(0...lastIndex, id: \.self) { i in
BarElement(selected: i <= currentIndex)
}
}
}
}
struct BarElement: View {
var selected: Bool
var body: some View {
Capsule()
.fill(selected ? .green : Color(UIColor.lightGray))
.frame(width: 33, height: 5, alignment: .center)
}
}