ThermalPrinterEncoder icon indicating copy to clipboard operation
ThermalPrinterEncoder copied to clipboard

Does this library support react native?

Open serhii-yalla opened this issue 1 year ago • 12 comments

If so, what version is it support? For my case, I am on 0.75.3 version of react native.

serhii-yalla avatar Oct 01 '24 11:10 serhii-yalla

BTW. Tried latest 3.0.1 version. Built successful, but not working. Code that calling class construct display that.

 (NOBRIDGE) ERROR  [ReferenceError: Property 'structuredClone' doesn't exist] 

serhii-yalla avatar Oct 01 '24 15:10 serhii-yalla

Apparently Hermes does not support structuredClone()... which is a bit surprising. https://github.com/facebook/hermes/issues/684

I'll see if I can include a polyfill in the next update.

NielsLeenheer avatar Oct 01 '24 15:10 NielsLeenheer

@NielsLeenheer May I ask you to add some variants to print images on web and mobile side? Cause I can't find a way to get image data to pass to your image method of escpos builder 🫶

serhii-yalla avatar Oct 02 '24 13:10 serhii-yalla

In the examples directory there are a lot of libraries that can be used with ReceiptPrinterEncoder, and some are plain JavaScript, so I am sure some of them support React Native as well. But I am not familiar with how React Native works, so I can't give you examples of how to use it.

https://github.com/NielsLeenheer/ReceiptPrinterEncoder/tree/main/examples/images

NielsLeenheer avatar Oct 02 '24 14:10 NielsLeenheer

Got something similar: Cannot find 'ImageData' in browser.js (3:18). Expo 51, React Native, 0.74.5, hermes engine. It's try to import an canvas with will not work in RN.

karaushu avatar Oct 17 '24 15:10 karaushu

That main be an issue with the bundler your project is using. ImageData is import from the @canvas/image-data package. That package has two code paths: one for the browser and one for Node. Apparently the bundler picks the path for the browser. And then it expects the browser native ImageData to be there. Which it isn't.

Not sure if that is helpful or not. Maybe the @canvas/image-data package itself is not React Native compatible. If that is the issue then perhaps we can work around it in a future version.

Ideally, for better React Native support I would need a sample project somewhere on Github which I could clone and play around with, without having to learn React Native from the ground up.

NielsLeenheer avatar Oct 25 '24 19:10 NielsLeenheer

You can use Expo Snack, it's an easy way to test lib on real devices. Here is example

karaushu avatar Oct 28 '24 08:10 karaushu

@serhii-yalla @karaushu Were you guys able to figure out if ReceiptPrinterEncoder can work correctly with react-native or not ?

I am also getting the same error around structuredClone as mentioned by @serhii-yalla in above comment.

ibrahimkundlik avatar Dec 04 '24 14:12 ibrahimkundlik

I'm using 2.1.1 as of now because this does not run on RN for me, hopefully ImageData can be replaced/substituted for React Native developers

antoniozh avatar Mar 03 '25 19:03 antoniozh

I have created a PR on @canvas/image-path in order to fix the resolution problem on react-native https://github.com/node-gfx/image-data/pull/4

vasu2001 avatar Oct 14 '25 02:10 vasu2001

I've released ImageData 🚢 1.1.0 / 2025-10-14 which points to the correct file for React Native 🚀

LinusU avatar Oct 14 '25 12:10 LinusU

It works for me with one workaround: I had to redeclare structuredClone, seems like the constructor required it. Thank you!

antoniozh avatar Oct 14 '25 19:10 antoniozh