{"id":20529481,"url":"https://github.com/bmcmahen/react-gesture-responder","last_synced_at":"2025-04-07T15:07:55.924Z","repository":{"id":34850419,"uuid":"184454589","full_name":"bmcmahen/react-gesture-responder","owner":"bmcmahen","description":"a gesture responder system for your react application","archived":false,"fork":false,"pushed_at":"2022-12-09T21:50:10.000Z","size":4229,"stargazers_count":115,"open_issues_count":30,"forks_count":15,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-04T19:56:19.634Z","etag":null,"topics":["gesture","hooks","react","touch"],"latest_commit_sha":null,"homepage":"http://react-gesture-responder.netlify.com","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/bmcmahen.png","metadata":{"files":{"readme":"Readme.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-05-01T17:31:30.000Z","updated_at":"2024-04-30T09:31:08.000Z","dependencies_parsed_at":"2023-01-15T09:45:27.832Z","dependency_job_id":null,"html_url":"https://github.com/bmcmahen/react-gesture-responder","commit_stats":null,"previous_names":["bmcmahen/pan-responder-hook"],"tags_count":15,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bmcmahen%2Freact-gesture-responder","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bmcmahen%2Freact-gesture-responder/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bmcmahen%2Freact-gesture-responder/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bmcmahen%2Freact-gesture-responder/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/bmcmahen","download_url":"https://codeload.github.com/bmcmahen/react-gesture-responder/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247675597,"owners_count":20977376,"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":["gesture","hooks","react","touch"],"created_at":"2024-11-15T23:32:15.848Z","updated_at":"2025-04-07T15:07:55.900Z","avatar_url":"https://github.com/bmcmahen.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003cdiv align=\"center\"\u003e\n     \u003cimg \n    max-width=\"300px\"\n    alt=\"A demo showing a ball being pulled around, released, and animating back into place.\"\n     src=\"https://raw.githubusercontent.com/bmcmahen/react-gesture-responder/master/demo.gif\"\u003e\u003cbr /\u003e\n\n# react-gesture-responder\n\n[![npm package](https://img.shields.io/npm/v/react-gesture-responder/latest.svg)](https://www.npmjs.com/package/react-gesture-responder)\n[![Follow on Twitter](https://img.shields.io/twitter/follow/benmcmahen.svg?style=social\u0026logo=twitter)](https://twitter.com/intent/follow?screen_name=benmcmahen)\n\n\u003c/div\u003e\n\n`react-gesture-responder` offers a gesture responder system for your react application. It's heavily inspired by [react-native's](https://facebook.github.io/react-native/docs/gesture-responder-system.html) pan-responder. It's built for use in [Sancho-UI](https://github.com/bmcmahen/sancho).\n\n[View the demo and website here](http://react-gesture-responder.netlify.com/). \n\nYou can also read how to [create a swipe to like feature](https://benmcmahen.com/building-react-components-with-gesture-support/) using react-gesture-responder.\n\n## Features\n\n- **The ability to delegate between multiple overlapping gestures.** This means that you can embed gesture responding views within eachother and provide negotiation strategies between them.\n- **Simple kinematics for gesture based animations.** Values including distance, velocity, delta, and direction are provided through gesture callbacks.\n- **Integrates well with [react-spring](react-spring.io) to create performant animations**.\n- **Built with react-gesture-responder:** [react-gesture-view](https://github.com/bmcmahen/react-gesture-view), [touchable-hook](https://github.com/bmcmahen/touchable-hook), [react-grid-dnd](https://github.com/bmcmahen/react-grid-dnd), [react-gesture-gallery](https://github.com/bmcmahen/react-gesture-gallery), [react-gesture-stack](https://github.com/bmcmahen/react-gesture-stack), [sancho-ui](https://github.com/bmcmahen/sancho).\n\n## Getting started\n\nInstall into your react project using yarn or npm.\n\n```\nyarn add react-gesture-responder\n```\n\nThe example below demonstrates how it can be used in conjunction with `react-spring`.\n\n```jsx\nimport { useSpring, animated } from \"react-spring\";\nimport { useGestureResponder } from \"react-gesture-responder\";\n\nfunction Draggable() {\n  const [{ xy }, set] = useSpring(() =\u003e ({\n    xy: [0, 0]\n  }));\n\n  const { bind } = useGestureResponder({\n    onStartShouldSet: () =\u003e true,\n    onRelease: onEnd,\n    onTerminate: onEnd,\n    onMove: ({ delta }) =\u003e {\n      set({\n        xy: delta,\n        immediate: true\n      });\n    }\n  });\n\n  function onEnd() {\n    set({ xy: [0, 0], immediate: false });\n  }\n\n  return (\n    \u003canimated.div\n      style={{\n        transform: xy.interpolate((x, y) =\u003e `translate3d(${x}px, ${y}px, 0)`)\n      }}\n      {...bind}\n    /\u003e\n  );\n}\n```\n\n## API\n\nOnly one responder can be active at any given time. The `useGesture` hook provides callbacks which allow you to implement a negotiation strategy between competing views.\n\n- `onStartShouldSet: (state, e) =\u003e boolean` - Should the view become the responder upon first touch?\n- `onMoveShouldSet: (state, e) =\u003e boolean` - This is called during any gesture movement on the view. You can return true to claim the responder for that view.\n- `onStartShouldSetCapture: (state, e) =\u003e boolean` - The same as above, but using event capturing instead of bubbling. Useful if you want a parent view to capture the responder prior to children.\n- `onMoveShouldSetCapture: (state, e) =\u003e boolean`.\n- `onTerminationRequest: (state) =\u003e boolean`. - Should we allow the responder to be claimed by another view? This is only called when a parent `onMoveShouldSet` returns true. By default, it returns true.\n\nBy default, if a parent and child both return true from `onStartShouldSet` the child element will claim the responder.\n\nOnce a responder is claimed, other callbacks can be used to provide visual feedback to the user.\n\n- `onGrant: (state, e) =\u003e void` - called when the view claims the responder, typically corresponding with `mousedown` or `touchstart` events.\n- `onMove: (state, e) =\u003e void`\n- `onRelease: (state, e) =\u003e void` - corresponds with `mouseup` or `touchend` events.\n- `onTerminate: (state) =\u003e void` - called when the responder is claimed by another view.\n\n```js\nconst { bind } = useGestureResponder(\n  {\n    onStartShouldSet: state =\u003e true,\n    onStartShouldSetCapture: state =\u003e false,\n    onMoveShouldSet: state =\u003e false,\n    onMoveShouldSetCapture: state =\u003e false,\n    onTerminationRequest: state =\u003e true,\n    onGrant: state =\u003e {},\n    onRelease: state =\u003e {},\n    onTerminate: state =\u003e {},\n    onMove: state =\u003e {}\n  },\n  {\n    uid: \"a-unique-id\",\n    enableMouse: true\n  }\n);\n```\n\n`state` contains the following values:\n\n```js\nexport interface StateType {\n  time: number;\n  xy: [number, number];\n  delta: [number, number];\n  initial: [number, number];\n  previous: [number, number];\n  direction: [number, number];\n  initialDirection: [number, number];\n  local: [number, number];\n  lastLocal: [number, number];\n  velocity: number;\n  distance: number;\n}\n```\n\n## Prior art\n\n- [react-native-web](https://github.com/necolas/react-native-web/blob/master/packages/react-native-web/src/vendor/react-native/PanResponder/index.js)\n- [react-with-gesture](https://github.com/react-spring/react-use-gesture) for some of the kinematics.\n\n## License\n\nMIT\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbmcmahen%2Freact-gesture-responder","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbmcmahen%2Freact-gesture-responder","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbmcmahen%2Freact-gesture-responder/lists"}