0.3.23 β€’ Published 3 months ago

@equinor/react-native-skia-draw v0.3.23

Weekly downloads
-
License
MIT
Repository
-
Last release
3 months ago

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 */}
        </>
    )
}
0.3.23

3 months ago

0.3.22

3 months ago

0.3.20

3 months ago

0.3.21

3 months ago

0.3.19

3 months ago

0.3.18

3 months ago

0.3.17

3 months ago

0.3.16

3 months ago

0.3.15

3 months ago

0.3.14

3 months ago

0.3.13

3 months ago

0.3.12

3 months ago

0.3.11

3 months ago

0.3.10

3 months ago

0.3.9

4 months ago

0.3.8

4 months ago

0.3.7

4 months ago

0.3.6

4 months ago

0.3.5

4 months ago

0.3.4

4 months ago

0.3.3

5 months ago

0.3.2

5 months ago

0.3.1

5 months ago

0.3.0

5 months ago

0.2.27

5 months ago

0.2.26

6 months ago

0.2.25

6 months ago

0.2.24

7 months ago

0.2.23

7 months ago

0.2.22

7 months ago

0.2.21

7 months ago

0.2.20

7 months ago

0.2.19

7 months ago

0.2.18

7 months ago

0.2.17

7 months ago

0.2.16

7 months ago

0.2.15

7 months ago

0.2.14

8 months ago

0.2.13

8 months ago

0.2.12

8 months ago

0.2.11

8 months ago

0.2.10

8 months ago

0.2.7

9 months ago

0.2.9

8 months ago

0.2.8

9 months ago

0.2.6

11 months ago

0.2.5

11 months ago

0.2.4

11 months ago

0.2.3

12 months ago

0.2.2

12 months ago

0.2.1

1 year ago

0.2.0

1 year ago

0.1.4

1 year ago

0.1.3

1 year ago

0.1.2

1 year ago

0.1.1

1 year ago

0.1.0

1 year ago

0.0.4

1 year ago

0.0.3

1 year ago

0.0.1

1 year ago