I'm trying to create a list of objects that when filled every object will have an animation with a delay depending on its position in the array.
To replicate my problem here's the code:
struct ScrollViewTest: View{
@State private var indexes = [Int]()
var body: some View{
VStack{
ForEach(indexes, id:.self){ index in
Text("Index: (index)")
.transition(.opacity)
}
}
.onAppear {
for index in 0..<9{
withAnimation(Animation.easeInOut.delay(Double(index) * 0.5)){
indexes.insert(index, at: index)
}
}
}
}
}
As you can see, Index 8
is already visible before the animation even started.
How do I solve this kind of problem?
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…