{"id":5853,"date":"2020-11-19T14:23:00","date_gmt":"2020-11-19T14:23:00","guid":{"rendered":"https:\/\/azoora.com\/blog\/?p=5853"},"modified":"2020-11-22T14:33:26","modified_gmt":"2020-11-22T14:33:26","slug":"gesture-detector-detect-complex-gestures-in-react-native","status":"publish","type":"post","link":"https:\/\/azoora.com\/blog\/code\/gesture-detector-detect-complex-gestures-in-react-native\/","title":{"rendered":"Gesture Detector &#8211; Detect Complex Gestures in React Native"},"content":{"rendered":"\n<h2>Description:<\/h2>\n\n\n\n<p>A <strong>React Native<\/strong> component to create and detect custom <strong>complex gestures <\/strong>on <strong>React Native<\/strong> app.<\/p>\n\n\n\n<ul data-carousel-extra='{\"blog_id\":1,\"permalink\":\"https:\\\/\\\/azoora.com\\\/blog\\\/code\\\/gesture-detector-detect-complex-gestures-in-react-native\\\/\"}' class=\"wp-container-2 wp-block-gallery-1 wp-block-gallery columns-3 is-cropped\"><li class=\"blocks-gallery-item\"><figure><img data-attachment-id=\"5854\" data-permalink=\"https:\/\/azoora.com\/blog\/code\/gesture-detector-detect-complex-gestures-in-react-native\/attachment\/detect-complex-gestures-in-react-native-03\/#main\" data-orig-file=\"https:\/\/azoora.com\/blog\/wp-content\/uploads\/2020\/11\/detect-complex-gestures-in-react-native-03.gif\" data-orig-size=\"463,1000\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}\" data-image-title=\"detect-complex-gestures-in-react-native-03\" data-image-description=\"\" data-medium-file=\"https:\/\/azoora.com\/blog\/wp-content\/uploads\/2020\/11\/detect-complex-gestures-in-react-native-03-139x300.gif\" data-large-file=\"https:\/\/azoora.com\/blog\/wp-content\/uploads\/2020\/11\/detect-complex-gestures-in-react-native-03.gif\" loading=\"lazy\" width=\"463\" height=\"1000\" src=\"https:\/\/azoora.com\/blog\/wp-content\/uploads\/2020\/11\/detect-complex-gestures-in-react-native-03.gif\" alt=\"\" data-id=\"5854\" data-full-url=\"https:\/\/azoora.com\/blog\/wp-content\/uploads\/2020\/11\/detect-complex-gestures-in-react-native-03.gif\" data-link=\"https:\/\/azoora.com\/blog\/?attachment_id=5854#main\" class=\"wp-image-5854\"\/><\/figure><\/li><li class=\"blocks-gallery-item\"><figure><img data-attachment-id=\"5855\" data-permalink=\"https:\/\/azoora.com\/blog\/code\/gesture-detector-detect-complex-gestures-in-react-native\/attachment\/detect-complex-gestures-in-react-native-02\/#main\" data-orig-file=\"https:\/\/azoora.com\/blog\/wp-content\/uploads\/2020\/11\/detect-complex-gestures-in-react-native-02.gif\" data-orig-size=\"463,1000\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}\" data-image-title=\"detect-complex-gestures-in-react-native-02\" data-image-description=\"\" data-medium-file=\"https:\/\/azoora.com\/blog\/wp-content\/uploads\/2020\/11\/detect-complex-gestures-in-react-native-02-139x300.gif\" data-large-file=\"https:\/\/azoora.com\/blog\/wp-content\/uploads\/2020\/11\/detect-complex-gestures-in-react-native-02.gif\" loading=\"lazy\" width=\"463\" height=\"1000\" src=\"https:\/\/azoora.com\/blog\/wp-content\/uploads\/2020\/11\/detect-complex-gestures-in-react-native-02.gif\" alt=\"\" data-id=\"5855\" data-full-url=\"https:\/\/azoora.com\/blog\/wp-content\/uploads\/2020\/11\/detect-complex-gestures-in-react-native-02.gif\" data-link=\"https:\/\/azoora.com\/blog\/?attachment_id=5855#main\" class=\"wp-image-5855\"\/><\/figure><\/li><li class=\"blocks-gallery-item\"><figure><img data-attachment-id=\"5856\" data-permalink=\"https:\/\/azoora.com\/blog\/code\/gesture-detector-detect-complex-gestures-in-react-native\/attachment\/detect-complex-gestures-in-react-native-01\/#main\" data-orig-file=\"https:\/\/azoora.com\/blog\/wp-content\/uploads\/2020\/11\/detect-complex-gestures-in-react-native-01.gif\" data-orig-size=\"463,1000\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}\" data-image-title=\"detect-complex-gestures-in-react-native-01\" data-image-description=\"\" data-medium-file=\"https:\/\/azoora.com\/blog\/wp-content\/uploads\/2020\/11\/detect-complex-gestures-in-react-native-01-139x300.gif\" data-large-file=\"https:\/\/azoora.com\/blog\/wp-content\/uploads\/2020\/11\/detect-complex-gestures-in-react-native-01.gif\" loading=\"lazy\" width=\"463\" height=\"1000\" src=\"https:\/\/azoora.com\/blog\/wp-content\/uploads\/2020\/11\/detect-complex-gestures-in-react-native-01.gif\" alt=\"\" data-id=\"5856\" data-full-url=\"https:\/\/azoora.com\/blog\/wp-content\/uploads\/2020\/11\/detect-complex-gestures-in-react-native-01.gif\" data-link=\"https:\/\/azoora.com\/blog\/?attachment_id=5856#main\" class=\"wp-image-5856\"\/><\/figure><\/li><\/ul>\n\n\n\n<h2>How to use it:<\/h2>\n\n\n\n<p>1. Install and import the component.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"># Yarn\n$ yarn add react-native-gesture-detector react-native-gesture-handler lodash<\/pre>\n\n\n\n<pre class=\"wp-block-preformatted\">import GestureDetector, {\n  GestureRecorder,\n  GesturePath,\n  Cursor,\n} from \"react-native-gesture-detector\";<\/pre>\n\n\n\n<p>2. Basic usage:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">const gestures = {\n  \/\/ this will result in the gesture shown in the first demo give above\n  Coil: [\n    { x: 10, y: -30 }, \/\/ This is a coordinate object\n    { x: 25, y: -15 },\n    { x: 40, y: -10 },\n    { x: 55, y: -15 },\n    { x: 70, y: -30 },\n    { x: 85, y: -45 },\n    { x: 90, y: -65 },\n    { x: 85, y: -85 },\n    { x: 70, y: -100 },\n    { x: 55, y: -115 },\n    { x: 40, y: -130 },\n    { x: 20, y: -130 },\n    { x: 0, y: -130 },\n    { x: -20, y: -130 },\n    { x: -35, y: -115 },\n    { x: -50, y: -100 },\n    { x: -65, y: -85 },\n    { x: -80, y: -70 },\n    { x: -80, y: -55 },\n    { x: -80, y: -30 },\n    { x: -80, y: -15 },\n    { x: -80, y: 0 },\n    { x: -65, y: 15 },\n    { x: -50, y: 30 },\n    { x: -35, y: 45 },\n    { x: -20, y: 60 },\n    { x: 0, y: 65 },\n    { x: 20, y: 70 },\n    { x: 40, y: 70 },\n  ],\n};\nconst CoilExample = () =&gt; (\n  &lt;GestureDetector\n    onGestureFinish={(gesture) =&gt; console.log(`Gesture \"${gesture}\" finished!`)}\n    onProgress={({ gesture, progress }) =&gt; {\n      console.log(`Gesture: ${gesture}, progress: ${progress}`);\n    }}\n    onPanRelease={() =&gt; {\n      console.log(\"User released finger!\");\n    }}\n    gestures={gestures}\n    slopRadius={35}\n  &gt;\n    {({ coordinate }) =&gt; (\n      &lt;View style={{ position: \"relative\", width: \"100%\", height: \"100%\" }}&gt;\n        &lt;GesturePath path={gestures[\"Coil\"]} color=\"green\" slopRadius={35} \/&gt;\n        {coordinate &amp;&amp; &lt;Cursor {...coordinate} \/&gt;}\n      &lt;\/View&gt;\n    )}\n  &lt;\/GestureDetector&gt;\n);\nconst RecordGestureExample = () =&gt; {\n  \/\/ finishedGesture will look like gestures[\"Coil\"] from the top\n  const [finishedGesture, setFinishedGesture] = useState([]);\n  return (\n    &lt;GestureRecorder onPanRelease={(gesture) =&gt; setFinishedGesture(gesture)}&gt;\n      {({ gesture }) =&gt; (\n        &lt;View style={{ position: \"relative\", width: \"100%\", height: \"100%\" }}&gt;\n          &lt;GesturePath path={gesture} color=\"green\" slopRadius={35} \/&gt;\n        &lt;\/View&gt;\n      )}\n    &lt;\/GestureRecorder&gt;\n  );\n};<\/pre>\n\n\n\n<blockquote class=\"wp-block-quote\"><p><strong>Author<\/strong>: mxmzb<\/p><p><strong>Live Demo<\/strong>:&nbsp;<a rel=\"noreferrer noopener\" href=\"https:\/\/maximzubarev.com\/projects\/react-native-gesture-detector\" target=\"_blank\">Link<\/a><\/p><p><strong>Download<\/strong>:&nbsp;<a rel=\"noreferrer noopener\" href=\"https:\/\/github.com\/mxmzb\/react-native-gesture-detector\/archive\/master.zip\" target=\"_blank\">Link<\/a><\/p><p><strong>Official Website<\/strong>:&nbsp;<a rel=\"noreferrer noopener\" href=\"https:\/\/github.com\/mxmzb\/react-native-gesture-detector\" target=\"_blank\">Link<\/a><\/p><p><strong>License<\/strong>: MIT<\/p><\/blockquote>\n","protected":false},"excerpt":{"rendered":"<p>Description: A React Native component to create and detect custom complex gestures on React Native app. How to use it: 1. Install and import the component. # Yarn $ yarn add react-native-gesture-detector react-native-gesture-handler lodash import GestureDetector, { GestureRecorder, GesturePath, Cursor, } from &#8220;react-native-gesture-detector&#8221;; 2. Basic usage: const gestures = { \/\/ this will result in [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":5858,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"spay_email":"","jetpack_publicize_message":"","jetpack_is_tweetstorm":false},"categories":[4,145],"tags":[25,146,90,133,17],"jetpack_featured_media_url":"https:\/\/azoora.com\/blog\/wp-content\/uploads\/2020\/11\/React-Native-Gesture-Detector.png","jetpack_publicize_connections":[],"jetpack_shortlink":"https:\/\/wp.me\/p7FQPL-1wp","jetpack-related-posts":[],"jetpack_sharing_enabled":true,"jetpack_likes_enabled":true,"_links":{"self":[{"href":"https:\/\/azoora.com\/blog\/wp-json\/wp\/v2\/posts\/5853"}],"collection":[{"href":"https:\/\/azoora.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/azoora.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/azoora.com\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/azoora.com\/blog\/wp-json\/wp\/v2\/comments?post=5853"}],"version-history":[{"count":2,"href":"https:\/\/azoora.com\/blog\/wp-json\/wp\/v2\/posts\/5853\/revisions"}],"predecessor-version":[{"id":5859,"href":"https:\/\/azoora.com\/blog\/wp-json\/wp\/v2\/posts\/5853\/revisions\/5859"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/azoora.com\/blog\/wp-json\/wp\/v2\/media\/5858"}],"wp:attachment":[{"href":"https:\/\/azoora.com\/blog\/wp-json\/wp\/v2\/media?parent=5853"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/azoora.com\/blog\/wp-json\/wp\/v2\/categories?post=5853"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/azoora.com\/blog\/wp-json\/wp\/v2\/tags?post=5853"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}