<Button onClick={handleBarcodeScan} primary >Scan Barcode</Button>
const handleBarcodeScan = () => {
scanBarcode(
app,
function (barcode) {
// do what we need
},
setToastErrorMessage
);
};
export const scanBarcode = (app, successCallback, failureCallback) => {
try {
const scanner = Scanner.create(app);
const features = Features.create(app);
// Subscribe to the update action (triggered when the permission dialog is interacted with)
features.subscribe(Features.Action.UPDATE, function (payload) {
if (payload.feature[Scanner.Action.OPEN_CAMERA]) {
available = payload.feature[Scanner.Action.OPEN_CAMERA].Dispatch;
// If the Camera Scanner actions were enabled, open a Scanner
if (available) {
scanner.dispatch(Scanner.Action.OPEN_CAMERA)
} else {
failureCallback("Camera scanner not available.");
}
}
});
// Dispatch an action to request access to Scanner actions
features.dispatch(Features.Action.REQUEST, {
feature: Group.Scanner,
action: Scanner.Action.OPEN_CAMERA
});
scanner.subscribe(Scanner.Action.CAPTURE, (payload) => {
successCallback(payload.data.scanData);
});
} catch (err) {
failureCallback("Camera scanner not available.");
}
};
This works but Shopify Scanner action scans a single barcode and then ends.
We don't want to let customers click the "Scan Barcode" button every time.
We need the user to be able to scan scan scan scan again and again until they choose to stop like Shopify's Inventory Scanner
Describe alternatives you've considered
We are considering other OS libraries for barcode scan.
Describe the feature you’d like
This works but Shopify Scanner action scans a single barcode and then ends. We don't want to let customers click the "Scan Barcode" button every time. We need the user to be able to scan scan scan scan again and again until they choose to stop like Shopify's Inventory Scanner
Describe alternatives you've considered
We are considering other OS libraries for barcode scan.