Skip to content
Merged
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
10 changes: 6 additions & 4 deletions Sources/SwiftUISupport/Modifiers/VelocityDraggingModifier.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ public struct VelocityDraggingModifier: ViewModifier {
For example, return CGSize.zero to put it back to the original position.
*/
public var onEndDragging:
(_ velocity: CGVector, _ offset: CGSize, _ contentSize: CGSize) -> CGSize
(_ velocity: inout CGVector, _ offset: CGSize, _ contentSize: CGSize) -> CGSize

public init(
onEndDragging: @escaping (_ velocity: CGVector, _ offset: CGSize, _ contentSize: CGSize)
onEndDragging: @escaping (_ velocity: inout CGVector, _ offset: CGSize, _ contentSize: CGSize)
-> CGSize = { _, _, _ in .zero }
) {
self.onEndDragging = onEndDragging
Expand Down Expand Up @@ -126,13 +126,15 @@ public struct VelocityDraggingModifier: ViewModifier {
})
.onEnded({ value in

var usingVelocity = self.velocity

let targetOffset: CGSize = handler.onEndDragging(
self.velocity,
&usingVelocity,
self.currentOffset,
self.contentSize
)

let velocity = self.velocity
let velocity = usingVelocity

let distance = CGSize(
width: targetOffset.width - currentOffset.width,
Expand Down