Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed an issue with ScrollGesture on SwipeView; Improved swipeDelete Transition by adding Move to Leading transition #28

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 31 additions & 21 deletions Sources/SwipeActions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -403,8 +403,19 @@ public struct SwipeView<Label, LeadingActions, TrailingActions>: 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.
Expand Down Expand Up @@ -438,16 +449,10 @@ public struct SwipeView<Label, LeadingActions, TrailingActions>: 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 {
Expand Down Expand Up @@ -501,18 +506,22 @@ public struct SwipeView<Label, LeadingActions, TrailingActions>: 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)
}
}
}
Expand Down Expand Up @@ -1282,6 +1291,7 @@ public extension AnyTransition {
active: SwipeDeleteModifier(visibility: 0),
identity: SwipeDeleteModifier(visibility: 1)
)
.combined(with: .move(edge: .leading))
}
}

Expand Down