Skip to content
Advertisement

Expo + React Native: Draw line between coordinates on two type of views

I am currently using this module: https://github.com/mxmzb/react-native-gesture-detector. I want to be able to draw a line from the points created. however, it only seems to output circles.

It has a “Create Gesture” view:

JavaScript

GesturePath is defined like so:

JavaScript

When you draw on that view, it outlines the path using dots, like so:

enter image description here

I would like it to be a smooth line and not a series of circles that the above image.

Advertisement

Answer

You are going to need something like a Canvas to draw lines instead of pixels (with Views). React Native does not currently come with a Canvas implementation.

The easiest way to do this in expo is to use the react-native-svg library.

Using that, you can draw a polyline from your gesture data with the following implementation:

JavaScript

You can also record gestures without the react-native-gesture-detector library by using the in-built React Native PanResponder. Here is an example:

JavaScript

See this snack for a working App tying everything together: https://snack.expo.io/@mtkopone/draw-gesture-path

User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement