From 3013f9b7fd741c2c6be5cea9a02bc8c064b30be8 Mon Sep 17 00:00:00 2001 From: ryanzhao Date: Fri, 4 Aug 2023 16:52:39 +1000 Subject: [PATCH] fix carousel view scrolling animation --- Session/Shared/SessionCarouselView+SwiftUI.swift | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/Session/Shared/SessionCarouselView+SwiftUI.swift b/Session/Shared/SessionCarouselView+SwiftUI.swift index 53cc1668d..d626a1c18 100644 --- a/Session/Shared/SessionCarouselView+SwiftUI.swift +++ b/Session/Shared/SessionCarouselView+SwiftUI.swift @@ -135,13 +135,16 @@ struct PageView: View where Content: View { let predictedEndOffset = -CGFloat(self.index) * geometry.size.width + value.predictedEndTranslation.width let predictedIndex = Int(round(predictedEndOffset / -geometry.size.width)) self.index = self.clampedIndex(from: predictedIndex) - withAnimation(.easeOut) { + withAnimation(.easeOut(duration: 0.2)) { self.dragging = false } - switch self.index { - case 0: self.index = self.maxIndex - 1 - case self.maxIndex: self.index = 1 - default: break + // FIXME: This is a workaround for withAnimation() not having completion callback + DispatchQueue.main.asyncAfter(deadline: .now() + 0.2) { + switch self.index { + case 0: self.index = self.maxIndex - 1 + case self.maxIndex: self.index = 1 + default: break + } } } )