react-native-scanbot-barcode-scanner-sdk 3.2.1-rc1 → 3.2.1-rc2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -18,12 +18,15 @@ import com.facebook.react.bridge.ReactApplicationContext;
18
18
  import com.facebook.react.bridge.ReactContext;
19
19
  import com.facebook.react.bridge.ReactContextBaseJavaModule;
20
20
  import com.facebook.react.bridge.ReactMethod;
21
+ import com.facebook.react.bridge.ReadableArray;
21
22
  import com.facebook.react.bridge.ReadableMap;
22
23
  import com.facebook.react.bridge.WritableArray;
23
24
  import com.facebook.react.bridge.WritableMap;
24
25
 
25
26
  import org.jetbrains.annotations.Contract;
26
27
  import org.jetbrains.annotations.NotNull;
28
+ import org.json.JSONArray;
29
+ import org.json.JSONException;
27
30
 
28
31
  import java.io.File;
29
32
  import java.io.IOException;
@@ -182,19 +185,22 @@ public class ScanbotBarcodeSdkModule extends ReactContextBaseJavaModule implemen
182
185
 
183
186
  detector.modifyConfig(new ScanbotBarcodeDetectorConfigBuilder(options));
184
187
 
185
- final BarcodeScanningResult result = detector.detectFromBitmap(bitmap, 0);
186
188
  WritableMap jsonResult;
