From 55c81594d914218ce657f3680121bf3a41f1c661 Mon Sep 17 00:00:00 2001 From: Sheng Xu Date: Wed, 18 Dec 2024 14:41:56 -0800 Subject: [PATCH] =?UTF-8?q?fix:=20=F0=9F=90=9B=20improve=20Carousel's=20dr?= =?UTF-8?q?ag=20gesture=20to=20avoid=20conflicts?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cherrypick from main --- .../FioriSwiftUICore/Card/MobileCardExample.swift | 14 ++++++++++---- Sources/FioriSwiftUICore/Views/Carousel.swift | 3 +-- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/Apps/Examples/Examples/FioriSwiftUICore/Card/MobileCardExample.swift b/Apps/Examples/Examples/FioriSwiftUICore/Card/MobileCardExample.swift index a6ed6b5b7..3b8564c1b 100644 --- a/Apps/Examples/Examples/FioriSwiftUICore/Card/MobileCardExample.swift +++ b/Apps/Examples/Examples/FioriSwiftUICore/Card/MobileCardExample.swift @@ -107,12 +107,18 @@ struct CarouselTestView: View { var body: some View { ScrollView(.vertical) { - Carousel(numberOfColumns: Int(self.numberOfColumns), spacing: self.spacing, alignment: self.alignment == 0 ? .top : (self.alignment == 1 ? .center : .bottom), isSnapping: self.isSnapping, isSameHeight: self.isSameHeight) { - ForEach(0 ..< CardTests.cardSamples.count, id: \.self) { i in - NavigationLink(destination: Text("Detail View")) { - CardTests.cardSamples[i] + VStack(alignment: .leading, spacing: 24) { + RoundedRectangle(cornerRadius: 16).foregroundStyle(Color.preferredColor(.grey3)).frame(height: 300) + + Carousel(numberOfColumns: Int(self.numberOfColumns), spacing: self.spacing, alignment: self.alignment == 0 ? .top : (self.alignment == 1 ? .center : .bottom), isSnapping: self.isSnapping, isSameHeight: self.isSameHeight) { + ForEach(0 ..< CardTests.cardSamples.count, id: \.self) { i in + NavigationLink(destination: Text("Detail View")) { + CardTests.cardSamples[i] + } } } + + RoundedRectangle(cornerRadius: 16).foregroundStyle(Color.preferredColor(.grey3)).frame(height: 300) } .cardStyle(.card) .padding(self.padding) diff --git a/Sources/FioriSwiftUICore/Views/Carousel.swift b/Sources/FioriSwiftUICore/Views/Carousel.swift index 54c835037..76591bbe6 100644 --- a/Sources/FioriSwiftUICore/Views/Carousel.swift +++ b/Sources/FioriSwiftUICore/Views/Carousel.swift @@ -260,7 +260,7 @@ public struct Carousel: View where Content: View { } .contentShape(Rectangle()) .highPriorityGesture( - DragGesture() + DragGesture(minimumDistance: 20) .onChanged { value in self.contentOffset.x = self.preContentOffset.x + (self.layoutDirection == .leftToRight ? -1 : 1) * value.translation.width } @@ -273,7 +273,6 @@ public struct Carousel: View where Content: View { if self.isSnapping { let itemWidth: CGFloat = (viewSize.width - CGFloat(self.numberOfColumns + 2) * self.spacing) / CGFloat(self.numberOfColumns) let index = (expectedX / (itemWidth + self.spacing)).rounded() - // finalX = max(0, min(maxX, index * (itemWidth + self.spacing) - self.spacing)) finalX = max(0, min(maxX, index * (itemWidth + self.spacing))) }