npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@equinor/react-native-skia-draw

v0.4.2

Published

A React Native drawing library running on SKIA

Downloads

258

Readme

React Native Skia Draw

This library adds basic drawing capabilities for your apps. It features a ready to use Signature Pad and an EDS themed Image Markup tool. The library also exposes functionality for creating your own solution.

🖌️ How to use

The library currently exposes two ready-made (reffered to as premades) solutions.

🖋️ Signature Pad

The Signature Pad component comes with a signature field, a clear button and the ability to create snapshots. A simple implementation looks like this:

import { Button } from "react-native";
import { SignaturePad, CanvasImageControls } from "@equinor/react-native-skia-draw";
import { SkiaDrawSnapshot } from "@equinor/react-native-skia-draw/dist/types";

const MySignaturePad = () => {
    const drawRef = useRef<CanvasImageControls>(null);
    const [myImage, setMyImage] = useState<SkiaDrawSnapshot>();

    const takeSnapshot = () => {
        if (drawRef.current?.makeImageSnapshot) {
            const result = drawRef.current.makeImageSnapshot();
            setMyImage(result);
        }
    };

    return (
        <>
            <SignaturePad ref={drawRef} />
            <Button
                title="Take snapshot!"
                onPress={takeSnapshot} />
        <>
    );
};

👩‍🎨 Image Markup

The Image Markup component comes with a simple control panel for some markup operations (stroke size, color selection, clear and undo), and the ability to draw on top of an imported image. A simple implementation looks like this:

import { Button } from "react-native";
import { ImageMarkup, CanvasImageControls } from "@equinor/react-native-skia-draw";
import { SkiaDrawSnapshot } from "@equinor/react-native-skia-draw/dist/types";

const MyImageMarkup = ({
    myImageAsAnEncodedString,
}:
{
    myImageAsAnEncodedString: string;
}) => {
    const drawRef = useRef<CanvasImageControls>(null);
    const [myImage, setMyImage] = useState<SkiaDrawSnapshot>();

    const takeSnapshot = () => {
        if (drawRef.current?.makeImageSnapshot) {
            const result = drawRef.current.makeImageSnapshot();
            setMyImage(result);
        }
    };

    return (
        <>
            <ImageMarkup
                ref={drawRef}
                markupImage={myImageAsAnEncodedString} />
            <Button
                title="Take snapshot!"
                onPress={takeSnapshot} />
        <>
    );
};

⚙️ Installation

React Native Skia is listed as a peer deendency to this project. This means you will have to install an appropriate version of this on your own. Please refer to the React Native installlation guide for information on how to do this.

🕸️ Web support

Note that React Native Skia has an own setup process for working on the web. Make sure to follow this when adding any solution from this packace to your React Native web project.

Custom implementations

In addition to the premades listed above, this library also lets you create your own design using your own components to control the canvas. Start by making sure that you wrap both your control panel and the canvas inside a CanvasControlProvider:

import { CanvasControlProvider, Canvas } from "@equinor/react-native-skia-draw";

export const MyCustomControlledCanvas = () => (
    <CanvasControlProvider>
        <MyCustomControlPanel />
        <Canvas />
    </CanvasControlProvider>
)

Then, in your custom control panel, tap into the canvas using the controls exported from the useCanvasControl() hook:

import { useCanvasControl } from "@equinor/react-native-skia-draw";

export const MyCustomControlPanel = () => {
    const {
        toolColor,
        setToolColor,
        strokeWeight,
        setStrokeWeight,
        toolType,
        setToolType,
        text,
        setText,
        font,
        undo,
        clear,
    } = useCanvasControl();
    
    return (
        <>
            {/* custom ui here */}
        </>
    )
}