react-native-scanbot-barcode-scanner-sdk 3.7.0-alpha.1 → 3.7.0-beta.2

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.
@@ -6,6 +6,7 @@
6
6
  package io.scanbot.barcodesdk.plugin.reactnative;
7
7
 
8
8
  import android.graphics.Color;
9
+ import android.util.Log;
9
10
 
10
11
  import com.facebook.react.bridge.ReadableMap;
11
12
 
@@ -14,6 +15,7 @@ import java.lang.reflect.Method;
14
15
  import java.util.HashMap;
15
16
  import java.util.Map;
16
17
 
18
+ import io.scanbot.barcodesdk.plugin.reactnative.utils.LogUtils;
17
19
  import io.scanbot.sdk.ui.camera.FinderAspectRatio;
18
20
 
19
21
  public final class ObjectMapper {
@@ -25,8 +27,9 @@ public final class ObjectMapper {
25
27
  * Properties listed here will be skipped by the Object Mapper
26
28
  */
27
29
  private final static String[] kIgnoredProperties = new String[] {
28
- "engineMode",
29
- "barcodeFilter"
30
+ "engineMode",
31
+ "barcodeFilter",
32
+ "cameraZoomRange"
30
33
  };
31
34
 
32
35
  public static class InvalidJSONException extends RuntimeException {
@@ -67,7 +70,7 @@ public final class ObjectMapper {
67
70
  }
68
71
 
69
72
  for (HashMap.Entry<String, Object> entry : source.entrySet()) {
70
- final String prop = entry.getKey();
73
+ String prop = entry.getKey();
71
74
  Object value = entry.getValue();
72
75
  if (value == null) {
73
76
  continue;
@@ -82,6 +85,11 @@ public final class ObjectMapper {
82
85
  value = "FRONT_MIRRORED";
83
86
  }
84
87
 
88
+ // for android this property is "initialScanDelayMs" and iOS is "initialScanDelay".
89
+ if (prop == "initialScanDelay") {
90
+ prop = "initialScanDelayMs";
91
+ }
92
+
85
93
  final String setterName = "set" + prop.substring(0, 1).toUpperCase() + prop.substring(1);
86
94
 
87
95
  if (methodMap.containsKey(setterName)) {
@@ -50,6 +50,7 @@ import io.scanbot.sdk.barcode.entity.BarcodeScanningResult;
50
50
  import io.scanbot.sdk.barcode.entity.EngineMode;
51
51
  import io.scanbot.sdk.barcode_scanner.ScanbotBarcodeScannerSDK;
52
52
  import io.scanbot.sdk.barcode_scanner.ScanbotBarcodeScannerSDKInitializer;
53
+ import io.scanbot.sdk.camera.ZoomRange;
53
54
  import io.scanbot.sdk.ui.barcode_scanner.view.barcode.BarcodeScannerActivity;
54
55
  import io.scanbot.sdk.ui.barcode_scanner.view.barcode.batch.BatchBarcodeScannerActivity;
55
56
  import io.scanbot.sdk.ui.view.barcode.SelectionOverlayConfiguration;
@@ -307,6 +308,15 @@ public class ScanbotBarcodeSdkModule extends ReactContextBaseJavaModule implemen
307
308
  configuration.setSelectionOverlayConfiguration(overlayConfiguration);
308
309
  }
309
310
  }
311
+
312
+ if (options.hasKey("cameraZoomRange")) {
313
+ final ZoomRange zoomRange = JSONUtils.extractCameraZoomRange(options);
314
+ if (zoomRange != null) {
315
+ configuration.setCameraZoomRange(zoomRange);
316
+ }
317
+ }
318
+
319
+ configuration.setCameraPreviewMode(JSONUtils.extractCameraPreviewMode(options));
310
320
  }
311
321
 
312
322
  @ReactMethod
@@ -37,6 +37,8 @@ import io.scanbot.sdk.barcode.entity.EngineMode;
37
37
  import io.scanbot.sdk.barcode.entity.MSIPlesseyChecksumAlgorithm;
38
38
  import io.scanbot.sdk.barcode.BarcodeFilter;
39
39
  import io.scanbot.sdk.barcode.ui.BarcodeOverlayTextFormat;
40
+ import io.scanbot.sdk.camera.CameraPreviewMode;
41
+ import io.scanbot.sdk.camera.ZoomRange;
40
42
  import io.scanbot.sdk.ui.view.barcode.SelectionOverlayConfiguration;
41
43
  import io.scanbot.sdk.ui.view.barcode.configuration.BarcodeScannerAdditionalConfiguration;
42
44
  import io.scanbot.sdk.ui.view.base.configuration.CameraOrientationMode;
@@ -412,12 +414,38 @@ public final class JSONUtils {
412
414
  }
413
415
 
414
416
  switch (textFormatString) {
415
- case "NONE":return BarcodeOverlayTextFormat.NONE;
416
- case "CODE": return BarcodeOverlayTextFormat.CODE;
417
- case "CODE_AND_TYPE": return BarcodeOverlayTextFormat.CODE_AND_TYPE;
417
+ case "NONE":
418
+ return BarcodeOverlayTextFormat.NONE;
419
+ case "CODE":
420
+ return BarcodeOverlayTextFormat.CODE;
421
+ case "CODE_AND_TYPE":
422
+ return BarcodeOverlayTextFormat.CODE_AND_TYPE;
418
423
  default:
419
424
  Log.w("ScanbotSDK", "Invalid overlay text format: " + textFormatString + ". Using default");
420
- return BarcodeOverlayTextFormat.CODE_AND_TYPE;
425
+ return BarcodeOverlayTextFormat.CODE_AND_TYPE;
421
426
  }
422
427
  }
423
- }
428
+
429
+ public static CameraPreviewMode extractCameraPreviewMode(ReadableMap configuration) {
430
+ CameraPreviewMode mode = CameraPreviewMode.FILL_IN;
431
+ if (!configuration.hasKey("cameraPreviewMode") || configuration.getString("cameraPreviewMode") == null) {
432
+ return mode;
433
+ }
434
+ String cameraPreviewModeString = configuration.getString("cameraPreviewMode");
435
+ if (cameraPreviewModeString.equals("FIT_IN")) {
436
+ mode = CameraPreviewMode.FIT_IN;
437
+ }
438
+ return mode;
439
+ }
440
+
441
+ public static ZoomRange extractCameraZoomRange(ReadableMap configuration) {
442
+ ZoomRange zoomRange = new ZoomRange();
443
+ if (configuration.hasKey("cameraZoomRange") && configuration.getMap("cameraZoomRange") != null) {
444
+ ReadableMap zoomRangeConfiguration = configuration.getMap("cameraZoomRange");
445
+ float maxZoom = (float)zoomRangeConfiguration.getDouble("maxZoom");
446
+ float minZoom = (float)zoomRangeConfiguration.getDouble("minZoom");
447
+ zoomRange = new ZoomRange(minZoom, maxZoom);
448
+ }
449
+ return zoomRange;
450
+ }
451
+ }
@@ -55,6 +55,7 @@
55
55
  @property (nonatomic) SBSDKUIBarcodeFilter* _Nullable barcodeFilter;
