Barcode lib not working on native

I tried this lib and it works in the editor and in the web version. However when the app is loaded on my iphone, the barcode is not loaded and there's a placeholder.

Is this not supported for the native app?

editor / web version:

iOS:

I doubt this would work -- we don't give you access to the React Native renderer. Can you share how you integrated it?

Barcode returns this toDataURL.

Seems like that in the native app it doesn’t work. Must be using some browser dependency.


let canvas = document.createElement('canvas');
try {
    bwipjs.toCanvas(canvas, {
      bcid:        'code128',       // Barcode type
      text:        '#TS-102',    // Text to encode
      scale:       2,               // 3x scaling factor
      height:      13,              // Bar height, in millimeters
      width:      14,
      includetext: true,            // Show human-readable text
      textxalign:  'center',        // Always good to set this
      padding: 5,
        });
    return canvas.toDataURL('image/png');
} catch (e) {
    // `e` may be a string or Error object
}

@Steven_W do you mind trying again today? A couple days ago we updated the code such that all your JS is run in a headless browser, which should have all these browser APIs like canvas, document.createElement etc.

If that doesn't work it's probably a more subtle issue unfortunately, and would require deeper investigation.

It’s not working. I do not get any error in the mobile console though. Just a placeholder.

When I replace the code with a base64 string it displays the barcode image of course. So it seems somewhere something doesn’t work with this lib :confused: but no exception is thrown.

Seems like the document.createElement isn’t supported

Seems like @bradlymathews also needed dom access:

If support was added, why doesn’t it work? Do I need to toggle some beta feature?

@Steven_W it should be on for all cloud users... is it possible you're running onprem or perhaps using an old client build?

(edit: just tested and document.createElement('canvas').toDataURL('image/png') does work)

(edit 2: we have reason to believe we failed to actually enable it for all of cloud, investigating...)

(edit 3: ok the feature should be properly rolled out to 100% of cloud now.)

2 Likes

@Steven_W Would you mind testing and letting us know if it works now?

:sob: it works. I’m so happy! Thank you for your help.

1 Like

Awesome @Steven_W! Thank you @bca!