Skip to content Skip to sidebar Skip to footer

How To Draw On The Screen With React Native?

I'm trying to implement an android drawing app in react native. I'm using the PanResponder but I don't know how to get the coordinates of the part that the user has touched. I've

Solution 1:

I had issues with all of the other offerings that I could see, especially when upgrading to IOS14 (beta) I could not find any that worked anymore with my project.

I instead created my own drawing component based on pure JavaScript and HTML Canvas. This component has a transparent background so can be overlayed onto any background as well. This also works in online and offline modes.

in it's simplest form you can initialise like this

import RNDrawOnScreen from 'react-native-draw-on-screen';

<RNDrawOnScreen
   penColor={'#000'}
   strokeWidth={20}
/>

If you pass in a parameter for penColor and strokeWidth these will automatically change when they are updated. You can also call undo and clear methods.

This is Expo friendly and works on IOS/Android only having one dependancy of react-native-webview in order to render the view.

I have created an npm package for this, hopefully others may find it useful. Included in the package is an example simple expo app which uses the component and creates the simple drawing app shown in the screenshot.

https://www.npmjs.com/package/react-native-draw-on-screen

enter image description here


Post a Comment for "How To Draw On The Screen With React Native?"