This code lists 100 rows with refresh icon animations. When using a LazyVStack
instead of a VStack
, after scrolling down to the bottom of this list all the animations stop, including those at the top of the list once you scroll back. No such issues with a VStack
. Any ideas as to why this is happening and is there a workaround?
Using Xcode 12.0.1, iOS 14, Swift 5
struct RefreshingList : View {
@State var isAnimating = false
var body: some View {
ScrollView {
LazyVStack { // <- change to VStack to have animations not stop
ForEach(0..<100, id: \.self) { i in
HStack {
Text("\(i) -> ")
self.button()
}
}
}
}
.onAppear {
self.isAnimating=true
}
}
func button() -> some View {
Button(action: {}, label: {
Image(systemName: "arrow.2.circlepath")
.rotationEffect(Angle(degrees: self.isAnimating ? 360.0 : 0.0))
.animation(Animation.linear(duration: 2.0)
.repeatForever(autoreverses: false))
})
}
}