react-native-scanbot-barcode-scanner-sdk 3.2.1-beta2 → 3.2.1-beta5
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 +22 -6
- 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 +52 -69
- package/android/src/main/java/io/scanbot/barcodesdk/plugin/reactnative/barcode/ScanbotBarcodeDetectorAdditionalConfigBuilder.java +36 -0
- package/android/src/main/java/io/scanbot/barcodesdk/plugin/reactnative/barcode/ScanbotBarcodeDetectorConfigBuilder.java +45 -0
- package/android/src/main/java/io/scanbot/barcodesdk/plugin/reactnative/components/barcodecameraview/ScanbotBarcodeCameraViewFragment.java +23 -28
- package/android/src/main/java/io/scanbot/barcodesdk/plugin/reactnative/components/barcodecameraview/ScanbotBarcodeCameraViewManager.java +1 -1
- package/android/src/main/java/io/scanbot/barcodesdk/plugin/reactnative/filters/ReactBarcodeExtensionsFilter.java +59 -0
- package/android/src/main/java/io/scanbot/barcodesdk/plugin/reactnative/utils/BitmapHelper.java +30 -0
- package/android/src/main/java/io/scanbot/barcodesdk/plugin/reactnative/utils/JSONUtils.java +286 -0
- package/android/src/main/java/io/scanbot/barcodesdk/plugin/reactnative/utils/LogUtils.java +40 -0
- package/android/src/main/java/io/scanbot/barcodesdk/plugin/reactnative/utils/ResponseUtils.java +41 -0
- package/ios/ScanbotBarcodeSdk.m +41 -49
- package/ios/Utils/BarcodeMapping.h +68 -13
- package/ios/Utils/ReactBarcodeExtensionsFilter.h +22 -0
- package/ios/Utils/ReactBarcodeExtensionsFilter.m +55 -0
- package/package.json +1 -1
- package/src/configuration.ts +10 -5
- package/src/enum.ts +5 -0
- package/android/src/main/java/io/scanbot/barcodesdk/plugin/reactnative/BarcodeExtensionsFilter.java +0 -24
|
@@ -0,0 +1,286 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Scanbot Barcode Scanner SDK React Native Plugin
|
|
3
|
+
Copyright (c) 2020 doo GmbH. All rights reserved.
|
|
4
|
+
https://scanbot.io/sdk
|
|
5
|
+
*/
|
|
6
|
+
package io.scanbot.barcodesdk.plugin.reactnative.utils;
|
|
7
|
+
|
|
8
|
+
import android.graphics.PointF;
|
|
9
|
+
import android.util.Log;
|
|
10
|
+
|
|
11
|
+
import androidx.annotation.NonNull;
|
|
12
|
+
import androidx.annotation.Nullable;
|
|
13
|
+
|
|
14
|
+
import com.facebook.react.bridge.Arguments;
|
|
15
|
+
import com.facebook.react.bridge.ReadableArray;
|
|
16
|
+
import com.facebook.react.bridge.ReadableMap;
|
|
17
|
+
import com.facebook.react.bridge.WritableArray;
|
|
18
|
+
import com.facebook.react.bridge.WritableMap;
|
|
19
|
+
import com.facebook.react.bridge.WritableNativeMap;
|
|
20
|
+
|
|
21
|
+
import org.jetbrains.annotations.NotNull;
|
|
22
|
+
|
|
23
|
+
import java.util.ArrayList;
|
|
24
|
+
import java.util.EnumSet;
|
|
25
|
+
import java.util.List;
|
|
26
|
+
import java.util.Objects;
|
|
27
|
+
|
|
28
|
+
import io.scanbot.barcodesdk.plugin.reactnative.filters.ReactBarcodeExtensionsFilter;
|
|
29
|
+
import io.scanbot.sdk.barcode.entity.BarcodeDocumentFormat;
|
|
30
|
+
import io.scanbot.sdk.barcode.entity.BarcodeFormat;
|
|
31
|
+
import io.scanbot.sdk.barcode.entity.BarcodeItem;
|
|
32
|
+
import io.scanbot.sdk.barcode.entity.BarcodeScannerAdditionalConfig;
|
|
33
|
+
import io.scanbot.sdk.barcode.entity.BarcodeScanningResult;
|
|
34
|
+
import io.scanbot.sdk.barcode.entity.EngineMode;
|
|
35
|
+
import io.scanbot.sdk.barcode.entity.MSIPlesseyChecksumAlgorithm;
|
|
36
|
+
import io.scanbot.sdk.ui.view.barcode.configuration.BarcodeFilter;
|
|
37
|
+
import io.scanbot.sdk.ui.view.barcode.configuration.BarcodeScannerAdditionalConfiguration;
|
|
38
|
+
import io.scanbot.sdk.ui.view.base.configuration.CameraOrientationMode;
|
|
39
|
+
|
|
40
|
+
public final class JSONUtils {
|
|
41
|
+
|
|
42
|
+
private JSONUtils() {}
|
|
43
|
+
|
|
44
|
+
public static class WritableMapBuilder {
|
|
45
|
+
|
|
46
|
+
private final WritableNativeMap _writableMap = new WritableNativeMap();
|
|
47
|
+
|
|
48
|
+
public WritableMapBuilder putBoolean(@NonNull String key, boolean value) {
|
|
49
|
+
_writableMap.putBoolean(key, value);
|
|
50
|
+
return this;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
public WritableMapBuilder putDouble(@NonNull String key, double value) {
|
|
54
|
+
_writableMap.putDouble(key, value);
|
|
55
|
+
return this;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
public WritableMapBuilder putInt(@NonNull String key, int value) {
|
|
59
|
+
_writableMap.putInt(key, value);
|
|
60
|
+
return this;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
public WritableMapBuilder putNull(@NonNull String key) {
|
|
64
|
+
_writableMap.putNull(key);
|
|
65
|
+
return this;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
public WritableMapBuilder putString(@NonNull String key, @Nullable String value) {
|
|
69
|
+
_writableMap.putString(key, value);
|
|
70
|
+
return this;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
public WritableMapBuilder putMap(@NonNull String key, @Nullable ReadableMap value) {
|
|
74
|
+
_writableMap.putMap(key, value);
|
|
75
|
+
return this;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
public WritableMapBuilder putArray(@NonNull String key, @Nullable ReadableArray value) {
|
|
79
|
+
_writableMap.putArray(key, value);
|
|
80
|
+
return this;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
public WritableMap build() {
|
|
84
|
+
return this._writableMap;
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
public static WritableArray sdkPolygonToWritableArray(final List<PointF> polygon) {
|
|
89
|
+
WritableArray points = Arguments.createArray();
|
|
90
|
+
if (polygon != null) {
|
|
91
|
+
for (final PointF p: polygon) {
|
|
92
|
+
WritableMap pointRecord = Arguments.createMap();
|
|
93
|
+
pointRecord.putDouble("x", p.x);
|
|
94
|
+
pointRecord.putDouble("y", p.y);
|
|
95
|
+
points.pushMap(pointRecord);
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
return points;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
public static ArrayList<BarcodeFormat> extractBarcodeFormats(@NotNull ReadableMap configuration) {
|
|
102
|
+
ArrayList<BarcodeFormat> nativeBarcodeFormats = new ArrayList<>();
|
|
103
|
+
if (configuration.hasKey("barcodeFormats")) {
|
|
104
|
+
ReadableArray barcodeFormats = configuration.getArray("barcodeFormats");
|
|
105
|
+
if (barcodeFormats != null) {
|
|
106
|
+
for (int i = 0; i < barcodeFormats.size(); ++i) {
|
|
107
|
+
nativeBarcodeFormats.add(BarcodeFormat.valueOf(barcodeFormats.getString(i)));
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
return nativeBarcodeFormats;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
public static ArrayList<BarcodeDocumentFormat> extractBarcodeDocumentFormats(final ReadableMap configuration) {
|
|
115
|
+
ArrayList<BarcodeDocumentFormat> nativeBarcodeDocumentFormats = new ArrayList<>();
|
|
116
|
+
ArrayList<String> barcodeDocumentFormats = JSONUtils.getStringArrayListFromMap(configuration, "acceptedDocumentFormats");
|
|
117
|
+
|
|
118
|
+
for (String format : barcodeDocumentFormats) {
|
|
119
|
+
nativeBarcodeDocumentFormats.add(BarcodeDocumentFormat.valueOf(format));
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
return nativeBarcodeDocumentFormats;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
public static @Nullable CameraOrientationMode extractCameraOrientationMode(final ReadableMap configuration) {
|
|
126
|
+
if (configuration.hasKey("allowedInterfaceOrientations")) {
|
|
127
|
+
String orientation = configuration.getString("allowedInterfaceOrientations");
|
|
128
|
+
if (orientation == null) {
|
|
129
|
+
orientation = "NONE";
|
|
130
|
+
}
|
|
131
|
+
switch (orientation) {
|
|
132
|
+
case "NONE":
|
|
133
|
+
break;
|
|
134
|
+
case "PORTRAIT":
|
|
135
|
+
case "PORTRAIT_UPSIDE_DOWN":
|
|
136
|
+
return CameraOrientationMode.PORTRAIT;
|
|
137
|
+
case "LANDSCAPE_LEFT":
|
|
138
|
+
case "LANDSCAPE_RIGHT":
|
|
139
|
+
case "LANDSCAPE":
|
|
140
|
+
return CameraOrientationMode.LANDSCAPE;
|
|
141
|
+
default:
|
|
142
|
+
return null;
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
return null;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
public static @Nullable BarcodeScannerAdditionalConfig extractBarcodeScannerAdditionalConfig(final ReadableMap configuration) {
|
|
150
|
+
boolean changed = false;
|
|
151
|
+
|
|
152
|
+
int minimumTextLength = BarcodeScannerAdditionalConfig.DEFAULT_MIN_TEXT_LENGTH;
|
|
153
|
+
if (configuration.hasKey("minimumTextLength")) {
|
|
154
|
+
minimumTextLength = configuration.getInt("minimumTextLength");
|
|
155
|
+
changed = true;
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
int maximumTextLength = BarcodeScannerAdditionalConfig.DEFAULT_MAX_TEXT_LENGTH;
|
|
159
|
+
if (configuration.hasKey("maximumTextLength")) {
|
|
160
|
+
maximumTextLength = configuration.getInt("maximumTextLength");
|
|
161
|
+
changed = true;
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
int minimum1DQuietZoneSize = BarcodeScannerAdditionalConfig.DEFAULT_MIN_1D_QUIET_ZONE_SIZE;
|
|
165
|
+
if (configuration.hasKey("minimum1DBarcodesQuietZone")) {
|
|
166
|
+
minimum1DQuietZoneSize = configuration.getInt("minimum1DBarcodesQuietZone");
|
|
167
|
+
changed = true;
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
boolean gs1DecodingEnabled = BarcodeScannerAdditionalConfig.DEFAULT_GS1_DECODING_ENABLED;
|
|
171
|
+
if (configuration.hasKey("gs1DecodingEnabled")) {
|
|
172
|
+
gs1DecodingEnabled = configuration.getBoolean("gs1DecodingEnabled");
|
|
173
|
+
changed = true;
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
EnumSet<MSIPlesseyChecksumAlgorithm> msiPlesseyChecksumAlgorithms =
|
|
177
|
+
BarcodeScannerAdditionalConfig.Companion.getDEFAULT_MSI_PLESSEY_CHECKSUM_ALGORITHMS();
|
|
178
|
+
if (configuration.hasKey("msiPlesseyChecksumAlgorithm")) {
|
|
179
|
+
msiPlesseyChecksumAlgorithms.clear();
|
|
180
|
+
String algorithm = configuration.getString("msiPlesseyChecksumAlgorithm");
|
|
181
|
+
msiPlesseyChecksumAlgorithms.add(MSIPlesseyChecksumAlgorithm.valueOf(algorithm));
|
|
182
|
+
changed = true;
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
boolean stripCheckDigits = BarcodeScannerAdditionalConfig.DEFAULT_STRIP_CHECK_DIGITS;
|
|
186
|
+
if (configuration.hasKey("stripCheckDigits")) {
|
|
187
|
+
stripCheckDigits = configuration.getBoolean("stripCheckDigits");
|
|
188
|
+
changed = true;
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
boolean lowPowerMode = BarcodeScannerAdditionalConfig.DEFAULT_LOW_POWER_MODE;
|
|
192
|
+
if (configuration.hasKey("lowPowerMode")) {
|
|
193
|
+
lowPowerMode = configuration.getBoolean("lowPowerMode");
|
|
194
|
+
changed = true;
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
return changed ? new BarcodeScannerAdditionalConfig(
|
|
198
|
+
minimumTextLength,
|
|
199
|
+
maximumTextLength,
|
|
200
|
+
minimum1DQuietZoneSize,
|
|
201
|
+
gs1DecodingEnabled,
|
|
202
|
+
msiPlesseyChecksumAlgorithms,
|
|
203
|
+
stripCheckDigits,
|
|
204
|
+
lowPowerMode
|
|
205
|
+
) : null;
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
public static @Nullable BarcodeScannerAdditionalConfiguration extractBarcodeScannerAdditionalConfiguration(final ReadableMap configuration) {
|
|
209
|
+
final BarcodeScannerAdditionalConfig config = extractBarcodeScannerAdditionalConfig(configuration);
|
|
210
|
+
return config != null ? new BarcodeScannerAdditionalConfiguration(
|
|
211
|
+
config.getMinimumTextLength(),
|
|
212
|
+
config.getMaximumTextLength(),
|
|
213
|
+
config.getMinimum1DQuietZoneSize(),
|
|
214
|
+
config.getGs1DecodingEnabled(),
|
|
215
|
+
config.getMsiPlesseyChecksumAlgorithms(),
|
|
216
|
+
config.getStripCheckDigits(),
|
|
217
|
+
config.getLowPowerMode()
|
|
218
|
+
) : null;
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
public static BarcodeFilter extractBarcodeFilter(final ReadableMap options) {
|
|
222
|
+
if (!options.hasKey("barcodeFilter")) {
|
|
223
|
+
return null;
|
|
224
|
+
}
|
|
225
|
+
final String filterType = options.getString("barcodeFilter");
|
|
226
|
+
try {
|
|
227
|
+
final ReactBarcodeExtensionsFilter.Type type =
|
|
228
|
+
ReactBarcodeExtensionsFilter.Type.valueOf(filterType);
|
|
229
|
+
return new ReactBarcodeExtensionsFilter(type);
|
|
230
|
+
}
|
|
231
|
+
catch (IllegalArgumentException exception) {
|
|
232
|
+
final String errMsg = String.format("The value passed in 'barcodeFilter' (%s) does not exist", filterType);
|
|
233
|
+
Log.e("SCANBOT_SDK", errMsg);
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
return null;
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
public static List<BarcodeItem> getBarcodeItemsFromResultWithFilter(BarcodeScanningResult result, BarcodeFilter filter) {
|
|
240
|
+
if (result == null) {
|
|
241
|
+
return new ArrayList<>();
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
final List<BarcodeItem> filteredBarcodeItems = new ArrayList<>();
|
|
245
|
+
for (BarcodeItem barcodeItem : result.getBarcodeItems()) {
|
|
246
|
+
if (!filter.acceptsBarcode(barcodeItem)) { continue; }
|
|
247
|
+
filteredBarcodeItems.add(barcodeItem);
|
|
248
|
+
}
|
|
249
|
+
return filteredBarcodeItems;
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
public static ArrayList<String> getStringArrayListFromMap(final ReadableMap configuration, final String key) {
|
|
253
|
+
ArrayList<String> out = new ArrayList<>();
|
|
254
|
+
if(!configuration.hasKey(key)) {
|
|
255
|
+
return out;
|
|
256
|
+
}
|
|
257
|
+
ReadableArray nullable = configuration.getArray(key);
|
|
258
|
+
if (nullable != null) {
|
|
259
|
+
ArrayList<Object> objects = nullable.toArrayList();
|
|
260
|
+
for (Object obj : objects) {
|
|
261
|
+
try { out.add(Objects.toString(obj)); }
|
|
262
|
+
catch (ClassCastException ignored) {}
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
return out;
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
public static EngineMode extractEngineMode(ReadableMap configuration) {
|
|
269
|
+
if (!configuration.hasKey("engineMode")) {
|
|
270
|
+
return EngineMode.NextGen;
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
String mode = configuration.getString("engineMode");
|
|
274
|
+
if ("LEGACY".equals(mode)) {
|
|
275
|
+
return EngineMode.Legacy;
|
|
276
|
+
}
|
|
277
|
+
return EngineMode.NextGen;
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
public static boolean getBoolOrFalse(final ReadableMap map, final String key) {
|
|
281
|
+
if (!map.hasKey(key)) {
|
|
282
|
+
return false;
|
|
283
|
+
}
|
|
284
|
+
return map.getBoolean(key);
|
|
285
|
+
}
|
|
286
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Scanbot Barcode Scanner SDK React Native Plugin
|
|
3
|
+
Copyright (c) 2020 doo GmbH. All rights reserved.
|
|
4
|
+
https://scanbot.io/sdk
|
|
5
|
+
*/
|
|
6
|
+
package io.scanbot.barcodesdk.plugin.reactnative.utils;
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
import android.util.Log;
|
|
10
|
+
|
|
11
|
+
public final class LogUtils {
|
|
12
|
+
|
|
13
|
+
// global static loggingEnabled flag (set on ScanbotSdkPlugin.initializeSdk(..))
|
|
14
|
+
private static boolean loggingEnabled = false;
|
|
15
|
+
|
|
16
|
+
private LogUtils() {}
|
|
17
|
+
|
|
18
|
+
public static synchronized void setLoggingEnabled(final boolean flag) {
|
|
19
|
+
loggingEnabled = flag;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
public static synchronized boolean isLoggingEnabled() {
|
|
23
|
+
return loggingEnabled;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
public static void debugLog(final String logTag, final String msg) {
|
|
27
|
+
if (loggingEnabled) {
|
|
28
|
+
Log.d(logTag, msg);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
public static void errorLog(final String logTag, final String msg) {
|
|
33
|
+
Log.e(logTag, msg);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
public static void errorLog(final String logTag, final String msg, final Throwable e) {
|
|
37
|
+
Log.e(logTag, msg, e);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
}
|
package/android/src/main/java/io/scanbot/barcodesdk/plugin/reactnative/utils/ResponseUtils.java
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Scanbot Barcode Scanner SDK React Native Plugin
|
|
3
|
+
Copyright (c) 2020 doo GmbH. All rights reserved.
|
|
4
|
+
https://scanbot.io/sdk
|
|
5
|
+
*/
|
|
6
|
+
package io.scanbot.barcodesdk.plugin.reactnative.utils;
|
|
7
|
+
|
|
8
|
+
import android.view.View;
|
|
9
|
+
|
|
10
|
+
import com.facebook.react.bridge.Arguments;
|
|
11
|
+
import com.facebook.react.bridge.Promise;
|
|
12
|
+
import com.facebook.react.bridge.ReactContext;
|
|
13
|
+
import com.facebook.react.bridge.WritableMap;
|
|
14
|
+
import com.facebook.react.uimanager.events.RCTEventEmitter;
|
|
15
|
+
|
|
16
|
+
public class ResponseUtils {
|
|
17
|
+
|
|
18
|
+
public static void successMessageJson(final String msg, final Promise promise) {
|
|
19
|
+
final WritableMap response = Arguments.createMap();
|
|
20
|
+
response.putString("status", "OK");
|
|
21
|
+
response.putString("message", msg);
|
|
22
|
+
promise.resolve(response);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
public static void successCanceled(final Promise promise) {
|
|
26
|
+
final WritableMap response = Arguments.createMap();
|
|
27
|
+
response.putString("status", "CANCELED");
|
|
28
|
+
promise.resolve(response);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
public static void errorMessageJson(final String msg, final Promise promise) {
|
|
32
|
+
final WritableMap response = Arguments.createMap();
|
|
33
|
+
response.putString("error", msg);
|
|
34
|
+
promise.reject(msg);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
public static void sendReactEvent(String eventName, WritableMap event, View view) {
|
|
38
|
+
final ReactContext reactContext = (ReactContext)view.getContext();
|
|
39
|
+
reactContext.getJSModule(RCTEventEmitter.class).receiveEvent(view.getId(), eventName, event);
|
|
40
|
+
}
|
|
41
|
+
}
|
package/ios/ScanbotBarcodeSdk.m
CHANGED
|
@@ -40,13 +40,13 @@ RCT_EXPORT_METHOD(initializeSdk:(NSDictionary *)configuration
|
|
|
40
40
|
{
|
|
41
41
|
[ObjectMapper setEnumerationMapping:@{
|
|
42
42
|
@"barcodeImageGenerationType": @{
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
43
|
+
@"NONE": @(SBSDKBarcodeImageGenerationTypeNone),
|
|
44
|
+
@"VIDEO_FRAME": @(SBSDKBarcodeImageGenerationTypeFromVideoFrame),
|
|
45
|
+
@"CAPTURED_IMAGE" :@(SBSDKBarcodeImageGenerationTypeCapturedImage),
|
|
46
46
|
},
|
|
47
47
|
@"engineMode": @{
|
|
48
|
-
|
|
49
|
-
|
|
48
|
+
@"LEGACY": @(SBSDKBarcodeEngineModeLegacy),
|
|
49
|
+
@"NEXT_GEN": @(SBSDKBarcodeEngineModeNextGen)
|
|
50
50
|
},
|
|
51
51
|
@"allowedInterfaceOrientations": @{
|
|
52
52
|
@"NONE": @(UIInterfaceOrientationMaskAll),
|
|
@@ -120,35 +120,24 @@ RCT_EXPORT_METHOD(startBarcodeScanner:(NSDictionary*)configuration
|
|
|
120
120
|
SBSDKUIBarcodeScannerUIConfiguration* uiConfig = [[SBSDKUIBarcodeScannerUIConfiguration alloc] init];
|
|
121
121
|
SBSDKUIBarcodeScannerBehaviorConfiguration* behaviorConfig = [[SBSDKUIBarcodeScannerBehaviorConfiguration alloc] init];
|
|
122
122
|
SBSDKUIBarcodeScannerTextConfiguration* textConfig = [[SBSDKUIBarcodeScannerTextConfiguration alloc] init];
|
|
123
|
-
SBSDKBarcodeAdditionalParameters* additionalParameters = [[SBSDKBarcodeAdditionalParameters alloc] init];
|
|
124
123
|
|
|
125
124
|
@try {
|
|
126
125
|
[ObjectMapper populateInstance:uiConfig fromDictionary:configuration];
|
|
127
126
|
[ObjectMapper populateInstance:behaviorConfig fromDictionary:configuration];
|
|
128
127
|
[ObjectMapper populateInstance:textConfig fromDictionary:configuration];
|
|
129
|
-
[ObjectMapper populateInstance:additionalParameters fromDictionary:configuration];
|
|
130
128
|
}
|
|
131
129
|
@catch (NSException* ex) {
|
|
132
130
|
reject(@"Property error", [ex reason], nil);
|
|
133
131
|
return;
|
|
134
132
|
}
|
|
135
133
|
|
|
136
|
-
//
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
additionalParameters.enableGS1Decoding = [gs1Decoding boolValue];
|
|
134
|
+
// Barcode Filter (at the moment used for UPC Extension filters)
|
|
135
|
+
SBSDKUIBarcodeFilter* barcodeFilter = extractBarcodeFilter(configuration);
|
|
136
|
+
if (barcodeFilter != nil) {
|
|
137
|
+
behaviorConfig.barcodeFilter = barcodeFilter;
|
|
141
138
|
}
|
|
142
139
|
|
|
143
|
-
|
|
144
|
-
NSNumber* shouldApplyExtensionFilter = [configuration objectForKey:@"onlyAcceptCodesWithExtensions"];
|
|
145
|
-
if (shouldApplyExtensionFilter != nil && [shouldApplyExtensionFilter boolValue]) {
|
|
146
|
-
behaviorConfig.barcodeFilter = [[SBSDKUIBarcodeExtensionsFilter alloc] init];
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
additionalParameters.msiPlesseyChecksumAlgorithm = extractPlesseyChecksumAlgorithmFromConfiguration(configuration);
|
|
150
|
-
|
|
151
|
-
behaviorConfig.additionalParameters = additionalParameters;
|
|
140
|
+
behaviorConfig.additionalParameters = extractAdditionalParameters(configuration);
|
|
152
141
|
|
|
153
142
|
NSArray* machineCodeTypes = extractBarcodeTypesFromConfiguration(configuration);
|
|
154
143
|
NSArray* acceptedDocumentTypes = extractBarcodeDocumentTypesFromConfiguration(configuration);
|
|
@@ -184,47 +173,34 @@ RCT_EXPORT_METHOD(closeBarcodeScanner:(RCTPromiseResolveBlock)resolve
|
|
|
184
173
|
RCT_EXPORT_METHOD(startBatchBarcodeScanner:(NSDictionary*)configuration
|
|
185
174
|
withResolver:(RCTPromiseResolveBlock)resolve
|
|
186
175
|
withRejecter:(RCTPromiseRejectBlock)reject) {
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
SBSDKUIBarcodesBatchScannerTextConfiguration *text =
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
[[SBSDKUIBarcodesBatchScannerBehaviorConfiguration alloc] init];
|
|
193
|
-
SBSDKBarcodeAdditionalParameters* additionalParameters = [[SBSDKBarcodeAdditionalParameters alloc] init];
|
|
194
|
-
|
|
176
|
+
|
|
177
|
+
SBSDKUIBarcodesBatchScannerUIConfiguration *ui = [[SBSDKUIBarcodesBatchScannerUIConfiguration alloc] init];
|
|
178
|
+
SBSDKUIBarcodesBatchScannerTextConfiguration *text = [[SBSDKUIBarcodesBatchScannerTextConfiguration alloc] init];
|
|
179
|
+
SBSDKUIBarcodesBatchScannerBehaviorConfiguration *behavior = [[SBSDKUIBarcodesBatchScannerBehaviorConfiguration alloc] init];
|
|
180
|
+
|
|
195
181
|
@try {
|
|
196
182
|
[ObjectMapper populateInstance:ui fromDictionary:configuration];
|
|
197
183
|
[ObjectMapper populateInstance:behavior fromDictionary:configuration];
|
|
198
184
|
[ObjectMapper populateInstance:text fromDictionary:configuration];
|
|
199
|
-
[ObjectMapper populateInstance:additionalParameters fromDictionary:configuration];
|
|
200
185
|
}
|
|
201
186
|
@catch (NSException* ex) {
|
|
202
187
|
reject(@"Property error", [ex reason], nil);
|
|
203
188
|
return;
|
|
204
189
|
}
|
|
205
|
-
|
|
206
|
-
//
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
additionalParameters.enableGS1Decoding = [gs1Decoding boolValue];
|
|
211
|
-
}
|
|
212
|
-
|
|
213
|
-
// UPC Extension filter
|
|
214
|
-
NSNumber* shouldApplyExtensionFilter = [configuration objectForKey:@"onlyAcceptCodesWithExtensions"];
|
|
215
|
-
if (shouldApplyExtensionFilter != nil && [shouldApplyExtensionFilter boolValue]) {
|
|
216
|
-
behavior.barcodeFilter = [[SBSDKUIBarcodeExtensionsFilter alloc] init];
|
|
190
|
+
|
|
191
|
+
// Barcode Filter (at the moment used for UPC Extension filters)
|
|
192
|
+
SBSDKUIBarcodeFilter* barcodeFilter = extractBarcodeFilter(configuration);
|
|
193
|
+
if (barcodeFilter != nil) {
|
|
194
|
+
behavior.barcodeFilter = barcodeFilter;
|
|
217
195
|
}
|
|
218
196
|
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
behavior.additionalDetectionParameters = additionalParameters;
|
|
222
|
-
|
|
197
|
+
behavior.additionalDetectionParameters = extractAdditionalParameters(configuration);
|
|
198
|
+
|
|
223
199
|
SBSDKUIBarcodesBatchScannerConfiguration *config = [[SBSDKUIBarcodesBatchScannerConfiguration alloc]
|
|
224
200
|
initWithUIConfiguration:ui
|
|
225
201
|
textConfiguration:text
|
|
226
202
|
behaviorConfiguration:behavior];
|
|
227
|
-
|
|
203
|
+
|
|
228
204
|
NSArray* machineCodeTypes = extractBarcodeTypesFromConfiguration(configuration);
|
|
229
205
|
NSArray* acceptedDocumentTypes = extractBarcodeDocumentTypesFromConfiguration(configuration);
|
|
230
206
|
|
|
@@ -270,16 +246,32 @@ RCT_EXPORT_METHOD(detectBarcodesOnImage:(NSDictionary *)configuration
|
|
|
270
246
|
return;
|
|
271
247
|
}
|
|
272
248
|
|
|
273
|
-
NSArray* barcodeTypes = [ScanbotBarcodeSdk extractBarcodeTypesFromConfiguration:configuration];
|
|
274
|
-
|
|
275
249
|
runInBackground(^{
|
|
250
|
+
|
|
251
|
+
NSArray* barcodeTypes = [ScanbotBarcodeSdk extractBarcodeTypesFromConfiguration:configuration];
|
|
276
252
|
SBSDKBarcodeScanner* barcodeScanner = [[SBSDKBarcodeScanner alloc] initWithTypes:barcodeTypes];
|
|
253
|
+
|
|
254
|
+
NSArray* barcodeDocumentTypes = extractBarcodeDocumentTypesFromConfiguration(configuration);
|
|
255
|
+
[barcodeScanner setAcceptedDocumentTypes: barcodeDocumentTypes];
|
|
256
|
+
|
|
257
|
+
SBSDKBarcodeEngineMode engineMode = extractEngineMode(configuration);
|
|
258
|
+
[barcodeScanner setEngineMode:engineMode];
|
|
259
|
+
|
|
260
|
+
SBSDKBarcodeAdditionalParameters* additionalParameters = extractAdditionalParameters(configuration);
|
|
261
|
+
[barcodeScanner setAdditionalParameters:additionalParameters];
|
|
262
|
+
|
|
277
263
|
UIImage* image = [ScanbotStorageUtils loadImage:imageUri];
|
|
278
264
|
if (!image) {
|
|
279
265
|
[self reportErrorWithMessage:@"Image could not be loaded." reject:reject];
|
|
280
266
|
return;
|
|
281
267
|
}
|
|
282
268
|
NSArray<SBSDKBarcodeScannerResult *> *barcodeResults = [barcodeScanner detectBarCodesOnImage:image];
|
|
269
|
+
|
|
270
|
+
SBSDKUIBarcodeFilter* barcodeFilter = extractBarcodeFilter(configuration);
|
|
271
|
+
if (barcodeFilter != nil) {
|
|
272
|
+
barcodeResults = filterBarcodeResults(barcodeResults, barcodeFilter);
|
|
273
|
+
}
|
|
274
|
+
|
|
283
275
|
resolve(@{
|
|
284
276
|
@"status": @"OK",
|
|
285
277
|
@"barcodes": jsonFromBarcodeResults(barcodeResults),
|
|
@@ -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,54 @@ static inline NSArray<NSDictionary<NSString*, NSObject*>*>* jsonFromMappedBarcod
|
|
|
86
87
|
return [jsonResults copy];
|
|
87
88
|
}
|
|
88
89
|
|
|
90
|
+
static inline SBSDKBarcodeMSIPlesseyChecksumAlgorithm extractPlesseyChecksumAlgorithmFromConfiguration(NSDictionary* configuration) {
|
|
91
|
+
NSString* algorithm = [configuration objectForKey:@"msiPlesseyChecksumAlgorithm"];
|
|
92
|
+
|
|
93
|
+
if (algorithm != nil) {
|
|
94
|
+
if ([algorithm isEqualToString:@"None"]) return SBSDKBarcodeMSIPlesseyChecksumAlgorithmNone;
|
|
95
|
+
if ([algorithm isEqualToString:@"Mod10"]) return SBSDKBarcodeMSIPlesseyChecksumAlgorithmMod10;
|
|
96
|
+
if ([algorithm isEqualToString:@"Mod1010"]) return SBSDKBarcodeMSIPlesseyChecksumAlgorithmMod1010;
|
|
97
|
+
if ([algorithm isEqualToString:@"Mod11IBM"]) return SBSDKBarcodeMSIPlesseyChecksumAlgorithmMod11IBM;
|
|
98
|
+
if ([algorithm isEqualToString:@"Mod11NCR"]) return SBSDKBarcodeMSIPlesseyChecksumAlgorithmMod11NCR;
|
|
99
|
+
if ([algorithm isEqualToString:@"Mod1110IBM"]) return SBSDKBarcodeMSIPlesseyChecksumAlgorithmMod1110IBM;
|
|
100
|
+
if ([algorithm isEqualToString:@"Mod1110NCR"]) return SBSDKBarcodeMSIPlesseyChecksumAlgorithmMod1110NCR;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
return SBSDKBarcodeMSIPlesseyChecksumAlgorithmMod10;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
static inline SBSDKUIBarcodeFilter* extractBarcodeFilter(NSDictionary* configuration) {
|
|
107
|
+
NSString* jsonFilterType = [configuration objectForKey:@"barcodeFilter"];
|
|
108
|
+
if (jsonFilterType == nil) {
|
|
109
|
+
return nil;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
if ([jsonFilterType isEqualToString:@"WithExtension"]) {
|
|
113
|
+
return [[ReactBarcodeExtensionsFilter alloc] init:ReactBarcodeExtensionsFilterWithExtension];
|
|
114
|
+
} else if ([jsonFilterType isEqualToString:@"WithEAN2Extension"]) {
|
|
115
|
+
return [[ReactBarcodeExtensionsFilter alloc] init:ReactBarcodeExtensionsFilterWithEAN2Extension];
|
|
116
|
+
} else if ([jsonFilterType isEqualToString:@"WithEAN5Extension"]) {
|
|
117
|
+
return [[ReactBarcodeExtensionsFilter alloc] init:ReactBarcodeExtensionsFilterWithEAN5Extension];
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
return nil;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
static inline NSArray* filterBarcodeResults(NSArray<SBSDKBarcodeScannerResult *>* barcodeResults, SBSDKUIBarcodeFilter* filter) {
|
|
124
|
+
NSMutableArray<SBSDKBarcodeScannerResult *>* outResults = [[NSMutableArray alloc] init];
|
|
125
|
+
|
|
126
|
+
if (barcodeResults == nil) {
|
|
127
|
+
return outResults;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
for (SBSDKBarcodeScannerResult* result in barcodeResults) {
|
|
131
|
+
if (![filter acceptsBarcode:result]) { continue; }
|
|
132
|
+
[outResults addObject:result];
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
return outResults;
|
|
136
|
+
}
|
|
137
|
+
|
|
89
138
|
static inline NSArray* extractBarcodeTypesFromConfiguration(NSDictionary* configuration) {
|
|
90
139
|
NSArray* barcodeFormats = [configuration objectForKey:@"barcodeFormats"];
|
|
91
140
|
if (barcodeFormats && [barcodeFormats indexOfObject:@"ALL_FORMATS"] == NSNotFound) {
|
|
@@ -126,20 +175,26 @@ static inline SBSDKBarcodeEngineMode extractEngineMode(NSDictionary* configurati
|
|
|
126
175
|
return SBSDKBarcodeEngineModeNextGen;
|
|
127
176
|
}
|
|
128
177
|
|
|
129
|
-
static inline
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
if ([algorithm isEqualToString:@"None"]) return SBSDKBarcodeMSIPlesseyChecksumAlgorithmNone;
|
|
134
|
-
if ([algorithm isEqualToString:@"Mod10"]) return SBSDKBarcodeMSIPlesseyChecksumAlgorithmMod10;
|
|
135
|
-
if ([algorithm isEqualToString:@"Mod1010"]) return SBSDKBarcodeMSIPlesseyChecksumAlgorithmMod1010;
|
|
136
|
-
if ([algorithm isEqualToString:@"Mod11IBM"]) return SBSDKBarcodeMSIPlesseyChecksumAlgorithmMod11IBM;
|
|
137
|
-
if ([algorithm isEqualToString:@"Mod11NCR"]) return SBSDKBarcodeMSIPlesseyChecksumAlgorithmMod11NCR;
|
|
138
|
-
if ([algorithm isEqualToString:@"Mod1110IBM"]) return SBSDKBarcodeMSIPlesseyChecksumAlgorithmMod1110IBM;
|
|
139
|
-
if ([algorithm isEqualToString:@"Mod1110NCR"]) return SBSDKBarcodeMSIPlesseyChecksumAlgorithmMod1110NCR;
|
|
178
|
+
static inline SBSDKBarcodeAdditionalParameters* extractAdditionalParameters(NSDictionary* configuration) {
|
|
179
|
+
SBSDKBarcodeAdditionalParameters* additionalParameters = [[SBSDKBarcodeAdditionalParameters alloc] init];
|
|
180
|
+
@try {
|
|
181
|
+
[ObjectMapper populateInstance:additionalParameters fromDictionary:configuration];
|
|
140
182
|
}
|
|
141
|
-
|
|
142
|
-
|
|
183
|
+
@catch (NSException* ex) {
|
|
184
|
+
return nil;
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
// Need to manually extract because of naming disparity between iOS and Android
|
|
188
|
+
// Also, it is nullable, 'true' by default, so we wrap it in an NSNumber
|
|
189
|
+
NSNumber* gs1Decoding = [configuration objectForKey:@"gs1DecodingEnabled"];
|
|
190
|
+
if (gs1Decoding != nil) {
|
|
191
|
+
additionalParameters.enableGS1Decoding = [gs1Decoding boolValue];
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
// We also need to manually extract the MSI-Plessey Checksum Algorithm since it can't be mapped automatically
|
|
195
|
+
additionalParameters.msiPlesseyChecksumAlgorithm = extractPlesseyChecksumAlgorithmFromConfiguration(configuration);
|
|
196
|
+
|
|
197
|
+
return additionalParameters;
|
|
143
198
|
}
|
|
144
199
|
|
|
145
200
|
static inline SBSDKUICameraConfiguration* extractCameraConfiguration(NSDictionary* configuration) {
|
|
@@ -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
|