56
56
  @property (nonatomic) SBSDKBarcodeDensity codeDensity;
57
57
  @property (nonatomic) UIEdgeInsets finderInset;
58
+ @property (nonatomic) SBSDKZoomRange* _Nullable zoomRange;
58
59
  @end
59
60
 
60
61
  #endif /* RNScanbotCameraView_h */
@@ -45,15 +45,21 @@
45
45
  if (!parentViewController) {
46
46
  return;
47
47
  }
48
-
48
+ BOOL isInit = false;
49
49
  if (!_cameraViewController) {
50
50
  viewController = [[SBSDKBarcodeScannerViewController alloc] initWithParentViewController:parentViewController
51
51
  parentView:self
52
52
  delegate:self];
53
53
  _cameraViewController = viewController;
54
+ isInit = true;
55
+ }
56
+
57
+ // Temporary workaround for flashEnabled property.
58
+ if (isInit && _cameraViewConfiguration.flashEnabled) {
59
+ [self applyConfigurationWithDelay:0.5];
60
+ } else {
61
+ [self applyConfiguration];
54
62
  }
55
-
56
- [self updateWithConfiguration];
57
63
  }
58
64
 
59
65
  - (void)setConfiguration:(NSDictionary *)configuration {
@@ -85,8 +91,8 @@
85
91
  cameraViewConfiguration.msiPlesseyChecksumAlgorithm = extractPlesseyChecksumAlgorithmFromConfiguration(configuration);
86
92
  cameraViewConfiguration.codeDensity = extractBarcodeDensity(config);
87
93
  cameraViewConfiguration.finderInset = [self populateFinderInset:config];
88
-
89
94
  self.shouldUseFinderView = [[config objectForKey:@"shouldUseFinderView"] boolValue];
95
+ cameraViewConfiguration.zoomRange = extractCameraZoomRange(config);
90
96
 
91
97
  } @catch (NSException *exception) {
92
98
  NSLog(@"%@", [exception reason]);
@@ -96,11 +102,11 @@
96
102
  _cameraViewConfiguration = cameraViewConfiguration;
97
103
 
98
104
  if(viewController) {
99
- [self updateWithConfiguration];
105
+ [self applyConfiguration];
100
106
  }
101
107
  }