187
-
188
- final boolean shouldFilterBarcodes = options.hasKey("barcodeFilter");
189
- if (shouldFilterBarcodes) {
190
- final BarcodeFilter barcodeFilter = JSONUtils.extractBarcodeFilter(options);
191
- if (barcodeFilter == null) {
192
- throw new IllegalArgumentException("Invalid Barcode Filter specified in JSON configuration: " + options.getString("barcodeFilter"));
193
- }
194
- final List<BarcodeItem> barcodeItems = JSONUtils.getBarcodeItemsFromResultWithFilter(result, barcodeFilter);
195
- jsonResult = jsonResultFromBarcodeScannerResult(barcodeItems);
189
+ final BarcodeScanningResult result = detector.detectFromBitmap(bitmap, 0);
190
+ if (result == null) {
191
+ jsonResult = JSONUtils.jsonResultFromBarcodeItems(new ArrayList<>());
196
192
  } else {
197
- jsonResult = jsonResultFromBarcodeScannerResult(result);
193
+ final boolean shouldFilterBarcodes = options.hasKey("barcodeFilter");
194
+ if (shouldFilterBarcodes) {
195
+ final BarcodeFilter barcodeFilter = JSONUtils.extractBarcodeFilter(options);
196
+ if (barcodeFilter == null) {
197
+ throw new IllegalArgumentException("Invalid Barcode Filter specified in JSON configuration: " + options.getString("barcodeFilter"));
198
+ }
199
+ final List<BarcodeItem> barcodeItems = JSONUtils.getBarcodeItemsFromResultWithFilter(result, barcodeFilter);
200
+ jsonResult = JSONUtils.jsonResultFromBarcodeItems(barcodeItems);
201
+ } else {
202
+ jsonResult = JSONUtils.jsonResultFromBarcodeResult(result);
203
+ }
198
204
  }
199
205
 
200
206
  jsonResult.putString("imageFileUri", imageUri);
@@ -349,7 +355,7 @@ public class ScanbotBarcodeSdkModule extends ReactContextBaseJavaModule implemen
349
355
  final BarcodeScannerActivity.Result barcodeResult = BarcodeScannerActivity.extractResult(resultCode, intent);
350
356
 
351
357
  if (barcodeResult.getResultOk()) {
352
- final WritableMap result = jsonResultFromBarcodeScannerResult(barcodeResult.getResult());
358
+ final WritableMap result = JSONUtils.jsonResultFromBarcodeResult(barcodeResult.getResult());
353
359
 
354
360
  String imagePath = intent.getStringExtra(BarcodeScannerActivity.SCANNED_BARCODE_IMAGE_PATH_EXTRA);
355
361
  if (imagePath == null) {
@@ -378,27 +384,6 @@ public class ScanbotBarcodeSdkModule extends ReactContextBaseJavaModule implemen
378
384
  }
379
385
  }
380
386
 
381
- private static WritableMap jsonResultFromBarcodeScannerResult(List<BarcodeItem> barcodeItems) {
382
- final WritableArray barcodes = Arguments.createArray();
383
- for (BarcodeItem barcodeItem : barcodeItems) {
384
- final WritableMap barcode = Arguments.createMap();
385
- barcode.putString("type", barcodeItem.getBarcodeFormat().name());
386
- barcode.putString("text", barcodeItem.getText());
387
- barcode.putString("textWithExtension", barcodeItem.getTextWithExtension());
388
- barcodes.pushMap(barcode);
389
- }
390
- final WritableMap result = Arguments.createMap();
391
- result.putString("status", "OK");
392
- result.putArray("barcodes", barcodes);
393
- return result;
394
- }
395
-
396
- private static WritableMap jsonResultFromBarcodeScannerResult(BarcodeScanningResult barcodeResult) {
397
- return jsonResultFromBarcodeScannerResult(
398
- barcodeResult != null ? barcodeResult.getBarcodeItems() : new ArrayList<>()
399
- );
400
- }
401
-
402
387
  @NotNull
403
388
  @Contract(pure = true)
404
389
  private static String descriptionFromLicenseStatus(@NotNull io.scanbot.sap.Status status) {
@@ -207,22 +207,7 @@ public class RNScanbotBarcodeCameraComponent extends RNScanbotNativeComponent im
207
207
  return;
208
208
  }
209
209
 
210
- final WritableArray barcodes = new WritableNativeArray();
211
-
212
- for (BarcodeItem item: barcodeItems) {
213
- final WritableMap barcode = new JSONUtils.WritableMapBuilder()
214
- .putString("text", item.getText())
215
- .putString("type", item.getBarcodeFormat().name())
216
- .putString("textWithExtension", item.getTextWithExtension())
217
- .build();
218
- barcodes.pushMap(barcode);
219
- }
220
-
221
- final WritableMap result = new JSONUtils.WritableMapBuilder()
222
- .putString("status", "OK")
223
- .putArray("barcodes", barcodes)
224
- .build();
225
-
210
+ final ReadableMap result = JSONUtils.jsonResultFromBarcodeItems(barcodeItems);
226
211
  final WritableMap data = new JSONUtils.WritableMapBuilder()
227
212
  .putMap("result", result)
228
213
  .build();
@@ -294,4 +294,39 @@ public final class JSONUtils {
294
294
  }
295
295
  return map.getBoolean(key);
296
296
  }
297
+
298
+ public static WritableMap jsonResultFromBarcodeResult(BarcodeScanningResult barcodeResult) {
299
+ return jsonResultFromBarcodeItems(
300
+ barcodeResult != null ? barcodeResult.getBarcodeItems() : new ArrayList<>()
301
+ );
302
+ }
303
+
304
+ public static WritableMap jsonResultFromBarcodeItems(List<BarcodeItem> barcodeItems) {
305
+ final WritableArray barcodes = Arguments.createArray();
306
+ for (BarcodeItem barcodeItem : barcodeItems) {
307
+ final WritableMap barcode = Arguments.createMap();
308
+ barcode.putString("type", barcodeItem.getBarcodeFormat().name());
309
+ barcode.putString("text", barcodeItem.getText());
310
+ barcode.putString("textWithExtension", barcodeItem.getTextWithExtension());
311
+ barcode.putArray("rawBytes", jsonFromRawBytes(barcodeItem.getRawBytes()));
312
+ barcodes.pushMap(barcode);
313
+ }
314
+ final WritableMap result = Arguments.createMap();
315
+ result.putString("status", "OK");
316
+ result.putArray("barcodes", barcodes);
317
+ return result;
318
+ }
319
+
320
+ public static ReadableArray jsonFromRawBytes(byte[] rawBytes) {
321
+ final WritableArray jsonArray = Arguments.createArray();
322
+ if (rawBytes.length == 0) {
323
+ return jsonArray;
324
+ }
325
+
326
+ for (byte b: rawBytes) {
327
+ jsonArray.pushInt(b);
328
+ }
329
+
330
+ return jsonArray;
331
+ }
297
332
  }
