Shopify / shopify-app-bridge

https://shopify.dev/docs/api/app-bridge
82 stars 9 forks source link

Scanning multiple barcode is not supported #258

Open remy727 opened 7 months ago

remy727 commented 7 months ago

Describe the feature you’d like

<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.

jzazove commented 4 months ago

Thanks for this request. We are labeling it as such.