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:
parent
8e1f03907b
commit
97941a919f
@ -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)
|
||||
|
@ -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"),
|
||||
@ -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
|
||||
@ -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
|
||||
@ -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
|
||||
|
@ -40,6 +40,9 @@ extension AVMetadataObject.ObjectType {
|
||||
case "upc-e":
|
||||
self = .upce
|
||||
return
|
||||
case "upc-a":
|
||||
self = .ean13
|
||||
return
|
||||
case "qr":
|
||||
self = .qr
|
||||
return
|
||||
|
@ -12,6 +12,7 @@ export type CodeType =
|
||||
| 'ean-8'
|
||||
| 'itf'
|
||||
| 'upc-e'
|
||||
| 'upc-a'
|
||||
| 'qr'
|
||||
| 'pdf-417'
|
||||
| 'aztec'
|
||||
|
Loading…
Reference in New Issue
Block a user