Skip to content

Commit

Permalink
Update README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
muukii authored May 7, 2023
1 parent c681235 commit f88afbc
Showing 1 changed file with 35 additions and 1 deletion.
36 changes: 35 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -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

Expand Down Expand Up @@ -33,3 +35,35 @@ RoundedRectangle(cornerRadius: 16, style: .continuous)
)
)
```

---

**Thowing to the point**

<img width=250 src="https://user-images.githubusercontent.com/1888355/236678943-e6cd9b26-0c5b-407a-8ed1-c1841254cc01.gif" />

"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
}
})
)
)
```

0 comments on commit f88afbc

Please sign in to comment.