Skip to content

Commit

Permalink
feat: Add UPC-A support (#2563)
Browse files Browse the repository at this point in the history
* Add UPC_A support

* Add documentation for UPC-A on iOS

* Doc adjustments

---------

Co-authored-by: Keaton Roux <keaton@codehesion.co.za>
  • Loading branch information
Gambitboy and Keaton Roux committed Mar 18, 2024
1 parent 8e1f039 commit 97941a9
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 0 deletions.
19 changes: 19 additions & 0 deletions docs/docs/guides/CODE_SCANNING.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -130,4 +130,23 @@ The Code Scanner will call your [`onCodeScanned`](/docs/api/interfaces/CodeScann

<br />

## UPC-A vs EAN-13 codes

UPC-A is a special case to handle if you need to cater for it. Android's SDK officially supports UPC-A but iOS does not, instead they handle the code as EAN-13. Since EAN-13 is a superset of UPC-A, with an extra 0 digit at the front.

This means, the `upc-a` types are reported under the `ean-13` umbrella type on iOS:

```jsx
const codeScanner = useCodeScanner({
codeTypes: ['upc-a'], // <-- ✅ We configure for 'upc-a' types
onCodeScanned: (codes) => {
for (const code of codes) {
console.log(code.type); // <-- ❌ On iOS, we receive 'ean-13'
}
}
})
```

You will need to keep this in mind and do the conversion from EAN-13 to UPC-A yourself. This can be done by removing the front `0` digit from the code to get a UPC-A code.

#### 🚀 Next section: [Frame Processors](frame-processors)
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ enum class CodeType(override val unionValue: String) : JSUnionValue {
EAN_8("ean-8"),
ITF("itf"),
UPC_E("upc-e"),
UPC_A("upc-a"),
QR("qr"),
PDF_417("pdf-417"),
AZTEC("aztec"),
Expand All @@ -29,6 +30,7 @@ enum class CodeType(override val unionValue: String) : JSUnionValue {
EAN_8 -> Barcode.FORMAT_EAN_8
ITF -> Barcode.FORMAT_ITF
UPC_E -> Barcode.FORMAT_UPC_E
UPC_A -> Barcode.FORMAT_UPC_A
QR -> Barcode.FORMAT_QR_CODE
PDF_417 -> Barcode.FORMAT_PDF417
AZTEC -> Barcode.FORMAT_AZTEC
Expand All @@ -47,6 +49,7 @@ enum class CodeType(override val unionValue: String) : JSUnionValue {
Barcode.FORMAT_EAN_8 -> EAN_8
Barcode.FORMAT_ITF -> ITF
Barcode.FORMAT_UPC_E -> UPC_E
Barcode.FORMAT_UPC_A -> UPC_A
Barcode.FORMAT_QR_CODE -> QR
Barcode.FORMAT_PDF417 -> PDF_417
Barcode.FORMAT_AZTEC -> AZTEC
Expand All @@ -64,6 +67,7 @@ enum class CodeType(override val unionValue: String) : JSUnionValue {
"ean-8" -> EAN_8
"itf" -> ITF
"upc-e" -> UPC_E
"upc-a" -> UPC_A
"qr" -> QR
"pdf-417" -> PDF_417
"aztec" -> AZTEC
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ extension AVMetadataObject.ObjectType {
case "upc-e":
self = .upce
return
case "upc-a":
self = .ean13
return
case "qr":
self = .qr
return
Expand Down
1 change: 1 addition & 0 deletions package/src/CodeScanner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export type CodeType =
| 'ean-8'
| 'itf'
| 'upc-e'
| 'upc-a'
| 'qr'
| 'pdf-417'
| 'aztec'
Expand Down

0 comments on commit 97941a9

Please sign in to comment.