Skip to main content

Advanced Configurations

Customize the Overlay Appearance

To customize the appearance of the overlay, you can implement a LabelCaptureBasicOverlayListener.

The method brushForLabel() is called every time a label captured and brushForField() is called for each of its fields to determine the brush for the label or field.

const overlayListener = useMemo<LabelCaptureBasicOverlayListener>(() => ({
brushForFieldOfLabel: (_, field) => {
switch (field.name) {
case "<your-barcode-field-name>":
return new Brush(
"rgba(0, 255, 255, 0.5)",
"rgba(0, 255, 255, 0.5)",
0)
case "<your-expiry-date-field-name>":
return new Brush(
"rgba(255, 165, 0, 0.5)",
"rgba(255, 165, 0, 0.5)",
0)
default:
return new Brush(
Colors.transparentColor,
Colors.transparentColor,
0)
},
brushForLabel() {
return new Brush(Colors.transparentColor, Colors.transparentColor, 0)
},
didTapLabel() {
/*
* Handle user tap gestures on the label.
*/
}
}), [])

useEffect(() => {
/*
* Assign the overlay listener to the overlay
* before adding it to the data capture view.
*/
overlay.listener = overlayListener
const dataCaptureView = dataCaptureViewRef.current
dataCaptureView.addOverlay(overlay)
return () => {
/*
* Unassign the overlay listener from the overlay
* before removing it from the data capture view.
*/
overlay.listener = null
dataCaptureView?.removeOverlay(overlay)
}
}, [])
tip

Use brush colors with transparency (alpha < 100%) to not occlude the captured barcodes or texts.