package/index.d.ts CHANGED
@@ -3,7 +3,7 @@ import { BarcodeScannerConfiguration, BatchBarcodeScannerConfiguration, DetectBa
3
3
  import { BarcodeDocumentFormat, BarcodeFormat, EngineMode } from "./src/enum";
4
4
  import { BarcodeResult, BarcodeScannerResult, BatchBarcodeScannerResult } from "./src/result";
5
5
  import { ScanbotBarcodeCameraView } from "./src/components/barcode-camera-view/scanbot-barcode-camera-view";
6
- import { ScanbotBarcodeCameraViewConfiguration, ScanbotBarcodeCameraViewResult} from "./src/components/barcode-camera-view/scanbot-barcode-camera-view-types";
6
+ import { ScanbotBarcodeCameraViewConfiguration} from "./src/components/barcode-camera-view/scanbot-barcode-camera-view-types";
7
7
 
8
8
  export {
9
9
  BarcodeScannerConfiguration,
@@ -15,7 +15,6 @@ export {
15
15
  BatchBarcodeScannerResult,
16
16
  ScanbotBarcodeCameraView,
17
17
  ScanbotBarcodeCameraViewConfiguration,
18
- ScanbotBarcodeCameraViewResult,
19
18
  EngineMode
20
19
  }
21
20
 
@@ -178,20 +178,10 @@
178
178
  results = filterBarcodeResults(results, _cameraViewConfiguration.barcodeFilter);
179
179
  }
180
180
 
181
- NSMutableArray* jsonBarcodes = [[NSMutableArray alloc] init];
182
-
183
- for (SBSDKBarcodeScannerResult* result in results) {
184
- [jsonBarcodes addObject:@{
185
- @"text": result.rawTextString,
186
- @"type": result.type.name,
187
- @"textWithExtension": result.rawTextStringWithExtension,
188
- }];
189
- }
190
-
191
181
  NSDictionary* outResult = @{
192
182
  @"result": @{
193
183
  @"status": @"OK",
194
- @"barcodes": jsonBarcodes
184
+ @"barcodes": jsonFromBarcodeResults(results)
195
185
  }
196
186
  };
197
187
 
@@ -267,9 +267,13 @@ RCT_EXPORT_METHOD(detectBarcodesOnImage:(NSDictionary *)configuration
267
267
  }
268
268
  NSArray<SBSDKBarcodeScannerResult *> *barcodeResults = [barcodeScanner detectBarCodesOnImage:image];
269
269
 
270
- SBSDKUIBarcodeFilter* barcodeFilter = extractBarcodeFilter(configuration);
271
- if (barcodeFilter != nil) {
272
- barcodeResults = filterBarcodeResults(barcodeResults, barcodeFilter);
270
+ if (barcodeResults) {
271
+ SBSDKUIBarcodeFilter* barcodeFilter = extractBarcodeFilter(configuration);
272
+ if (barcodeFilter != nil) {
273
+ barcodeResults = filterBarcodeResults(barcodeResults, barcodeFilter);
274
+ }
275
+ } else {
276
+ barcodeResults = [[NSArray alloc] init];
273
277
  }
274
278
 
275
279
  resolve(@{
@@ -44,6 +44,17 @@ static inline SBSDKBarcodeDocumentType* barcodeDocumentTypeFromString(NSString*
44
44
  return nil;
45
45
  }
46
46
 
47
+ static inline NSArray<NSNumber*>* jsonFromRawBytes(NSData* rawBytes) {
48
+ NSMutableArray<NSNumber*>* byteArray = [[NSMutableArray alloc] init];
49
+ uint8_t* bytePtr = (uint8_t*)[rawBytes bytes];
50
+ NSInteger totalData = [rawBytes length] / sizeof(uint8_t);
51
+ for (int i=0 ; i<totalData; i++) {
52
+ uint8_t current = bytePtr[i];
53
+ [byteArray addObject:[[NSNumber alloc] initWithUnsignedChar:current]];
54
+ }
55
+ return byteArray;
56
+ }
57
+
47
58
  static inline NSString* stringFromBarcodeType(SBSDKBarcodeType* type) {
48
59
  if ([type.name isEqualToString:@"QRCode"]) {
49
60
  return @"QR_CODE";
@@ -60,11 +71,11 @@ static inline NSString* stringFromBarcodeType(SBSDKBarcodeType* type) {
60
71
  }
61
72
 
62
73
  static inline NSDictionary<NSString*, NSObject*>* jsonFromBarcodeResult(SBSDKBarcodeScannerResult *result) {
63
-
64
74
  NSMutableDictionary* x = @{
65
75
  @"type": stringFromBarcodeType(result.type),
66
76
  @"text": result.rawTextString,
67
77
  @"textWithExtension": result.rawTextStringWithExtension,
78
+ @"rawBytes": jsonFromRawBytes(result.rawBytes)
68
79
  }.mutableCopy;
69
80
  return x.copy;
70
81
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "react-native-scanbot-barcode-scanner-sdk",
3
3
  "title": "Scanbot Barcode Scanner SDK for React Native",
4
- "version": "3.2.1-rc1",
4
+ "version": "3.2.1-rc2",
5
5
  "description": "Scanbot Barcode Scanner SDK React Native Plugin for Android and iOS",
6
6
  "main": "index.js",
7
7
  "files": [
@@ -1,4 +1,5 @@
1
1
  import { StyleProp, ViewStyle } from 'react-native';
2
+ import { BarcodeResult } from 'react-native-scanbot-barcode-scanner-sdk';
2
3
  import {
3
4
  BarcodeDocumentFormat,
4
5
  BarcodeFilter,
@@ -9,7 +10,7 @@ import {
9
10
  import { FinderAspectRatio } from '../../model';
10
11
 
11
12
  export interface ScanbotBarcodeCameraViewProperties {
12
- onBarcodeScannerResult?: (result: ScanbotBarcodeCameraViewResult) => void;
13
+ onBarcodeScannerResult?: (result: BarcodeResult) => void;
13
14
  requestComponentReload?: () => void;
14
15
  configuration?: ScanbotBarcodeCameraViewConfiguration;
15
16
  style: StyleProp<ViewStyle>;
@@ -21,11 +22,6 @@ export interface ScanbotBarcodeCameraViewBarcode {
21
22
  type: string;
22
23
  }
23
24
 
24
- export type ScanbotBarcodeCameraViewResult = {
25
- status: 'OK' | 'CANCELED';
26
- barcodes: ScanbotBarcodeCameraViewBarcode[];
27
- };
28
-
29
25
  export interface ScanbotBarcodeCameraViewConfiguration {
30
26
  /**
31
27
  * The finder view is a rectangular overlay view that clips the camera view,
package/src/result.ts CHANGED
@@ -15,11 +15,16 @@ export interface BarcodeResultField {
15
15
  * The raw text encoded in the barcode that also includes the extension, if detected
16
16
  */
17
17
  textWithExtension: string;
18
+
19
+ /**
20
+ * The array of raw bytes contained in the barcode.
21
+ */
22
+ rawBytes: number[];
18
23
  }
19
24
 
20
25
  export interface BarcodeResult {
21
26
  status: Status;
22
- barcodes?: BarcodeResultField[];
27
+ barcodes: BarcodeResultField[];
23
28
  }
24
29
 
25
30
  export type BarcodeScannerResult = BarcodeResult & {