102
108
 
103
- - (void)updateWithConfiguration {
109
+ - (void)applyConfiguration {
104
110
 
105
111
  SBSDKBaseScannerViewFinderConfiguration *configuration = [[SBSDKBaseScannerViewFinderConfiguration alloc] init];
106
112
  configuration.lineWidth = _cameraViewConfiguration.finderLineWidth;
@@ -160,8 +166,18 @@
160
166
  if (_cameraViewConfiguration.flashEnabled) {
161
167
  viewController.flashLightEnabled = [_cameraViewConfiguration.flashEnabled boolValue];
162
168
  }
169
+
170
+ if (viewController.zoomConfiguration != nil) {
171
+ viewController.zoomConfiguration.zoomRange = _cameraViewConfiguration.zoomRange;
172
+ }
163
173
  }
164
174
 
175
+ - (void)applyConfigurationWithDelay:(NSTimeInterval)delayInSeconds {
176
+ dispatch_time_t delayTime = dispatch_time(DISPATCH_TIME_NOW, (int64_t)(delayInSeconds * NSEC_PER_SEC));
177
+ dispatch_after(delayTime, dispatch_get_main_queue(), ^(void){
178
+ [self applyConfiguration];
179
+ });
180
+ }
165
181
 
166
182
  - (UIEdgeInsets)populateFinderInset: (NSMutableDictionary*)config {
167
183
  UIEdgeInsets finderInset = UIEdgeInsetsZero;
@@ -145,14 +145,15 @@ RCT_EXPORT_METHOD(startBarcodeScanner:(NSDictionary*)configuration
145
145
  behaviorConfig.acceptedDocumentTypes = extractBarcodeDocumentTypesFromConfiguration(configuration);
146
146
  behaviorConfig.acceptedBarcodeTypes = extractBarcodeTypesFromConfiguration(configuration);
147
147
  behaviorConfig.engineMode = extractEngineMode(configuration);
148
+ behaviorConfig.cameraZoomRange = extractCameraZoomRange(configuration);
148
149
 
149
150
  uiConfig.orientationLockMode = [ObjectMapper extractOrientationLockMode:configuration];
150
151
 
151
152
  SBSDKUIBarcodeScannerConfiguration* barcodeScannerConfiguration = [[SBSDKUIBarcodeScannerConfiguration alloc] initWithUIConfiguration:uiConfig
152
- textConfiguration:textConfig
153
- behaviorConfiguration:behaviorConfig
154
- cameraConfiguration:cameraConfig
155
- selectionOverlayConfiguration: selectionOverlayConfig];
153
+ textConfiguration:textConfig
154
+ behaviorConfiguration:behaviorConfig
155
+ cameraConfiguration:cameraConfig
156
+ selectionOverlayConfiguration: selectionOverlayConfig];
156
157
 
157
158
  SBSDKUICameraConfiguration* cameraConfiguration = extractCameraConfiguration(configuration);
158
159
  if (cameraConfiguration) {
@@ -200,9 +201,10 @@ RCT_EXPORT_METHOD(startBatchBarcodeScanner:(NSDictionary*)configuration
200
201
  }
201
202
 
202
203
  behaviorConfig.additionalDetectionParameters = extractAdditionalParameters(configuration);
203
- behaviorConfig.acceptedDocumentTypes = extractBarcodeDocumentTypesFromConfiguration(configuration);;
204
+ behaviorConfig.acceptedDocumentTypes = extractBarcodeDocumentTypesFromConfiguration(configuration);
204
205
  behaviorConfig.acceptedBarcodeTypes = extractBarcodeTypesFromConfiguration(configuration);
205
206
  behaviorConfig.engineMode = extractEngineMode(configuration);
207
+ behaviorConfig.cameraZoomRange = extractCameraZoomRange(configuration);
206
208
 
207
209
  uiConfig.orientationLockMode = [ObjectMapper extractOrientationLockMode:configuration];
208
210
 
@@ -31,6 +31,7 @@ static inline SBSDKBarcodeType* barcodeTypeFromString(NSString* string) {
31
31
  if ([string isEqualToString:@"IATA_2_OF_5"]) return SBSDKBarcodeTypeIATA2Of5;
32
32
  if ([string isEqualToString:@"INDUSTRIAL_2_OF_5"]) return SBSDKBarcodeTypeIndustrial2Of5;
33
33
  if ([string isEqualToString:@"CODE_25"]) return SBSDKBarcodeTypeCode25;
34
+ if ([string isEqualToString:@"MICRO_QR_CODE"]) return SBSDKBarcodeTypeMicroQRCode;
34
35
  return nil;
35
36
  }
36
37
 
@@ -314,4 +315,15 @@ static inline SBSDKUIBarcodeSelectionOverlayConfiguration* extractSelectionOverl
314
315
  return overlayConfig;
315
316
  }
316
317
 
318
+ static inline SBSDKZoomRange* extractCameraZoomRange(NSDictionary* configuration) {
319
+ SBSDKZoomRange* zoomRange = nil;
320
+ NSDictionary* zoomRangeDictionary = [configuration objectForKey:@"cameraZoomRange"];
321
+ if (zoomRangeDictionary != nil) {
322
+ CGFloat minZoom = [[zoomRangeDictionary objectForKey:@"minZoom"] doubleValue];
323
+ CGFloat maxZoom = [[zoomRangeDictionary objectForKey:@"maxZoom"] doubleValue];
324
+ zoomRange = [[SBSDKZoomRange alloc] initWithMinZoom:minZoom andMaxZoom:maxZoom];
325
+ }
326
+ return zoomRange;
327
+ }
328
+
317
329
  #endif /* BarcodeMapping_h */
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.7.0-alpha.1",
4
+ "version": "3.7.0-beta.2",
5
5
  "description": "Scanbot Barcode Scanner SDK React Native Plugin for Android and iOS",
6
6
  "main": "index.js",
7
7
  "files": [
@@ -13,6 +13,7 @@ import {
13
13
  CameraModule,
14
14
  BarcodeFilter,
15
15
  CodeDensity,
16
+ CameraPreviewMode,
16
17
  } from "./enum";
17
18
  import { MSIPlesseyChecksumAlgorithm } from "./enum";
18
19
 
@@ -147,6 +148,10 @@ interface InternalBarcodeDetectionCommonParameters {
147
148
  * Whether the flash is toggled on or off.
148
149
  */
149
150
  flashEnabled?: boolean;
151
+ /**
152
+ * Disables auto-focus and locks the lens at the specified focus lock lens position. Default value is false. iOS only. For Android, minFocusDistanceLock can be used.
153
+ */
154
+ focusLockEnabled?: boolean;
150
155
  /**
151
156
  * iOS Only: Whether the flash button should be visible or not in the UI.
152
157
  */
@@ -204,6 +209,54 @@ interface InternalBarcodeDetectionCommonParameters {
204
209
  * Set `true` to enable showing the area of interest on camera preview. Enabled by default.
205
210
  */
206
211
  viewFinderEnabled?: boolean
212
+
213
+ /**
214
+ * Title of the button that opens the screen where the user can allow the usage of the camera by the app.
215
+ * */
216
+ enableCameraButtonTitle?: string;
217
+
218
+ /**
219
+ * Text that will be displayed when the app is not allowed to use the camera, prompting the user to enable the usage of the camera.
220
+ * */
221
+ enableCameraExplanationText?: string;
222
+
223
+ /**
224
+ * The position of the lens. Values can be between 0.0f (minimum focusing distance) and 1.0f (maximum focusing distance). The value will be clamped to(0.0f, 1.0f). The default value is 0.0. iOS only. For Android, minFocusDistanceLock can be used. iOS only. For Android, minFocusDistanceLock can be used.
225
+ * */
226
+ focusLockPosition?: number;
227
+ /*
228
+ * Lock focus distance withing minimum possible range
229
+ */
230
+ minFocusDistanceLock?: boolean;
231
+ /*
232
+ * Preview mode of the camera. FILL_IN or FIT_IN. Default is FILL_IN. Android only
233
+ */
234
+ cameraPreviewMode?: CameraPreviewMode;
235
+ /*
236
+ * The range of valid camera zoom factors.
237
+ For iOS it ranges between 1.0 to 12.0. Default value is (1.0; 12.0).
238
+ For Android it ranges between 0.0 to 1.0.
239
+ */
240
+ cameraZoomRange?: ZoomRange;
241
+ /*
242
+ * Sets auto close timer in seconds. 0 = disabled and it is the default value. Android only
243
+ */
244
+ autoCancelTimeout?: number;
245
+
246
+ /** Scanning delay after scanner appearance in seconds. Defaults to 0 secs. */
247
+ initialScanDelay?: number;
248
+
249
+ /** Freezes a preview after a scan for a given amount of seconds. Defaults to 0 secs. Android only. */
250
+ delayAfterScan?: number;
251
+
252
+ /** When this property is set to true, the zoom can be activated by double tapping somewhere in the receivers view. iOS only. */
253
+ doubleTapToZoomEnabled?: boolean;
254
+
255
+ /** When this property is set to true, the zoom can be activated by a pinch gesture somewhere in the receivers view. iOS only. */
256
+ pinchToZoomEnabled?: boolean;
257
+
258
+ /** Defines, if zooming in or out should be animated. iOS only. */
259
+ shouldAnimateZooming?: boolean;
207
260
  }
208
261
 
209
262
  /**
@@ -259,3 +312,12 @@ export interface BarcodeAdditionalParameters {
259
312
  */
260
313
  codeDensity?: CodeDensity;
261
314
  }
315
+
316
+ /** Defines a range for zooming */
317
+ export interface ZoomRange {
318
+ /** The minimum zoom scale. Defaults to 1.0. */
319
+ minZoom: number;
320
+
321
+ /** The maximum zoom scale. Defaults to 3.0. */
322
+ maxZoom: number;
323
+ }
package/src/enum.ts CHANGED
@@ -61,7 +61,8 @@ export type BarcodeFormat =
61
61
  "IATA_2_OF_5" |
62
62
  "INDUSTRIAL_2_OF_5" |
63
63
  "MSI_PLESSEY" |
64
- "CODE_25";
64
+ "CODE_25" |
65
+ "MICRO_QR_CODE";
65
66
 
66
67
  export type EngineMode = "LEGACY" | "NEXT_GEN";
67
68
 
@@ -72,8 +73,7 @@ export type MSIPlesseyChecksumAlgorithm =
72
73
  "Mod11NCR" |
73
74
  "Mod1010" |
74
75
  "Mod1110IBM" |
75
- "Mod1110NCR"
76
- ;
76
+ "Mod1110NCR";
77
77
 
78
78
  export type CameraModule = 'FRONT' | 'BACK';
79
79
 
@@ -87,3 +87,11 @@ export type CodeDensity = 'LOW' | 'HIGH';
87
87
  export type BarcodeOverlayFormat = 'NONE' |
88
88
  'CODE' |
89
89
  'CODE_AND_TYPE';
90
+
91
+ /** Represents camera preview modes */
92
+ export type CameraPreviewMode =
93
+ /** In this mode camera preview frames will be downscaled to the layout view size - full preview frame content will be visible, but unused edges could be appeared in the preview layout. */
94
+ | 'FIT_IN'
95
+ /** In this mode camera preview frames fill the layout view - the preview frames may contain additional content on the edges that was not visible in the preview layout. */
96
+ | 'FILL_IN';
97
+