From 78795e59178b0e1497839a163f7097b84cdf26ae Mon Sep 17 00:00:00 2001 From: Om Chachad Date: Sat, 2 Nov 2024 10:32:45 +0530 Subject: [PATCH 1/2] Added move to leading transition to swipeDelete --- Sources/SwipeActions.swift | 1 + 1 file changed, 1 insertion(+) diff --git a/Sources/SwipeActions.swift b/Sources/SwipeActions.swift index 60eb846..52cd0e5 100644 --- a/Sources/SwipeActions.swift +++ b/Sources/SwipeActions.swift @@ -1282,6 +1282,7 @@ public extension AnyTransition { active: SwipeDeleteModifier(visibility: 0), identity: SwipeDeleteModifier(visibility: 1) ) + .combined(with: .move(edge: .leading)) } } From 87bee1a0d299db69d061ecf59a4fd0aa5a65575d Mon Sep 17 00:00:00 2001 From: Om Chachad Date: Tue, 18 Feb 2025 21:24:35 +0530 Subject: [PATCH 2/2] Fixed Scrolling Gesture on SwipeView This commit fixes an issue where a SwipeView, when inside a ScrollView, would interfere with the regular system scroll gesture and previously prevent scrolling. Credits for the solution: https://stackoverflow.com/a/79037514 --- Sources/SwipeActions.swift | 51 ++++++++++++++++++++++---------------- 1 file changed, 30 insertions(+), 21 deletions(-) diff --git a/Sources/SwipeActions.swift b/Sources/SwipeActions.swift index 52cd0e5..4e1c037 100644 --- a/Sources/SwipeActions.swift +++ b/Sources/SwipeActions.swift @@ -403,8 +403,19 @@ public struct SwipeView: View where Labe self.leadingActions = leadingActions self.trailingActions = trailingActions } - + public var body: some View { + let dragGesture = DragGesture(minimumDistance: options.swipeMinimumDistance) + .updating($currentlyDragging) { value, state, transaction in + state = true + } + .onChanged(onChanged) + .onEnded(onEnded) + .updatingVelocity($velocity) + + let tapGesture = TapGesture() + .onEnded(reset) + HStack { label() .offset(x: offset) /// Apply the offset here. @@ -438,16 +449,10 @@ public struct SwipeView: View where Labe ) // MARK: - Add gestures - - .highPriorityGesture( /// Add the drag gesture. - DragGesture(minimumDistance: options.swipeMinimumDistance) - .updating($currentlyDragging) { value, state, transaction in - state = true - } - .onChanged(onChanged) - .onEnded(onEnded) - .updatingVelocity($velocity), - including: options.swipeEnabled ? .all : .subviews /// Enable/disable swiping here. + .simultaneousGesture(dragGesture) + .highPriorityGesture( + tapGesture + .exclusively(before: dragGesture) ) .onChange(of: currentlyDragging) { currentlyDragging in /// Detect gesture cancellations. if !currentlyDragging, let latestDragGestureValueBackup { @@ -501,18 +506,22 @@ public struct SwipeView: View where Labe } .onChange(of: swipeViewGroupSelection.wrappedValue) { newValue in if swipeViewGroupSelection.wrappedValue != id { - currentSide = nil + reset() + } + } + } + + func reset() { + currentSide = nil - if leadingState != .closed { - leadingState = .closed - close(velocity: 0) - } + if leadingState != .closed { + leadingState = .closed + close(velocity: 0) + } - if trailingState != .closed { - trailingState = .closed - close(velocity: 0) - } - } + if trailingState != .closed { + trailingState = .closed + close(velocity: 0) } } }