diff --git a/README.md b/README.md index 0541d9f..33f3029 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,8 @@ # SwiftUI - SnapDraggingModifier -This is a small package for SwiftUI that enables the creation of a draggable view and tracks the velocity of the dragging action for use in animations when the drag is released +This is a small SwiftUI package that allows for the creation of a draggable view and tracks the velocity of the dragging action, which can be used to create fluid animations when the drag is released. This component is a big help in creating interactive user interfaces and enhancing their fluidity. + +About Fluid interfaces : https://developer.apple.com/videos/play/wwdc2018/803/ ## Examples @@ -33,3 +35,35 @@ RoundedRectangle(cornerRadius: 16, style: .continuous) ) ) ``` + +--- + +**Thowing to the point** + + + +"The modifier asks for the destination point when the gesture ends, and the view will smoothly move to the specified point with velocity-based animation." + +```swift +RoundedRectangle(cornerRadius: 16, style: .continuous) + .fill(Color.blue) + .frame(width: nil, height: 50) + .modifier( + SnapDraggingModifier( + axis: .horizontal, + horizontalBoundary: .init(min: 0, max: .infinity, bandLength: 50), + handler: .init(onEndDragging: { velocity, offset, contentSize in + + print(velocity, offset, contentSize) + + if velocity.dx > 50 || offset.width > (contentSize.width / 2) { + print("remove") + return .init(width: contentSize.width, height: 0) + } else { + print("stay") + return .zero + } + }) + ) + ) +```