SketchCanvas
function SketchCanvas(props: SketchCanvasProps): ReactElement
A low-latency ink canvas with pens, erasers, lasso selection, zoom and undo. Touch input never reaches JavaScript; observe results through the callbacks or the CanvasController received through ref.
<SketchCanvas
ref={canvas}
layout={{ flex: 1 }}
drawing={drawing}
tool={{ type: 'ink', ink: 'pen', color: 0x1e88e5ff, width: 4 }}
maximumZoom={8}
onDrawingChange={(changed) => console.log(changed.strokeCount)}
/>
Props
| Prop | Type | Default | Description |
|---|---|---|---|
tool | Tool | Black 4 pt pen | The active tool. |
drawing | Drawing | The canvas's own drawing | The drawing to show and edit. |
drawingPolicy | DrawingPolicy | 'anyInput' | Which touches draw. |
minimumZoom | number | 1 | Smallest zoom. |
maximumZoom | number | 1 | Largest zoom. 1 disables zooming. |
contentSize | Size | The view's own size | Scrollable content size in points. |
rulerActive | boolean | false | Shows the ruler. |
onDrawingChange | (drawing: Drawing) => void | Called after each change of the shown drawing, including undo and redo. | |
onSelectionChange | (selectedStrokeCount: number) => void | Called when the number of selected strokes changes. | |
onViewportChange | (viewport: Viewport) => void | Called when the canvas zooms or scrolls. | |
onTouchDown | () => void | Called when a finger or stylus first touches the canvas, whether it then draws, pans or moves the ruler. | |
ref | Ref<CanvasController> | Receives the canvas's controller once the native view exists. | |
layout, style, other view props | NitroUI SharedViewProps | Everything a NitroUI view takes except children. |
tool
Changing tool switches the canvas's tool. See Inks and tools.
drawing
Passing a new Drawing swaps the drawing the canvas shows and edits. Setting the prop back to undefined keeps the last drawing; it does not reset the canvas.
Behaviour
- With a stylus, other touches are ignored while it draws (palm rejection).
- With
drawingPolicy="stylusOnly", one finger pans; otherwise two fingers pan and pinch. - See Input, zoom and pan for zoom limits and the viewport.