This library is an implementation of GS1 Barcode Syntax Engine as an Expo native module created using create-expo-module to be used in Expo mobile apps and in React Native mobile apps with installed Expo.
This project is an Expo/React Native wrapper around the GS1 Barcode Syntax Engine. It is an independent project and is not an official GS1 AISBL package.
Currently used GS1 Barcode Syntax Engine version: 1.4.1
This application is provided as-is without any gurantee of support.
The library uses .java wrapper from GS1 Barcode Syntax Engine that references native C code from GS1 Barcode Syntax Engine. This library is just a .kt and .ts wrapper around the .java GS1 Barcode Syntax Engine wrapper that exposes methods from GS1Encoder.java.
All GS1 Barcode Syntax Engine are exposed and ready to use and there are a few additional methods.
npx expo install expo-gs1-syntax-engineIf you are installing this in an existing React Native app, make sure to install expo in your project.
npm install expo-gs1-syntax-engine- First, import GS1Engine class and required types
import { GS1Engine, ProcessBarcodeResult } from 'expo-gs1-syntax-engine';- Init GS1Engine class and set instance properties
// 1. Initialization function with settings
async function initGS1Encoder(): Promise<GS1Engine> {
const gs1encoder = new GS1Engine();
await gs1encoder.init();
// Configuring an instance using get/set properties
gs1encoder.permitUnknownAIs = true;
gs1encoder.setValidationEnabled(GS1Engine.validation.RequisiteAIs, true);
gs1encoder.includeDataTitlesInHRI = true;
gs1encoder.permitZeroSuppressedGTINinDLuris = false;
return gs1encoder;
}- Initialize GS1Engine class in useEffect hook with cleanup function
const [encoder, setEncoder] = useState<GS1Engine | null>(null);
const [loading, setLoading] = useState<boolean>(true);
const [error, setError] = useState<string>('');
// 2. Instance Lifecycle Management
useEffect(() => {
let activeEncoder: GS1Engine | null = null;
async function setup() {
try {
setLoading(true);
// Calling init
activeEncoder = await initGS1Encoder();
setEncoder(activeEncoder);
setError('');
} catch (err: any) {
setError(`Error initializing the C engine: ${err.message}`);
} finally {
setLoading(false);
}
}
setup();
// Memory cleanup: When a component is unmounted, the native context is closed
return () => {
if (activeEncoder) {
console.log('Freeing up GS1 Syntax Engine from C memory.');
activeEncoder.close();
}
};
}, []);- Start processing data
4.1. Using the additional method processBarcode
// gs1 datamatrix
const result3 = encoder.processBarcode(
']d2011231231231233310ABC123\u001D99XYZ',
'https://mydomain.sk'
);
console.log('Processing result for gs1 datamatrix:');
console.log(result3);4.2. Using the original methods
encoder.setScanData(']d201085800000000091126071610Lot858\u001D21Serial01');
console.log('Get HRI from direct input');
const resultDirect = encoder.getHRI();
console.log(`${resultDirect}`);
console.log('Get formated engine result data');
const complexData = encoder.getEngineResultData();
console.log(complexData);We have created a basic Expo GS1 Barcode Syntax Engine Example App to demonstrate how this library can be used.
This library includes portions of the GS1 Barcode Syntax Engine.
GS1 Barcode Syntax Engine Copyright (c) GS1 AISBL
Licensed under the Apache License, Version 2.0. https://www.apache.org/licenses/LICENSE-2.0
MIT