Skip to main content

Input, zoom and pan

Drawing policy​

drawingPolicy decides which touches draw.

PolicyDraws withPans with
anyInputFinger or stylusTwo fingers (also pinch)
stylusOnlyStylus onlyOne finger

anyInput is the default. While a stylus draws, other touches are ignored (palm rejection).

<SketchCanvas drawingPolicy="stylusOnly" maximumZoom={4} layout={{ flex: 1 }} />

Zoom​

minimumZoom and maximumZoom both default to 1, so zoom is off until you raise maximumZoom. The limits must satisfy 0 < minimumZoom <= maximumZoom; anything else throws.

<SketchCanvas minimumZoom={0.5} maximumZoom={8} layout={{ flex: 1 }} />

Content size​

contentSize sets the scrollable area in content points. Without it, the content is the size of the view. Values must be finite and not negative.

<SketchCanvas contentSize={{ width: 2000, height: 3000 }} maximumZoom={4} layout={{ flex: 1 }} />

Viewport​

The Viewport is { zoom, x, y }: the scale and the content point shown at the view's top-left corner.

  • Read it with controller.viewport.
  • Follow it with onViewportChange or controller.addOnViewportChangeListener.
  • Set it with controller.setViewport(viewport). The value is clamped to the zoom limits and the content size; non-finite values throw.
const canvas = useRef<CanvasController>(null)

// Reset zoom and scroll.
canvas.current?.setViewport({ zoom: 1, x: 0, y: 0 })

Touch down​

onTouchDown fires when a finger or stylus first touches the canvas, whether it then draws, pans or moves the ruler. Use it to dismiss popups, such as the tool picker's options card.