{"id":15288697,"url":"https://github.com/fluidgroup/swiftui-gesture-velocity","last_synced_at":"2025-12-11T22:53:31.134Z","repository":{"id":59005182,"uuid":"534981441","full_name":"FluidGroup/swiftui-gesture-velocity","owner":"FluidGroup","description":"In SwiftUI, a property-wrapper provides velocity in pt/s from gesture","archived":false,"fork":false,"pushed_at":"2023-05-06T18:15:16.000Z","size":22,"stargazers_count":42,"open_issues_count":0,"forks_count":2,"subscribers_count":4,"default_branch":"main","last_synced_at":"2025-04-12T05:03:56.480Z","etag":null,"topics":["swiftui"],"latest_commit_sha":null,"homepage":"","language":"Swift","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/FluidGroup.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2022-09-10T11:46:25.000Z","updated_at":"2024-08-26T07:13:51.000Z","dependencies_parsed_at":"2022-09-24T22:21:50.325Z","dependency_job_id":null,"html_url":"https://github.com/FluidGroup/swiftui-gesture-velocity","commit_stats":null,"previous_names":["muukii/swiftui-gesturevelocity","fluidgroup/swiftui-gesturevelocity"],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/FluidGroup%2Fswiftui-gesture-velocity","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/FluidGroup%2Fswiftui-gesture-velocity/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/FluidGroup%2Fswiftui-gesture-velocity/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/FluidGroup%2Fswiftui-gesture-velocity/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/FluidGroup","download_url":"https://codeload.github.com/FluidGroup/swiftui-gesture-velocity/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248674659,"owners_count":21143760,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["swiftui"],"created_at":"2024-09-30T15:52:07.171Z","updated_at":"2025-12-11T22:53:31.100Z","avatar_url":"https://github.com/FluidGroup.png","language":"Swift","funding_links":[],"categories":[],"sub_categories":[],"readme":"# swiftui-GestureVelocity\n\nIn SwiftUI, a property-wrapper provides velocity in pt/s from gesture\n\n\n## Instructions\n\n```swift\n@GestureVelocity private var velocity: CGVector\n```\n\n```swift\n.gesture(\n  DragGesture(...)\n  ... some declarations\n  .updatingVelocity($velocity)\n```\n\n## Example\n\n![CleanShot 2023-04-08 at 16 32 28](https://user-images.githubusercontent.com/1888355/230709515-163918d7-5ef0-47b7-b394-77b18c0c3d54.gif)\n\n\n```swift\nstruct Joystick: View {\n\n  /**\n   ???\n   Use just State instead of GestureState to trigger animation on gesture ended.\n   This approach is right?\n\n   refs:\n   https://stackoverflow.com/questions/72880712/animate-gesturestate-on-reset\n   */\n  @State private var position: CGSize = .zero\n\n  @GestureVelocity private var velocity: CGVector\n\n  var body: some View {\n    stick\n      .padding(10)\n  }\n\n  private var stick: some View {\n    Circle()\n      .fill(Color.blue)\n      .frame(width: 100, height: 100)\n      .animatableOffset(position) // https://github.com/FluidGroup/swiftui-support\n      .gesture(\n        DragGesture(\n          minimumDistance: 0,\n          coordinateSpace: .local\n        )\n        .onChanged({ value in\n          withAnimation(.interactiveSpring()) {\n            position = value.translation\n          }\n        })\n        .onEnded({ value in\n\n          let distance = CGSize(\n            width: -position.width,\n            height: -position.height\n          )\n\n          let mappedVelocity = CGVector(\n            dx: velocity.dx / distance.width,\n            dy: velocity.dy / distance.height\n          )\n          \n          withAnimation(\n            .interpolatingSpring(\n              stiffness: 50,\n              damping: 10,\n              initialVelocity: mappedVelocity.dx\n            )\n          ) {\n            position.width = 0\n          }\n          \n          withAnimation(\n            .interpolatingSpring(\n              stiffness: 50,\n              damping: 10,\n              initialVelocity: mappedVelocity.dy\n            )\n          ) {\n            position.height = 0\n          }\n        })\n        .updatingVelocity($velocity)\n\n      )\n\n  }\n}\n```\n\n## Example\n\n\n```swift\nRoundedRectangle(cornerRadius: 16, style: .continuous)\n  .fill(Color.blue)\n  .frame(width: 100, height: 100)\n  .modifier(VerticalDragModifier())\n```\n\n\n```swift\nstruct VerticalDragModifier: ViewModifier {\n  \n  /**\n   ???\n   Use just State instead of GestureState to trigger animation on gesture ended.\n   This approach is right?\n   \n   refs:\n   https://stackoverflow.com/questions/72880712/animate-gesturestate-on-reset\n   */\n  @State private var position: CGSize = .zero\n  \n  @GestureVelocity private var velocity: CGVector\n  \n  func body(content: Content) -\u003e some View {\n    content\n      .offset(position)\n      .gesture(\n        DragGesture(\n          minimumDistance: 0,\n          coordinateSpace: .local\n        )\n        .onChanged({ value in\n          withAnimation(.interactiveSpring()) {\n            position.height = value.translation.height\n          }\n        })\n        .onEnded({ value in\n          \n          let distance = CGSize(\n            width: -position.width,\n            height: -position.height\n          )\n          \n          let mappedVelocity = CGVector(\n            dx: velocity.dx / distance.width,\n            dy: velocity.dy / distance.height\n          )\n          \n          withAnimation(\n            .interpolatingSpring(\n              stiffness: 50,\n              damping: 10,\n              initialVelocity: mappedVelocity.dy\n            )\n          ) {\n            position.width = 0\n            position.height = 0\n          }\n        })\n        .updatingVelocity($velocity)\n        \n      )\n  }\n  \n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffluidgroup%2Fswiftui-gesture-velocity","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffluidgroup%2Fswiftui-gesture-velocity","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffluidgroup%2Fswiftui-gesture-velocity/lists"}