Skip to main content

Inks and tools

The canvas has one active Tool. Pass it as SketchCanvas's tool prop; change the prop to switch tools.

type Tool =
| { type: 'ink'; ink: InkType; color: number; width: number }
| { type: 'eraser'; mode: EraserMode; width: number }
| { type: 'lasso' }

Widths are content points. Colours are 0xRRGGBBAA. Without a tool prop the canvas draws with { type: 'ink', ink: 'pen', color: 0x000000ff, width: 4 }.

Inks​

InkBehaviour
penOpaque; width follows pressure (or speed with a finger).
monolineOpaque, constant width; ignores pressure and speed.
fountainPenOpaque, with a 45° broad nib: broad across the nib, a hairline along it; pressure adds weight.
markerTranslucent highlighter of constant width.
pencilGrainy; widens with stylus tilt.
crayonWaxy with paper-grain gaps; widens with stylus tilt.
watercolorTranslucent wash with soft edges and pigment blooms; overlapping strokes darken. Width follows pressure.
<SketchCanvas
tool={{ type: 'ink', ink: 'fountainPen', color: 0x1e3a8aff, width: 6 }}
layout={{ flex: 1 }}
/>

The canvas reads pressure, tilt and nib direction, and uses coalesced and predicted touches for low latency. Each sample is stored as a StrokePoint.

info

SVG and PDF exports draw pencil, crayon and watercolor strokes flat, without their texture and soft edges. PNG and JPEG keep them.

Erasers​

ModeEffect
strokeRemoves every stroke the eraser touches.
pixelCuts away only the touched parts of strokes.

width is the eraser's diameter in content points.

<SketchCanvas tool={{ type: 'eraser', mode: 'pixel', width: 16 }} layout={{ flex: 1 }} />

Lasso​

{ type: 'lasso' } selects strokes by drawing a loop around them. Drag the selection to move it. See Selection for deleting, duplicating and recolouring it from code.

Setting tools imperatively​

The tool prop calls these CanvasController methods for you. Use them directly only when you drive the canvas without the prop.

MethodEquivalent tool
setInkingTool(ink){ type: 'ink', ink: ink.type, color, width }
setEraserTool(mode, width){ type: 'eraser', mode, width }
setLassoTool(){ type: 'lasso' }

setInkingTool throws when the width is not above zero.