Skip to main content

ToolPicker

function ToolPicker(props: ToolPickerProps): ReactElement

A PencilKit-style tool palette: undo and redo, drawn instruments that rise when selected, a ruler toggle, colour swatches, and a rainbow button for any colour. Tapping the selected ink instrument or eraser opens a card above the bar with its widths and eraser modes. Each instrument remembers its own colour and width while another one is active. See the Tool picker guide.

<ToolPicker
tool={tool}
onToolChange={setTool}
drawing={drawing}
items={['undo', 'redo', 'pen', 'eraser', 'swatches']}
layout={{ position: 'absolute', bottom: 24, alignSelf: 'center' }}
/>

Props​

PropTypeDefaultDescription
toolToolRequiredThe active tool, usually also passed to SketchCanvas's tool.
onToolChange(tool: Tool) => voidRequiredCalled with the tool the user picks. Store it and pass it back as tool.
itemsreadonly ToolPickerItem[]defaultToolPickerItemsControls to show, in bar order. Without 'colorPicker', the swatches stay in the bar at every density.
drawingDrawingThe drawing undo and redo act on. Without it they are hidden.
rulerActivebooleanfalseWhether the canvas shows its ruler.
onRulerActiveChange(rulerActive: boolean) => voidCalled when the ruler item is tapped. Without it the ruler item is hidden.
colorsreadonly number[]defaultPaletteColorsSwatch colours as 0xRRGGBBAA, in two rows in the bar, or in the colour card.
densityToolPickerDensityBy window width'compact' below 500 points, 'comfortable' otherwise.
widthsInstrumentWidthsdefaultInstrumentWidthsWidths offered in the options card.
labelsToolPickerLabelsdefaultToolPickerLabelsEraser mode titles.
themeToolPickerThemelight or dark presetColours and shape; follows the system colour scheme by default.
accessoryReactNodeExtra content at the end of the bar, such as a ToolPickerButton. Scrolls with the controls.
layoutNitroUI layoutLayout of the picker: a column holding the options card, when open, above the bar.
refRef<ToolPickerHandle>Receives a handle to close the options card.

ToolPickerHandle​

interface ToolPickerHandle {
dismissOptions(): void
}

dismissOptions() closes the options card (widths, eraser modes or colours) when it is open. Call it from SketchCanvas's onTouchDown.

ToolPickerItem​

type ToolPickerItem = Instrument | 'ruler' | 'undo' | 'redo' | 'swatches' | 'colorPicker'

type Instrument =
| 'pen'
| 'marker'
| 'pencil'
| 'monoline'
| 'fountainPen'
| 'watercolor'
| 'crayon'
| 'eraser'
| 'lasso'

defaultToolPickerItems, in bar order:

;[
'undo',
'redo',
'pen',
'monoline',
'fountainPen',
'marker',
'pencil',
'crayon',
'watercolor',
'eraser',
'lasso',
'ruler',
'swatches',
'colorPicker',
]

ToolPickerDensity​

type ToolPickerDensity = 'compact' | 'comfortable' | 'spacious'
DensityBar heightSwatchButtonSwatches in bar
compact642628❌
comfortable803032✅
spacious963436✅

Sizes are in points.

InstrumentWidths​

Stroke widths in content points for each ink and the pixel eraser, thinnest first. defaultInstrumentWidths:

FieldDefault widths
pen1, 2, 4, 7, 12
marker8, 14, 20, 28, 36
pencil1, 2, 3, 5, 8
monoline1, 2, 3, 5, 8
fountainPen2, 4, 6, 9, 14
watercolor10, 18, 28, 40, 56
crayon4, 7, 10, 15, 22
eraser8, 16, 28, 44, 64

ToolPickerLabels​

FieldDefaultDescription
strokeEraser'Object'Eraser mode that removes whole strokes.
pixelEraser'Pixel'Eraser mode that removes only the touched parts.

defaultPaletteColors​

const defaultPaletteColors: readonly number[] = [
0x000000ff, 0x007affff, 0x34c759ff, 0xffcc00ff, 0xff3b30ff, 0xaf52deff,
]

Black, blue, green, yellow, red and purple.

ToolPickerTheme​

Colours and shape of a ToolPicker and its parts. Start from a preset in toolPickerThemes (light, dark, solidLight, solidDark) and override fields with a spread. See Theming.

FieldTypeDescription
glass{ style: GlassStyle; tint?: ColorValue }Liquid Glass for the bar and options card on iOS 26 and later. Omit for a solid background everywhere.
backgroundColorValueFill of the bar and the options card; with glass, only where glass is unavailable.
borderColorColorValueHairline around the bar and the options card.
borderWidthnumberHairline width in points. 0 removes it.
shadowsreadonly BoxShadow[]Shadows of the bar and the options card, front to back. Skipped where the platform has no shadows.
cornerRadiusnumberCorner radius of the bar in points, capped at half its height (a capsule).
foregroundColorValueGlyphs and labels, and the fill of the selected stroke width.
secondaryForegroundColorValueWidth numbers printed on the instruments and other quiet text.
controlBackgroundColorValueFill of round buttons and of the segmented control.
selectedControlBackgroundColorValueFill of the selected segment.
separatorColorValueHairline around colour swatches, so light colours stay visible.
barrelColorValueInstrument barrel colour.
barrelShadeColorValueBarrel edge colour; the barrel is shaded from this colour to barrel and back.
eraserCapColorValueRubber cap of the eraser.
eraserMarkColorValueMark printed on the eraser.