fix carousel view scrolling animation

pull/874/head
ryanzhao 2 years ago
parent 068af1136d
commit 3013f9b7fd

@ -135,13 +135,16 @@ struct PageView<Content>: View where Content: View {
let predictedEndOffset = -CGFloat(self.index) * geometry.size.width + value.predictedEndTranslation.width let predictedEndOffset = -CGFloat(self.index) * geometry.size.width + value.predictedEndTranslation.width
let predictedIndex = Int(round(predictedEndOffset / -geometry.size.width)) let predictedIndex = Int(round(predictedEndOffset / -geometry.size.width))
self.index = self.clampedIndex(from: predictedIndex) self.index = self.clampedIndex(from: predictedIndex)
withAnimation(.easeOut) { withAnimation(.easeOut(duration: 0.2)) {
self.dragging = false self.dragging = false
} }
switch self.index { // FIXME: This is a workaround for withAnimation() not having completion callback
case 0: self.index = self.maxIndex - 1 DispatchQueue.main.asyncAfter(deadline: .now() + 0.2) {
case self.maxIndex: self.index = 1 switch self.index {
default: break case 0: self.index = self.maxIndex - 1
case self.maxIndex: self.index = 1
default: break
}
} }
} }
) )

Loading…
Cancel
Save