Git Product home page Git Product logo

rn-perfect-sketch-canvas's Introduction

rn-perfect-sketch-canvas

A React Native component for drawing perfect pressure-sensitive freehand lines using perfect-freehand and Skia renderer.

Installation

npm install @shopify/react-native-skia rn-perfect-sketch-canvas

Usage

import React, { useRef } from 'react';
import { StyleSheet, SafeAreaView, Button } from 'react-native';
import { SketchCanvas, SketchCanvasRef } from 'rn-perfect-sketch-canvas';

export default function App() {
  const canvasRef = useRef<SketchCanvasRef>(null);

  return (
    <SafeAreaView style={styles.container}>
      <SketchCanvas
        ref={canvasRef}
        strokeColor={'black'}
        strokeWidth={8}
        containerStyle={styles.container}
      />
      <Button onPress={canvasRef.current?.reset} title="Reset" />
    </SafeAreaView>
  );
}

const styles = StyleSheet.create({
  container: {
    flex: 1,
  },
});

Props

Property Type Default Description
containerStyle object {} Styles to be applied on canvas component.
strokeColor string black Color of stroke.
strokeWidth number 8 Size (diameter) of the stroke.
topChildren ReactNode Node to be put on top of sketch
bottomChildren ReactNode Node to be put on bottom of sketch (Background)

Methods

Method Description
reset() Clear all the paths.
undo() Undo
redo() Redo
toBase64(format?: ImageFormat, quality?: number) Get the base64 of image.
toImage() Get a snapshot from the canvas in the surface.
toSvg(width: number, height: number, backgroundColor?: string) Get the svg string of all paths.
toPoints() Get the array of point groups that got drawn in the canvas.
addPoints(points: [x, y][][]) Draws from an array of point groups.

Contributing

See the contributing guide to learn how to contribute to the repository and the development workflow.

Inspired By

Please check out these previous works that helped inspire the creation of rn-perfect-sketch-canvas.

License

MIT

rn-perfect-sketch-canvas's People

Contributors

wobsoriano avatar matobiely avatar palodelincak avatar twanluttik avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.