Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue while creating EAN 13 barcode #17

Open
sukhdeep540 opened this issue Aug 6, 2017 · 22 comments
Open

Issue while creating EAN 13 barcode #17

sukhdeep540 opened this issue Aug 6, 2017 · 22 comments

Comments

@sukhdeep540
Copy link

Every time when i choose the format EAN 13, I got the error "undefined is not an object(evaluating binary.length)"

screen shot 2017-08-07 at 2 58 28 am

@sukhdeep540
Copy link
Author

I am facing the same issue with UPC barcode.
All other formats are working fine.

@andreyvital
Copy link
Contributor

@sukhdeep540 have you tried adding flat prop?

<Barcode value="..." format="EAN13" flat />

@Benjamin-Lin-X
Copy link

I add "flat", then it works! Thank you very much.
But also I set the text for ean13, there has no string.

How can I create a ean13 barcode with text?
like a sample in JsBarcode:
EAN13 with text

@cdesch
Copy link

cdesch commented Dec 31, 2017

I get a similar error when doing the EAN13 regarding the length. I added the flat parameter and got the ARTSurfaceView error

      <Barcode value={this.props.session.currentUser.card} format="EAN13" flat  />

screen shot 2017-12-31 at 2 56 38 pm

@wumke
Copy link

wumke commented Feb 9, 2018

see bartgryszko/react-native-circular-progress#23, dionysiusmarquis answer on 1 Jun 2016:

Add the ART lib, use flat, it will work!

@cdesch
Copy link

cdesch commented Feb 9, 2018

This is the code that worked:

  <Barcode value={this.props.session.currentUser.card} 
                    format="EAN13" 
                    flat 
                    width="2" 
                    text={this.props.session.currentUser.card} />

@tablee425
Copy link

This is still not fixed.

@tablee425
Copy link

Is there anyone implemented EAN-13 barcode builder by using this library?

@cdesch
Copy link

cdesch commented May 31, 2018

@emzarichab What error did you get?

@valerusg
Copy link

valerusg commented Sep 12, 2019

I accomplish to build EAN-13 barcode using this library.
The 'react-native-svg' is required. Uses 'svg' to draw the lines.
First of all add the 'svg' library: yarn add react-native-svg and link the library.

This code worked:
<Barcode flat width={3} height={150} value={cardCode} format={'EAN13'} text={cardCode} />

To fix the ART lib missing on iOS:
ReactNative > 0.60: yarn add @react-native-community/art && cd ios && pod install,
ReactNative < 0.60: https://github.com/cornade/linkART

@thaiphamvan
Copy link

I accomplish to build EAN-13 barcode using this library.
The 'react-native-svg' is required. Uses 'svg' to draw the lines.
First of all add the 'svg' library: yarn add react-native-svg and link the library.

This code worked:
<Barcode flat width={3} height={150} value={cardCode} format={'EAN13'} text={cardCode} />

To fix the ART lib missing on iOS:
ReactNative > 0.60: yarn add @react-native-community/art && cd ios && pod install,
ReactNative < 0.60: https://github.com/cornade/linkART

and Android?

@cdesch
Copy link

cdesch commented Dec 18, 2019

@thaiphamvan What do you do for RN > 60 that is running Expo?

@prowseed
Copy link

prowseed commented Dec 31, 2019

@thaiphamvan What do you do for RN > 60 that is running Expo?

I have rewrote the library to use svg instead of ART, took me like 5-10 minutes to do so :) It makes internally svg code already. Basically you need two essential things:

  1. react-native-svg library

import Svg, { G, Rect, Path } from 'react-native-svg';

  1. change render function to use svg
<Svg height="80" width="100%" viewBox="0 0 100 100" preserveAspectRatio="xMinYMin">
	<Path :d="bars.join('')" :fill="lineColor" />
</Svg>

PS: Check this pull request: 8927951

@cdesch
Copy link

cdesch commented Jan 2, 2020

@prowseed lol. thats my own pull request [#50] to use SVG. 👍

In the meantime, you can use my fork

@prowseed
Copy link

prowseed commented Jan 3, 2020

@prowseed lol. thats my own pull request [#50] to use SVG. 👍

In the meantime, you can use my fork

haha, that's bizarre :D I needed some tweaks in the library so i had to rewrite it in vue native anyway, but big thank you for that changes and yet too bad it's still not merged...

@thaiphamvan
Copy link

@thaiphamvan What do you do for RN > 60 that is running Expo?

I solved it with webview.

@thaiphamvan
Copy link

export default class BarCode extends React.Component<BarCodeProps, BarCodeState> {
constructor(props: BarCodeProps) {
super(props);
this.state = {
};
}
_getHtml = () => {
const jsBarCodeLib = <script src="https://cdn.jsdelivr.net/jsbarcode/3.6.0/JsBarcode.all.min.js"></script>;
let html = <!doctype html> <html> <head> <meta name="viewport" content="width=device-width, initial-scale=1.0"> </head> <body style="height: 100%;width: 100%;margin: 0;padding: 0;overflow: hidden"> <svg id="barcode"></svg> ${jsBarCodeLib} <script> JsBarcode("#barcode", ${this.props.value}, { format: "${this.props.format}", width: ${this.props.widthBarCode ? this.props.widthBarCode : 2}, height: ${ this.props.heightBarCode ? this.props.heightBarCode : 40 }, displayValue: true, lineColor:"${this.props.lineColor ? this.props.lineColor : '#000'}" }); </script> </body> </html>;
return html;
};
public render() {
return (

<WebView
originWhitelist={['*']}
source={{ html: this._getHtml() }}
javaScriptEnabled={true}
/>

);
}
}

@vksgautam1
Copy link

This is the code that worked:

  <Barcode value={this.props.session.currentUser.card} 
                    format="EAN13" 
                    flat 
                    width="2" 
                    text={this.props.session.currentUser.card} />

tried this code but still not showing in EAN13 format

@vksgautam1
Copy link

I add "flat", then it works! Thank you very much.
But also I set the text for ean13, there has no string.

How can I create a ean13 barcode with text?
like a sample in JsBarcode:
EAN13 with text

i wanna show my barcode like this

@wonsikin
Copy link
Owner

#53

@carloscuesta
Copy link

carloscuesta commented Jun 19, 2020

So basically this library can't render EAN13 without the flat prop 😕 @wonsikin

That's right and have been confirmed by him at:

#4 (comment)

@carloscuesta
Copy link

After investigating the issue a little bit:

I found out where's the problem on the code:

const binary = encoding.data;

This assumes that always the flat prop is provided to get the following binary encoding format:

Screenshot 2020-06-19 at 09 59 58

If you do not provide the flat prop an array of Objects is what is returned from JSBarCode.

Screenshot 2020-06-19 at 09 59 34

Clearly in this case you can't make binary.length because binary is an Array<Object>. So basically yes, this library does not supports rendering non flat Barcodes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests