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

Can't use EAN13 format #2

Open
inakineitor opened this issue Oct 18, 2020 · 3 comments
Open

Can't use EAN13 format #2

inakineitor opened this issue Oct 18, 2020 · 3 comments

Comments

@inakineitor
Copy link

inakineitor commented Oct 18, 2020

When I select CODE128 everything works perfectly, but when I choose EAN13 with the following code I get an error:

<DefaultBarcode
  value="7798159715571"
  width={2}
  height={100}
  textColor={text}
  lineColor={text}
  background="#00000000"
  onError={setError}
  format="EAN13"
/>

image

The source line references changes every time, but the undefined is not an object (evaluating 'binary.length') remains the same, so it should be where the error is at.

Any help would be greatly appreciated!

@inakineitor
Copy link
Author

After reviewing the source, I found out that the problem is caused by the drawer now supporting the output format of the EAN13 encoder.
This is the output:

Array [
  Object {
    "data": "101",
    "options": Object {
      "height": NaN,
    },
  },
  Object {
    "data": "011101100101110110111011001101100010010111",
    "options": Object {
      "fontSize": undefined,
    },
    "text": "798159",
  },
  Object {
    "data": "01010",
    "options": Object {
      "height": NaN,
    },
  },
  Object {
    "data": "100010011001101001110100111010001001100110",
    "options": Object {
      "fontSize": undefined,
    },
    "text": "715571",
  },
  Object {
    "data": "101",
    "options": Object {
      "height": NaN,
    },
  },
]

image

The drawSvgBarCode function assumed the encoder output is in a different format.

@inakineitor
Copy link
Author

inakineitor commented Oct 18, 2020

I managed to solve it temporarily by changing line 161 of index.js from

return encoded;

to

return encoded.reduce((p, n) => ({ data: `${p.data}${n.data || ''}`, text: `${p.text}${n.text || ''}` }), { data: '', text: ''});

thus flattening the array data.

I didn't want to use a custom solution on a production project so I ended using this up-to-date fork of react-native-barcode-builder using react-native-svg.

In case the mantainer of this package sees this, I would love to render my barcode as specified in this issue. I am willing to provide any of the help needed :)

@BloodyMonkey
Copy link

I updated with

if(format === "EAN13"){
      return encoded.reduce((p, n) => ({ data: `${p.data}${n.data || ''}`, text: `${p.text}${n.text || ''}` }), { data: '', text: ''});
}
else{
      return encoded
}

To handle others formats than EAN13

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

2 participants