@@ -8,16 +8,16 @@ import ScanbotBarcodeSDK, {
88} from 'react-native-scanbot-barcode-scanner-sdk' ;
99import { DocumentDirectoryPath } from 'react-native-fs' ;
1010
11- async function handleScanningResultWithImageRef ( ) {
11+ export async function handleScanningResultWithImageRef ( ) {
1212 // Start the barcode RTU UI with a configuration that returns image results
1313 const config = new BarcodeScannerScreenConfiguration ( ) ;
1414 config . scannerConfiguration . returnBarcodeImage = true ;
15- const scanningResult = await ScanbotBarcodeSDK . startBarcodeScanner ( config ) ;
1615
1716 // Autorelease executes the given block and releases native resources
18- await autorelease ( ( ) => {
17+ await autorelease ( async ( ) => {
18+ const scanningResult = await ScanbotBarcodeSDK . startBarcodeScanner ( config ) ;
1919 if ( scanningResult . status == 'OK' && scanningResult . data ) {
20- scanningResult . data . items . forEach ( async ( { barcode } ) => {
20+ for ( const { barcode } of scanningResult . data . items ) {
2121 // Check if sourceImage exists
2222 if ( barcode . sourceImage ) {
2323 // Saves the stored image at path with the given options
@@ -30,7 +30,7 @@ async function handleScanningResultWithImageRef() {
3030 // Releases the strong reference to the image manually
3131 barcode . sourceImage . release ( ) ;
3232 }
33- } ) ;
33+ }
3434 }
3535 } ) ;
3636}
@@ -39,40 +39,40 @@ async function handleScanningResultWithSerializedImageRef() {
3939 // Start the barcode RTU UI with a configuration that returns image results
4040 const config = new BarcodeScannerScreenConfiguration ( ) ;
4141 config . scannerConfiguration . returnBarcodeImage = true ;
42- const scanningResult = await ScanbotBarcodeSDK . startBarcodeScanner ( config ) ;
4342
4443 let serializedResult : DeepPartial < BarcodeScannerUiResult > ;
4544
4645 await autorelease ( async ( ) => {
46+ const scanningResult = await ScanbotBarcodeSDK . startBarcodeScanner ( config ) ;
4747 if ( scanningResult . status == 'OK' && scanningResult . data ) {
4848 // Serialized the scanned result in order to move the data outside the autorelease block
4949 serializedResult = await scanningResult . data . serialize ( ) ;
5050 }
5151 } ) ;
5252
5353 // In another part of the app utilize the serialized result
54- await autorelease ( ( ) => {
54+ await autorelease ( async ( ) => {
5555 const barcodeResult = new BarcodeScannerUiResult ( serializedResult ) ;
5656 // Continue working with ImageRefs
57- barcodeResult . items . forEach ( async ( { barcode } ) => {
57+ for ( const { barcode } of barcodeResult . items ) {
5858 if ( barcode . sourceImage ) {
5959 // Saves the stored image at path with the given options
6060 const path = DocumentDirectoryPath + '/my_custom_path/my_file.jpg' ;
6161 await barcode . sourceImage . saveImage ( path , new SaveImageOptions ( ) ) ;
6262 // Returns the stored image as base64.
6363 const base64Image = await barcode . sourceImage . encodeImage ( new EncodeImageOptions ( ) ) ;
6464 }
65- } ) ;
65+ }
6666 } ) ;
6767}
6868
6969async function handleScanningResultWithEncodedImageRef ( ) {
7070 // Start the barcode RTU UI with a configuration that returns image results
7171 const config = new BarcodeScannerScreenConfiguration ( ) ;
7272 config . scannerConfiguration . returnBarcodeImage = true ;
73- const scanningResult = await ScanbotBarcodeSDK . startBarcodeScanner ( config ) ;
7473
7574 await autorelease ( async ( ) => {
75+ const scanningResult = await ScanbotBarcodeSDK . startBarcodeScanner ( config ) ;
7676 if ( scanningResult . status == 'OK' && scanningResult . data ) {
7777 // Encode all ImageRefs as base64
7878 await scanningResult . data . encodeImages ( ) ;
0 commit comments