react-native-scanbot-barcode-scanner-sdk 3.2.1-beta2 → 3.2.1-beta3
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.
- package/android/src/main/java/io/scanbot/barcodesdk/plugin/reactnative/JSONUtils.java +21 -0
- package/android/src/main/java/io/scanbot/barcodesdk/plugin/reactnative/ObjectMapper.java +1 -1
- package/android/src/main/java/io/scanbot/barcodesdk/plugin/reactnative/ReactBarcodeExtensionsFilter.java +61 -0
- package/android/src/main/java/io/scanbot/barcodesdk/plugin/reactnative/ScanbotBarcodeSdkModule.java +7 -2
- package/ios/ScanbotBarcodeSdk.m +9 -9
- package/ios/Utils/BarcodeMapping.h +18 -0
- package/ios/Utils/ReactBarcodeExtensionsFilter.h +22 -0
- package/ios/Utils/ReactBarcodeExtensionsFilter.m +55 -0
- package/package.json +1 -1
- package/src/configuration.ts +6 -5
- package/src/enum.ts +5 -0
- package/android/src/main/java/io/scanbot/barcodesdk/plugin/reactnative/BarcodeExtensionsFilter.java +0 -24
|
@@ -6,6 +6,7 @@
|
|
|
6
6
|
package io.scanbot.barcodesdk.plugin.reactnative;
|
|
7
7
|
|
|
8
8
|
import android.graphics.PointF;
|
|
9
|
+
import android.util.Log;
|
|
9
10
|
|
|
10
11
|
import androidx.annotation.NonNull;
|
|
11
12
|
import androidx.annotation.Nullable;
|
|
@@ -30,6 +31,7 @@ import io.scanbot.sdk.barcode.entity.BarcodeFormat;
|
|
|
30
31
|
import io.scanbot.sdk.barcode.entity.BarcodeScannerAdditionalConfig;
|
|
31
32
|
import io.scanbot.sdk.barcode.entity.EngineMode;
|
|
32
33
|
import io.scanbot.sdk.barcode.entity.MSIPlesseyChecksumAlgorithm;
|
|
34
|
+
import io.scanbot.sdk.ui.view.barcode.configuration.BarcodeFilter;
|
|
33
35
|
import io.scanbot.sdk.ui.view.barcode.configuration.BarcodeScannerAdditionalConfiguration;
|
|
34
36
|
import io.scanbot.sdk.ui.view.base.configuration.CameraOrientationMode;
|
|
35
37
|
|
|
@@ -214,6 +216,25 @@ public final class JSONUtils {
|
|
|
214
216
|
) : null;
|
|
215
217
|
}
|
|
216
218
|
|
|
219
|
+
public static BarcodeFilter extractBarcodeFilter(final ReadableMap options) {
|
|
220
|
+
if (!options.hasKey("barcodeFilter")) {
|
|
221
|
+
return null;
|
|
222
|
+
}
|
|
223
|
+
final String filterType = options.getString("barcodeFilter");
|
|
224
|
+
try {
|
|
225
|
+
final ReactBarcodeExtensionsFilter.Type type =
|
|
226
|
+
ReactBarcodeExtensionsFilter.Type.valueOf(filterType);
|
|
227
|
+
return new ReactBarcodeExtensionsFilter(type);
|
|
228
|
+
}
|
|
229
|
+
catch (IllegalArgumentException exception) {
|
|
230
|
+
exception.printStackTrace();
|
|
231
|
+
final String errMsg = String.format("The value passed in 'barcodeFilter' (%s) does not exist", filterType);
|
|
232
|
+
Log.e("SCANBOT_SDK", errMsg);
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
return null;
|
|
236
|
+
}
|
|
237
|
+
|
|
217
238
|
public static ArrayList<String> getStringArrayListFromMap(final ReadableMap configuration, final String key) {
|
|
218
239
|
ArrayList<String> out = new ArrayList<>();
|
|
219
240
|
if(!configuration.hasKey(key)) {
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
package io.scanbot.barcodesdk.plugin.reactnative;
|
|
2
|
+
|
|
3
|
+
import androidx.annotation.NonNull;
|
|
4
|
+
|
|
5
|
+
import java.util.List;
|
|
6
|
+
import java.util.Map;
|
|
7
|
+
|
|
8
|
+
import io.scanbot.sdk.barcode.entity.BarcodeItem;
|
|
9
|
+
import io.scanbot.sdk.barcode.entity.BarcodeMetadataKey;
|
|
10
|
+
import io.scanbot.sdk.ui.view.barcode.configuration.BarcodeFilter;
|
|
11
|
+
import io.scanbot.sdk.ui.view.barcode.configuration.IBarcodeFilter;
|
|
12
|
+
|
|
13
|
+
public class ReactBarcodeExtensionsFilter extends BarcodeFilter {
|
|
14
|
+
|
|
15
|
+
public enum Type {
|
|
16
|
+
WithExtension,
|
|
17
|
+
WithEAN2Extension,
|
|
18
|
+
WithEAN5Extension
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
private final Type filterType;
|
|
22
|
+
|
|
23
|
+
public ReactBarcodeExtensionsFilter(Type filterType) {
|
|
24
|
+
this.filterType = filterType;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
@Override
|
|
28
|
+
public boolean acceptsBarcode(@NonNull BarcodeItem barcodeItem) {
|
|
29
|
+
if (!super.acceptsBarcode(barcodeItem)) {
|
|
30
|
+
return false;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
final String extension = getExtensionOrEmpty(barcodeItem);
|
|
34
|
+
if(extension.equals("")) {
|
|
35
|
+
return false;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
switch(this.filterType) {
|
|
39
|
+
case WithExtension:
|
|
40
|
+
return true;
|
|
41
|
+
case WithEAN2Extension:
|
|
42
|
+
return extension.trim().length() == 2;
|
|
43
|
+
case WithEAN5Extension:
|
|
44
|
+
return extension.trim().length() == 5;
|
|
45
|
+
default:
|
|
46
|
+
return false;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
private static String getExtensionOrEmpty(final BarcodeItem barcodeItem)
|
|
51
|
+
{
|
|
52
|
+
final Map<BarcodeMetadataKey, String> metadata = barcodeItem.getMetadata();
|
|
53
|
+
|
|
54
|
+
if (!metadata.containsKey(BarcodeMetadataKey.UpcEanExtension)
|
|
55
|
+
) {
|
|
56
|
+
return "";
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
return metadata.get(BarcodeMetadataKey.UpcEanExtension);
|
|
60
|
+
}
|
|
61
|
+
}
|
package/android/src/main/java/io/scanbot/barcodesdk/plugin/reactnative/ScanbotBarcodeSdkModule.java
CHANGED
|
@@ -47,6 +47,7 @@ import io.scanbot.sdk.ui.barcode_scanner.view.barcode.BarcodeScannerActivity;
|
|
|
47
47
|
import io.scanbot.sdk.ui.barcode_scanner.view.barcode.batch.BatchBarcodeScannerActivity;
|
|
48
48
|
import io.scanbot.sdk.ui.view.barcode.batch.configuration.BatchBarcodeScannerConfiguration;
|
|
49
49
|
import io.scanbot.sdk.ui.view.barcode.configuration.BarcodeExtensionsFilter;
|
|
50
|
+
import io.scanbot.sdk.ui.view.barcode.configuration.BarcodeFilter;
|
|
50
51
|
import io.scanbot.sdk.ui.view.barcode.configuration.BarcodeScannerAdditionalConfiguration;
|
|
51
52
|
import io.scanbot.sdk.ui.view.barcode.configuration.BarcodeScannerConfiguration;
|
|
52
53
|
import io.scanbot.sdk.ui.view.base.configuration.CameraOrientationMode;
|
|
@@ -54,6 +55,7 @@ import kotlin.Unit;
|
|
|
54
55
|
import kotlin.jvm.functions.Function1;
|
|
55
56
|
|
|
56
57
|
import android.app.Activity;
|
|
58
|
+
import android.util.Log;
|
|
57
59
|
|
|
58
60
|
|
|
59
61
|
public class ScanbotBarcodeSdkModule extends ReactContextBaseJavaModule implements ActivityEventListener {
|
|
@@ -308,8 +310,11 @@ public class ScanbotBarcodeSdkModule extends ReactContextBaseJavaModule implemen
|
|
|
308
310
|
configuration.setCancelButtonIcon(R.drawable.ic_baseline_arrow_back_24);
|
|
309
311
|
}
|
|
310
312
|
|
|
311
|
-
if (options.hasKey("
|
|
312
|
-
|
|
313
|
+
if (options.hasKey("barcodeFilter")) {
|
|
314
|
+
final BarcodeFilter barcodeFilter = JSONUtils.extractBarcodeFilter(options);
|
|
315
|
+
if (barcodeFilter != null) {
|
|
316
|
+
configuration.setBarcodeFilter(barcodeFilter);
|
|
317
|
+
}
|
|
313
318
|
}
|
|
314
319
|
}
|
|
315
320
|
|
package/ios/ScanbotBarcodeSdk.m
CHANGED
|
@@ -140,12 +140,12 @@ RCT_EXPORT_METHOD(startBarcodeScanner:(NSDictionary*)configuration
|
|
|
140
140
|
additionalParameters.enableGS1Decoding = [gs1Decoding boolValue];
|
|
141
141
|
}
|
|
142
142
|
|
|
143
|
-
// UPC Extension
|
|
144
|
-
|
|
145
|
-
if (
|
|
146
|
-
behaviorConfig.barcodeFilter =
|
|
143
|
+
// Barcode Filter (at the moment used for UPC Extension filters)
|
|
144
|
+
SBSDKUIBarcodeFilter* barcodeFilter = extractBarcodeFilter(configuration);
|
|
145
|
+
if (barcodeFilter != nil) {
|
|
146
|
+
behaviorConfig.barcodeFilter = barcodeFilter;
|
|
147
147
|
}
|
|
148
|
-
|
|
148
|
+
|
|
149
149
|
additionalParameters.msiPlesseyChecksumAlgorithm = extractPlesseyChecksumAlgorithmFromConfiguration(configuration);
|
|
150
150
|
|
|
151
151
|
behaviorConfig.additionalParameters = additionalParameters;
|
|
@@ -210,10 +210,10 @@ RCT_EXPORT_METHOD(startBatchBarcodeScanner:(NSDictionary*)configuration
|
|
|
210
210
|
additionalParameters.enableGS1Decoding = [gs1Decoding boolValue];
|
|
211
211
|
}
|
|
212
212
|
|
|
213
|
-
// UPC Extension
|
|
214
|
-
|
|
215
|
-
if (
|
|
216
|
-
behavior.barcodeFilter =
|
|
213
|
+
// Barcode Filter (at the moment used for UPC Extension filters)
|
|
214
|
+
SBSDKUIBarcodeFilter* barcodeFilter = extractBarcodeFilter(configuration);
|
|
215
|
+
if (barcodeFilter != nil) {
|
|
216
|
+
behavior.barcodeFilter = barcodeFilter;
|
|
217
217
|
}
|
|
218
218
|
|
|
219
219
|
additionalParameters.msiPlesseyChecksumAlgorithm = extractPlesseyChecksumAlgorithmFromConfiguration(configuration);
|
|
@@ -8,6 +8,7 @@
|
|
|
8
8
|
#define BarcodeMapping_h
|
|
9
9
|
|
|
10
10
|
#include "ScanbotStorageUtils.h"
|
|
11
|
+
#include "ReactBarcodeExtensionsFilter.h"
|
|
11
12
|
@import ScanbotBarcodeScannerSDK;
|
|
12
13
|
|
|
13
14
|
static inline SBSDKBarcodeType* barcodeTypeFromString(NSString* string) {
|
|
@@ -86,6 +87,23 @@ static inline NSArray<NSDictionary<NSString*, NSObject*>*>* jsonFromMappedBarcod
|
|
|
86
87
|
return [jsonResults copy];
|
|
87
88
|
}
|
|
88
89
|
|
|
90
|
+
static inline SBSDKUIBarcodeFilter* extractBarcodeFilter(NSDictionary* configuration) {
|
|
91
|
+
NSString* jsonFilterType = [configuration objectForKey:@"barcodeFilter"];
|
|
92
|
+
if (jsonFilterType == nil) {
|
|
93
|
+
return nil;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
if ([jsonFilterType isEqualToString:@"WithExtension"]) {
|
|
97
|
+
return [[ReactBarcodeExtensionsFilter alloc] init:ReactBarcodeExtensionsFilterWithExtension];
|
|
98
|
+
} else if ([jsonFilterType isEqualToString:@"WithEAN2Extension"]) {
|
|
99
|
+
return [[ReactBarcodeExtensionsFilter alloc] init:ReactBarcodeExtensionsFilterWithEAN2Extension];
|
|
100
|
+
} else if ([jsonFilterType isEqualToString:@"WithEAN5Extension"]) {
|
|
101
|
+
return [[ReactBarcodeExtensionsFilter alloc] init:ReactBarcodeExtensionsFilterWithEAN5Extension];
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
return nil;
|
|
105
|
+
}
|
|
106
|
+
|
|
89
107
|
static inline NSArray* extractBarcodeTypesFromConfiguration(NSDictionary* configuration) {
|
|
90
108
|
NSArray* barcodeFormats = [configuration objectForKey:@"barcodeFormats"];
|
|
91
109
|
if (barcodeFormats && [barcodeFormats indexOfObject:@"ALL_FORMATS"] == NSNotFound) {
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
//
|
|
2
|
+
// ReactBarcodeExtensionsFilter.h
|
|
3
|
+
// RNScanbotBarcodeSDK
|
|
4
|
+
//
|
|
5
|
+
// Created by Marco Saia on 13.07.22.
|
|
6
|
+
//
|
|
7
|
+
|
|
8
|
+
#import <Foundation/Foundation.h>
|
|
9
|
+
@import ScanbotBarcodeScannerSDK;
|
|
10
|
+
|
|
11
|
+
typedef enum BarcodeFilterType : NSUInteger {
|
|
12
|
+
ReactBarcodeExtensionsFilterWithExtension,
|
|
13
|
+
ReactBarcodeExtensionsFilterWithEAN2Extension,
|
|
14
|
+
ReactBarcodeExtensionsFilterWithEAN5Extension
|
|
15
|
+
} BarcodeFilterType;
|
|
16
|
+
|
|
17
|
+
@interface ReactBarcodeExtensionsFilter : SBSDKUIBarcodeFilter
|
|
18
|
+
|
|
19
|
+
- (instancetype)init NS_UNAVAILABLE;
|
|
20
|
+
- (id)init:(BarcodeFilterType)filterType;
|
|
21
|
+
|
|
22
|
+
@end
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
//
|
|
2
|
+
// ReactBarcodeExtensionsFilter.m
|
|
3
|
+
// RNScanbotBarcodeSDK
|
|
4
|
+
//
|
|
5
|
+
// Created by Marco Saia on 13.07.22.
|
|
6
|
+
//
|
|
7
|
+
|
|
8
|
+
#import "ReactBarcodeExtensionsFilter.h"
|
|
9
|
+
|
|
10
|
+
@implementation ReactBarcodeExtensionsFilter {
|
|
11
|
+
BarcodeFilterType mFilterType;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
-(id)init:(BarcodeFilterType)filterType
|
|
15
|
+
{
|
|
16
|
+
if(self = [super init]) {
|
|
17
|
+
mFilterType = filterType;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
return self;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
- (BOOL)acceptsBarcode:(nonnull SBSDKBarcodeScannerResult *)barcode {
|
|
24
|
+
if (![super acceptsBarcode: barcode]) {
|
|
25
|
+
return false;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
NSString* extension = barcode.metadata[SBSDKBarcodeMetadataEANUPCExtensionKey];
|
|
29
|
+
if (extension == nil || [extension length] == 0) {
|
|
30
|
+
return false;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
switch (mFilterType) {
|
|
34
|
+
case ReactBarcodeExtensionsFilterWithExtension:
|
|
35
|
+
return true;
|
|
36
|
+
case ReactBarcodeExtensionsFilterWithEAN2Extension:
|
|
37
|
+
return trim(extension).length == 2;
|
|
38
|
+
case ReactBarcodeExtensionsFilterWithEAN5Extension:
|
|
39
|
+
return trim(extension).length == 5;
|
|
40
|
+
default:
|
|
41
|
+
return false;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
- (BOOL)shouldAdd:(nonnull SBSDKBarcodeScannerResult *)barcode
|
|
46
|
+
toBarcodes:(nonnull NSArray<SBSDKBarcodeScannerResult *>*)codes
|
|
47
|
+
{
|
|
48
|
+
return [super shouldAdd:barcode toBarcodes:codes];
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
static inline NSString* trim(NSString* text) {
|
|
52
|
+
return [text stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
@end
|
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-
|
|
4
|
+
"version": "3.2.1-beta3",
|
|
5
5
|
"description": "Scanbot Barcode Scanner SDK React Native Plugin for Android and iOS",
|
|
6
6
|
"main": "index.js",
|
|
7
7
|
"files": [
|
package/src/configuration.ts
CHANGED
|
@@ -10,7 +10,8 @@ import {
|
|
|
10
10
|
BarcodeImageGenerationType,
|
|
11
11
|
UIInterfaceOrientationMask,
|
|
12
12
|
EngineMode,
|
|
13
|
-
CameraModule
|
|
13
|
+
CameraModule,
|
|
14
|
+
BarcodeFilter
|
|
14
15
|
} from "./enum";
|
|
15
16
|
import { MSIPlesseyChecksumAlgorithm } from "./enum";
|
|
16
17
|
|
|
@@ -89,9 +90,9 @@ export interface BarcodeScannerConfiguration {
|
|
|
89
90
|
*/
|
|
90
91
|
minimum1DBarcodesQuietZone?: number
|
|
91
92
|
/**
|
|
92
|
-
*
|
|
93
|
+
* Use a filter to determine which type of barcode can be detected; see `BarcodeFilter`
|
|
93
94
|
*/
|
|
94
|
-
|
|
95
|
+
barcodeFilter?: BarcodeFilter;
|
|
95
96
|
/**
|
|
96
97
|
* Whether a sound should be played on successful barcode detection.
|
|
97
98
|
*/
|
|
@@ -301,9 +302,9 @@ export interface BatchBarcodeScannerConfiguration {
|
|
|
301
302
|
*/
|
|
302
303
|
minimum1DBarcodesQuietZone?: number;
|
|
303
304
|
/**
|
|
304
|
-
*
|
|
305
|
+
* Use a filter to determine which type of barcode can be detected; see `BarcodeFilter`
|
|
305
306
|
*/
|
|
306
|
-
|
|
307
|
+
barcodeFilter?: BarcodeFilter;
|
|
307
308
|
/**
|
|
308
309
|
* The engine mode of the barcode recognizer. Defaults to NEXT_GEN.
|
|
309
310
|
* To use the legacy recognizer, please specify LEGACY.
|
package/src/enum.ts
CHANGED
package/android/src/main/java/io/scanbot/barcodesdk/plugin/reactnative/BarcodeExtensionsFilter.java
DELETED
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
package io.scanbot.barcodesdk.plugin.reactnative;
|
|
2
|
-
|
|
3
|
-
import androidx.annotation.NonNull;
|
|
4
|
-
|
|
5
|
-
import java.util.List;
|
|
6
|
-
|
|
7
|
-
import io.scanbot.sdk.barcode.entity.BarcodeItem;
|
|
8
|
-
import io.scanbot.sdk.barcode.entity.BarcodeMetadataKey;
|
|
9
|
-
import io.scanbot.sdk.ui.view.barcode.configuration.IBarcodeFilter;
|
|
10
|
-
|
|
11
|
-
public class BarcodeExtensionsFilter implements IBarcodeFilter {
|
|
12
|
-
@Override
|
|
13
|
-
public boolean acceptsBarcode(@NonNull BarcodeItem barcodeItem) {
|
|
14
|
-
return barcodeItem.getMetadata().containsKey(BarcodeMetadataKey.UpcEanExtension);
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
@Override
|
|
18
|
-
public boolean shouldAdd(@NonNull BarcodeItem barcodeItem, @NonNull List<BarcodeItem> list) {
|
|
19
|
-
if (this.acceptsBarcode(barcodeItem)) {
|
|
20
|
-
return !list.contains(barcodeItem);
|
|
21
|
-
}
|
|
22
|
-
return false;
|
|
23
|
-
}
|
|
24
|
-
}
|