Skip to content

Commit 9f216ae

Browse files
Fix/image ref snippet (#306)
* Fixed rtuUiHandleImageRefScanningResult.ts * Updated dependencies
1 parent 79baf61 commit 9f216ae

3 files changed

Lines changed: 1328 additions & 1271 deletions

File tree

ios/Podfile.lock

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1648,7 +1648,7 @@ PODS:
16481648
- React-RCTFBReactNativeSpec
16491649
- ReactCommon/turbomodule/core
16501650
- SocketRocket
1651-
- react-native-document-picker (10.1.5):
1651+
- react-native-document-picker (10.1.7):
16521652
- boost
16531653
- DoubleConversion
16541654
- fast_float
@@ -1706,7 +1706,7 @@ PODS:
17061706
- ReactCommon/turbomodule/core
17071707
- SocketRocket
17081708
- Yoga
1709-
- react-native-safe-area-context (5.5.2):
1709+
- react-native-safe-area-context (5.6.2):
17101710
- boost
17111711
- DoubleConversion
17121712
- fast_float
@@ -1725,8 +1725,8 @@ PODS:
17251725
- React-hermes
17261726
- React-ImageManager
17271727
- React-jsi
1728-
- react-native-safe-area-context/common (= 5.5.2)
1729-
- react-native-safe-area-context/fabric (= 5.5.2)
1728+
- react-native-safe-area-context/common (= 5.6.2)
1729+
- react-native-safe-area-context/fabric (= 5.6.2)
17301730
- React-NativeModulesApple
17311731
- React-RCTFabric
17321732
- React-renderercss
@@ -1737,7 +1737,7 @@ PODS:
17371737
- ReactCommon/turbomodule/core
17381738
- SocketRocket
17391739
- Yoga
1740-
- react-native-safe-area-context/common (5.5.2):
1740+
- react-native-safe-area-context/common (5.6.2):
17411741
- boost
17421742
- DoubleConversion
17431743
- fast_float
@@ -1766,7 +1766,7 @@ PODS:
17661766
- ReactCommon/turbomodule/core
17671767
- SocketRocket
17681768
- Yoga
1769-
- react-native-safe-area-context/fabric (5.5.2):
1769+
- react-native-safe-area-context/fabric (5.6.2):
17701770
- boost
17711771
- DoubleConversion
17721772
- fast_float
@@ -2302,7 +2302,7 @@ PODS:
23022302
- ScanbotBarcodeSDKWrapper (= 7.1.4.0)
23032303
- SocketRocket
23042304
- Yoga
2305-
- RNScreens (4.11.1):
2305+
- RNScreens (4.18.0):
23062306
- boost
23072307
- DoubleConversion
23082308
- fast_float
@@ -2330,10 +2330,10 @@ PODS:
23302330
- ReactCodegen
23312331
- ReactCommon/turbomodule/bridging
23322332
- ReactCommon/turbomodule/core
2333-
- RNScreens/common (= 4.11.1)
2333+
- RNScreens/common (= 4.18.0)
23342334
- SocketRocket
23352335
- Yoga
2336-
- RNScreens/common (4.11.1):
2336+
- RNScreens/common (4.18.0):
23372337
- boost
23382338
- DoubleConversion
23392339
- fast_float
@@ -2657,9 +2657,9 @@ SPEC CHECKSUMS:
26572657
React-logger: 2f0d40bc8e648fbb1ff3b6580ad54189a8753290
26582658
React-Mapbuffer: 9a7c65078c6851397c1999068989e4fc239d0c80
26592659
React-microtasksnativemodule: 4f1ef719ba6c7ebbd2d75346ffa2916f9b4771c9
2660-
react-native-document-picker: 65723ccdfe85fafc77b80428b61973039cae2e80
2660+
react-native-document-picker: a51b7f859bab49bee35a0bc63e2455ffaeea5505
26612661
react-native-image-picker: 588b86a708e2527ce8766e75f8b56cd88b8e0620
2662-
react-native-safe-area-context: 339885703b6dd1be2bce42d9c0b0350c21180032
2662+
react-native-safe-area-context: d446989793f96dc2f44c33c42dbfb316d983f24e
26632663
React-NativeModulesApple: f6f696e510b9d89c3c06b7764f56947dc13ae922
26642664
React-oscompat: 114036cd8f064558c9c1a0c04fc9ae5e1453706a
26652665
React-perflogger: 4b2f88ae059b600daf268528a4a83366338eef05
@@ -2693,7 +2693,7 @@ SPEC CHECKSUMS:
26932693
ReactCommon: 96684b90b235d6ae340d126141edd4563b7a446a
26942694
RNFS: 4ac0f0ea233904cb798630b3c077808c06931688
26952695
RNScanbotBarcodeSDK: 6ae16d74d5e98cdfaa52907de3cf05792ff87852
2696-
RNScreens: 45a4564413205e2a1695d40bbc0297f6eefc9b74
2696+
RNScreens: 846d53087db560ed5fbc34feb0643adb5f9602c5
26972697
ScanbotBarcodeScannerSDK: 763b4307353c249fa9d0eea69fb2a49df4f04889
26982698
ScanbotBarcodeSDKWrapper: 4a478864519ab5818e5bce9287dedcf1db9d96d6
26992699
SocketRocket: d4aabe649be1e368d1318fdf28a022d714d65748

src/codeSnippets/rtuui/rtuUiHandleImageRefScanningResult.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,16 @@ import ScanbotBarcodeSDK, {
88
} from 'react-native-scanbot-barcode-scanner-sdk';
99
import { 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

6969
async 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

Comments
 (0)