feat: Add UPC-A support (#2563)

* Add UPC_A support

* Add documentation for UPC-A on iOS

* Doc adjustments

---------

Co-authored-by: Keaton Roux <keaton@codehesion.co.za>
This commit is contained in:
Keaton Roux 2024-03-18 16:42:57 +02:00 committed by GitHub
parent 8e1f03907b
commit 97941a919f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 27 additions and 0 deletions

View File

@ -130,4 +130,23 @@ The Code Scanner will call your [`onCodeScanned`](/docs/api/interfaces/CodeScann
<br /> <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) #### 🚀 Next section: [Frame Processors](frame-processors)

View File

@ -13,6 +13,7 @@ enum class CodeType(override val unionValue: String) : JSUnionValue {
EAN_8("ean-8"), EAN_8("ean-8"),
ITF("itf"), ITF("itf"),
UPC_E("upc-e"), UPC_E("upc-e"),
UPC_A("upc-a"),
QR("qr"), QR("qr"),
PDF_417("pdf-417"), PDF_417("pdf-417"),
AZTEC("aztec"), AZTEC("aztec"),
@ -29,6 +30,7 @@ enum class CodeType(override val unionValue: String) : JSUnionValue {
EAN_8 -> Barcode.FORMAT_EAN_8 EAN_8 -> Barcode.FORMAT_EAN_8
ITF -> Barcode.FORMAT_ITF ITF -> Barcode.FORMAT_ITF
UPC_E -> Barcode.FORMAT_UPC_E UPC_E -> Barcode.FORMAT_UPC_E
UPC_A -> Barcode.FORMAT_UPC_A
QR -> Barcode.FORMAT_QR_CODE QR -> Barcode.FORMAT_QR_CODE
PDF_417 -> Barcode.FORMAT_PDF417 PDF_417 -> Barcode.FORMAT_PDF417
AZTEC -> Barcode.FORMAT_AZTEC AZTEC -> Barcode.FORMAT_AZTEC
@ -47,6 +49,7 @@ enum class CodeType(override val unionValue: String) : JSUnionValue {
Barcode.FORMAT_EAN_8 -> EAN_8 Barcode.FORMAT_EAN_8 -> EAN_8
Barcode.FORMAT_ITF -> ITF Barcode.FORMAT_ITF -> ITF
Barcode.FORMAT_UPC_E -> UPC_E Barcode.FORMAT_UPC_E -> UPC_E
Barcode.FORMAT_UPC_A -> UPC_A
Barcode.FORMAT_QR_CODE -> QR Barcode.FORMAT_QR_CODE -> QR
Barcode.FORMAT_PDF417 -> PDF_417 Barcode.FORMAT_PDF417 -> PDF_417
Barcode.FORMAT_AZTEC -> AZTEC Barcode.FORMAT_AZTEC -> AZTEC
@ -64,6 +67,7 @@ enum class CodeType(override val unionValue: String) : JSUnionValue {
"ean-8" -> EAN_8 "ean-8" -> EAN_8
"itf" -> ITF "itf" -> ITF
"upc-e" -> UPC_E "upc-e" -> UPC_E
"upc-a" -> UPC_A
"qr" -> QR "qr" -> QR
"pdf-417" -> PDF_417 "pdf-417" -> PDF_417
"aztec" -> AZTEC "aztec" -> AZTEC

View File

@ -40,6 +40,9 @@ extension AVMetadataObject.ObjectType {
case "upc-e": case "upc-e":
self = .upce self = .upce
return return
case "upc-a":
self = .ean13
return
case "qr": case "qr":
self = .qr self = .qr
return return

View File

@ -12,6 +12,7 @@ export type CodeType =
| 'ean-8' | 'ean-8'
| 'itf' | 'itf'
| 'upc-e' | 'upc-e'
| 'upc-a'
| 'qr' | 'qr'
| 'pdf-417' | 'pdf-417'
| 'aztec' | 'aztec'