react-native-scanbot-barcode-scanner-sdk 3.2.1-beta6 → 3.2.1-beta9

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.
Files changed (37) hide show
  1. package/android/.project +6 -0
  2. package/android/build.gradle +2 -2
  3. package/android/gradle/wrapper/gradle-wrapper.jar +0 -0
  4. package/android/gradle/wrapper/gradle-wrapper.properties +5 -0
  5. package/android/gradlew +185 -0
  6. package/android/gradlew.bat +89 -0
  7. package/android/src/main/java/com/reactlibrary/ScanbotBarcodeSdkPackage.java +17 -4
  8. package/android/src/main/java/io/scanbot/barcodesdk/plugin/reactnative/ObjectMapper.java +6 -0
  9. package/android/src/main/java/io/scanbot/barcodesdk/plugin/reactnative/ScanbotBarcodeSdkPackage.java +15 -5
  10. package/android/src/main/java/io/scanbot/barcodesdk/plugin/reactnative/components/barcodecameraview/RNScanbotBarcodeCameraComponent.java +292 -0
  11. package/android/src/main/java/io/scanbot/barcodesdk/plugin/reactnative/components/barcodecameraview/{ScanbotBarcodeCameraViewConfiguration.java → RNScanbotBarcodeCameraConfiguration.java} +54 -4
  12. package/android/src/main/java/io/scanbot/barcodesdk/plugin/reactnative/components/barcodecameraview/RNScanbotBarcodeCameraUi.java +81 -0
  13. package/android/src/main/java/io/scanbot/barcodesdk/plugin/reactnative/components/base/RNScanbotNativeComponent.java +90 -0
  14. package/android/src/main/java/io/scanbot/barcodesdk/plugin/reactnative/components/base/RNScanbotNativeComponentManager.java +133 -0
  15. package/android/src/main/java/io/scanbot/barcodesdk/plugin/reactnative/components/base/RNScanbotNativeComponentManagerFactory.java +40 -0
  16. package/android/src/main/java/io/scanbot/barcodesdk/plugin/reactnative/components/base/RNScanbotNativeComponentUi.java +131 -0
  17. package/android/src/main/java/io/scanbot/barcodesdk/plugin/reactnative/components/{EventEmitter.java → base/communication/RNScanbotEventEmitter.java} +27 -6
  18. package/android/src/main/java/io/scanbot/barcodesdk/plugin/reactnative/components/base/communication/RNScanbotEventReceiver.java +108 -0
  19. package/android/src/main/java/io/scanbot/barcodesdk/plugin/reactnative/components/{common/ScanbotComponentFrameLayout.java → base/views/RNScanbotNativeComponentFrameLayout.java} +4 -4
  20. package/android/src/main/java/io/scanbot/barcodesdk/plugin/reactnative/components/{common/ScanbotComponentRootView.java → base/views/RNScanbotNativeComponentRootView.java} +43 -48
  21. package/android/src/main/java/io/scanbot/barcodesdk/plugin/reactnative/utils/JSONUtils.java +25 -14
  22. package/android/src/main/res/layout/component_barcode_camera_view.xml +22 -5
  23. package/index.d.ts +7 -3
  24. package/ios/Components/BarcodeCameraView/RNScanbotBarcodeCameraView.h +7 -1
  25. package/ios/Components/BarcodeCameraView/RNScanbotBarcodeCameraView.m +18 -2
  26. package/ios/Components/BarcodeCameraView/RNScanbotBarcodeCameraViewManager.h +6 -0
  27. package/ios/Components/BarcodeCameraView/RNScanbotBarcodeCameraViewManager.m +41 -0
  28. package/ios/Utils/BarcodeMapping.h +3 -1
  29. package/package.json +1 -1
  30. package/src/components/barcode-camera-view/scanbot-barcode-camera-view-types.tsx +6 -0
  31. package/src/components/barcode-camera-view/scanbot-barcode-camera-view.tsx +42 -5
  32. package/android/src/main/java/io/scanbot/barcodesdk/plugin/reactnative/BitmapHelper.java +0 -28
  33. package/android/src/main/java/io/scanbot/barcodesdk/plugin/reactnative/JSONUtils.java +0 -272
  34. package/android/src/main/java/io/scanbot/barcodesdk/plugin/reactnative/LogUtils.java +0 -40
  35. package/android/src/main/java/io/scanbot/barcodesdk/plugin/reactnative/ResponseUtils.java +0 -41
  36. package/android/src/main/java/io/scanbot/barcodesdk/plugin/reactnative/components/barcodecameraview/ScanbotBarcodeCameraViewFragment.java +0 -255
  37. package/android/src/main/java/io/scanbot/barcodesdk/plugin/reactnative/components/barcodecameraview/ScanbotBarcodeCameraViewManager.java +0 -160
package/index.d.ts CHANGED
@@ -1,8 +1,9 @@
1
- import { InitializationOptions } from "react-native-scanbot-barcode-scanner-sdk/src/model";
1
+ import { InitializationOptions } from "./src/model";
2
2
  import { BarcodeScannerConfiguration, BatchBarcodeScannerConfiguration, DetectBarcodesOnImageArguments } from "./src/configuration";
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
7
 
7
8
  export {
8
9
  BarcodeScannerConfiguration,
@@ -12,12 +13,15 @@ export {
12
13
  BarcodeResult,
13
14
  BarcodeScannerResult,
14
15
  BatchBarcodeScannerResult,
16
+ ScanbotBarcodeCameraView,
17
+ ScanbotBarcodeCameraViewConfiguration,
18
+ ScanbotBarcodeCameraViewResult,
15
19
  EngineMode
16
20
  }
17
21
 
18
22
  export interface ScanbotBarcodeSdk {
19
23
  // SDK Internal
20
- initializeSdk(options: InitializationOptions): Promise<{result: string}>;
24
+ initializeSdk(options: InitializationOptions): Promise<{ result: string }>;
21
25
  getLicenseInfo(): Promise<any>;
22
26
  cleanup(): Promise<void>;
23
27
 
@@ -13,7 +13,7 @@
13
13
 
14
14
  @interface RNScanbotBarcodeCameraView: UIView<SBSDKBarcodeScannerViewControllerDelegate>
15
15
 
16
- @property UIViewController* _Nullable cameraViewController;
16
+ @property SBSDKBarcodeScannerViewController* _Nullable cameraViewController;
17
17
  @property NSMutableArray* _Nonnull barcodes;
18
18
  @property (nonatomic, copy) RCTBubblingEventBlock _Nullable onBarcodeScannerResult;
19
19
  @property (nonatomic, copy) RCTBubblingEventBlock _Nullable requestComponentReload;
@@ -23,6 +23,11 @@
23
23
  - (void) createCameraViewController;
24
24
  - (UIViewController* _Nullable) getParentViewController;
25
25
 
26
+ - (void) componentDidMount;
27
+ - (void) componentDidUpdate;
28
+ - (void) componentWillUnmount;
29
+ - (void) orientationChanged;
30
+
26
31
  @end
27
32
 
28
33
  @interface RNScanbotCameraViewConfiguration: NSObject
@@ -49,6 +54,7 @@
49
54
  @property (nonatomic, copy) NSArray<SBSDKBarcodeDocumentType *>* _Nullable acceptedDocumentFormats;
50
55
  @property (nonatomic) SBSDKBarcodeMSIPlesseyChecksumAlgorithm msiPlesseyChecksumAlgorithm;
51
56
  @property (nonatomic) SBSDKBarcodeEngineMode engineMode;
57
+ @property (nonatomic) SBSDKUIBarcodeFilter* _Nullable barcodeFilter;
52
58
 
53
59
  @end
54
60
 
@@ -35,7 +35,7 @@
35
35
 
36
36
  __weak typeof(self) weakSelf = self;
37
37
 
38
- dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 0.5 * NSEC_PER_SEC), dispatch_get_main_queue(), ^{
38
+ dispatch_async(dispatch_get_main_queue(), ^{
39
39
  [weakSelf createCameraViewController];
40
40
  });
41
41
  }
@@ -70,6 +70,11 @@
70
70
  [config removeObjectForKey:@"barcodeFormats"];
71
71
  }
72
72
 
73
+ if ([config objectForKey:@"barcodeFilter"]) {
74
+ cameraViewConfiguration.barcodeFilter = extractBarcodeFilter(config);
75
+ [config removeObjectForKey:@"barcodeFilter"];
76
+ }
77
+
73
78
  @try {
74
79
  [ObjectMapper populateInstance:cameraViewConfiguration fromDictionary:config];
75
80
  } @catch (NSException *exception) {
@@ -169,12 +174,17 @@
169
174
  return;
170
175
  }
171
176
 
177
+ if (_cameraViewConfiguration.barcodeFilter != nil) {
178
+ results = filterBarcodeResults(results, _cameraViewConfiguration.barcodeFilter);
179
+ }
180
+
172
181
  NSMutableArray* jsonBarcodes = [[NSMutableArray alloc] init];
173
182
 
174
183
  for (SBSDKBarcodeScannerResult* result in results) {
175
184
  [jsonBarcodes addObject:@{
176
185
  @"text": result.rawTextString,
177
- @"type": result.type.name
186
+ @"type": result.type.name,
187
+ @"textWithExtension": result.rawTextStringWithExtension,
178
188
  }];
179
189
  }
180
190
 
@@ -188,6 +198,12 @@
188
198
  self.onBarcodeScannerResult(outResult);
189
199
  }
190
200
 
201
+ // MARK: - React Native Lifecycle
202
+ - (void)componentDidMount {}
203
+ - (void)componentDidUpdate {}
204
+ - (void)componentWillUnmount {}
205
+ - (void)orientationChanged {}
206
+
191
207
  // MARK: - SBSDKBarcodeScannerViewControllerDelegate
192
208
 
193
209
  - (void)barcodeScannerController:(SBSDKBarcodeScannerViewController *)controller
@@ -9,8 +9,14 @@
9
9
  #define RNScanbotClassicComponents_h
10
10
 
11
11
  #import <React/RCTViewManager.h>
12
+ #import "RNScanbotBarcodeCameraView.h"
13
+
14
+ typedef void (^NativeViewBlock)(RNScanbotBarcodeCameraView* _Nonnull);
12
15
 
13
16
  @interface RNScanbotBarcodeCameraViewManager: RCTViewManager
17
+
18
+ - (void) callNativeMethodWithReactTag:(nonnull NSNumber*) reactTag andBlock:(nonnull NativeViewBlock)block;
19
+
14
20
  @end
15
21
 
16
22
  #endif /* RNScanbotClassicComponents_h */
@@ -9,6 +9,7 @@
9
9
  #import "RNScanbotBarcodeCameraViewManager.h"
10
10
  #import "RNScanbotBarcodeCameraView.h"
11
11
  #import <React/RCTViewManager.h>
12
+ #import <React/RCTUIManager.h>
12
13
 
13
14
  @import UIKit;
14
15
  @import ScanbotBarcodeScannerSDK;
@@ -27,4 +28,44 @@ RCT_EXPORT_VIEW_PROPERTY(configuration, NSDictionary*)
27
28
  return [[RNScanbotBarcodeCameraView alloc] init];
28
29
  }
29
30
 
31
+ // componentDidMount
32
+ RCT_EXPORT_METHOD(componentDidMount:(nonnull NSNumber*) reactTag) {
33
+ [self callNativeMethodWithReactTag: reactTag andBlock: ^void (RNScanbotBarcodeCameraView* nativeView) {
34
+ [nativeView componentDidMount];
35
+ }];
36
+ }
37
+
38
+ // componentDidUpdate
39
+ RCT_EXPORT_METHOD(componentDidUpdate:(nonnull NSNumber*) reactTag) {
40
+ [self callNativeMethodWithReactTag: reactTag andBlock: ^void (RNScanbotBarcodeCameraView* nativeView) {
41
+ [nativeView componentDidUpdate];
42
+ }];
43
+ }
44
+
45
+ // componentWillUnmount
46
+ RCT_EXPORT_METHOD(componentWillUnmount:(nonnull NSNumber*) reactTag) {
47
+ [self callNativeMethodWithReactTag: reactTag andBlock: ^void (RNScanbotBarcodeCameraView* nativeView) {
48
+ [nativeView componentWillUnmount];
49
+ }];
50
+ }
51
+
52
+ // orientationChanged
53
+ RCT_EXPORT_METHOD(orientationChanged:(nonnull NSNumber*) reactTag) {
54
+ [self callNativeMethodWithReactTag: reactTag andBlock: ^void (RNScanbotBarcodeCameraView* nativeView) {
55
+ [nativeView orientationChanged];
56
+ }];
57
+ }
58
+
59
+
60
+ - (void) callNativeMethodWithReactTag:(nonnull NSNumber*) reactTag andBlock:(NativeViewBlock)block {
61
+ [self.bridge.uiManager addUIBlock:^(RCTUIManager *uiManager, NSDictionary<NSNumber *,UIView *> *viewRegistry) {
62
+ RNScanbotBarcodeCameraView* view = (RNScanbotBarcodeCameraView*) viewRegistry[reactTag];
63
+ if (!view || ![view isKindOfClass:[RNScanbotBarcodeCameraView class]]) {
64
+ RCTLogError(@"Cannot find native view with tag #%@", reactTag);
65
+ return;
66
+ }
67
+ block(view);
68
+ }];
69
+ }
70
+
30
71
  @end
@@ -128,7 +128,9 @@ static inline NSArray* filterBarcodeResults(NSArray<SBSDKBarcodeScannerResult *>
128
128
  }
129
129
 
130
130
  for (SBSDKBarcodeScannerResult* result in barcodeResults) {
131
- if (![filter acceptsBarcode:result]) { continue; }
131
+ if (![filter acceptsBarcode:result]) {
132
+ continue;
133
+ }
132
134
  [outResults addObject:result];
133
135
  }
134
136
 
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-beta6",
4
+ "version": "3.2.1-beta9",
5
5
  "description": "Scanbot Barcode Scanner SDK React Native Plugin for Android and iOS",
6
6
  "main": "index.js",
7
7
  "files": [
@@ -1,6 +1,7 @@
1
1
  import { StyleProp, ViewStyle } from 'react-native';
2
2
  import {
3
3
  BarcodeDocumentFormat,
4
+ BarcodeFilter,
4
5
  BarcodeFormat,
5
6
  EngineMode,
6
7
  MSIPlesseyChecksumAlgorithm,
@@ -16,6 +17,7 @@ export interface ScanbotBarcodeCameraViewProperties {
16
17
 
17
18
  export interface ScanbotBarcodeCameraViewBarcode {
18
19
  text: string;
20
+ textWithExtension: string;
19
21
  type: string;
20
22
  }
21
23
 
@@ -118,4 +120,8 @@ export interface ScanbotBarcodeCameraViewConfiguration {
118
120
  * The default is `false`
119
121
  */
120
122
  stripCheckDigits?: boolean;
123
+ /**
124
+ * Use a filter to determine which type of barcode can be detected; see `BarcodeFilter`
125
+ */
126
+ barcodeFilter?: BarcodeFilter;
121
127
  }
@@ -1,5 +1,5 @@
1
1
  import React from 'react';
2
- import {Platform} from 'react-native';
2
+ import {findNodeHandle, NativeMethods, Platform, UIManager} from 'react-native';
3
3
  import {Dimensions} from 'react-native';
4
4
  import {ScanbotBarcodeCameraViewProperties} from './scanbot-barcode-camera-view-types';
5
5
  import ScanbotNativeBarcodeCameraView from './scanbot-native-barcode-camera-view';
@@ -21,6 +21,10 @@ interface ScanbotBarcodeCameraViewState {
21
21
 
22
22
  type Properties = ScanbotBarcodeCameraViewProperties;
23
23
  export class ScanbotBarcodeCameraView extends React.Component<Properties, {}> {
24
+
25
+ // Camera View Reference
26
+ cameraViewReference: React.RefObject<React.Component<ScanbotBarcodeCameraViewProperties > & Readonly<NativeMethods>>
27
+
24
28
  // String length of auto-generated component key
25
29
  static UNIQUE_VIEW_KEY_LENGTH = 6;
26
30
 
@@ -58,6 +62,11 @@ export class ScanbotBarcodeCameraView extends React.Component<Properties, {}> {
58
62
  orientation: Device.isPortrait() ? 'portrait' : 'landscape',
59
63
  };
60
64
 
65
+ constructor(props: ScanbotBarcodeCameraViewProperties) {
66
+ super(props);
67
+ this.cameraViewReference = React.createRef();
68
+ }
69
+
61
70
  // Returns a random string ID of the given length
62
71
  static getRandomId(
63
72
  length: number = ScanbotBarcodeCameraView.UNIQUE_VIEW_KEY_LENGTH,
@@ -74,7 +83,8 @@ export class ScanbotBarcodeCameraView extends React.Component<Properties, {}> {
74
83
 
75
84
  // Event Listener for orientation changes
76
85
  orientationChangeHandler = () => {
77
- this.isDirty = true;
86
+ this.sendCommandToCameraView("orientationChanged");
87
+ this._invalidate();
78
88
  this.setState({
79
89
  orientation: Device.isPortrait() ? 'portrait' : 'landscape',
80
90
  });
@@ -90,6 +100,7 @@ export class ScanbotBarcodeCameraView extends React.Component<Properties, {}> {
90
100
  };
91
101
 
92
102
  render() {
103
+
93
104
  this.evaluateComponentState();
94
105
 
95
106
  const style = this.preprocessStyle();
@@ -100,7 +111,8 @@ export class ScanbotBarcodeCameraView extends React.Component<Properties, {}> {
100
111
  {...props}
101
112
  style={style}
102
113
  key={this.cameraKey}
103
- requestComponentReload={this._invalidate}
114
+ ref={this.cameraViewReference}
115
+
104
116
  onBarcodeScannerResult={this._onBarcodeScannerResult}
105
117
  />
106
118
  );
@@ -109,11 +121,17 @@ export class ScanbotBarcodeCameraView extends React.Component<Properties, {}> {
109
121
  componentDidMount() {
110
122
  Dimensions.addEventListener('change', this.orientationChangeHandler);
111
123
  this.previousChildrenIds = this.childrenIds;
124
+ this.sendCommandToCameraView("componentDidMount");
125
+ }
126
+
127
+ componentDidUpdate() {
128
+ this.sendCommandToCameraView("componentDidUpdate");
112
129
  }
113
130
 
114
131
  componentWillUnmount() {
115
- Dimensions.removeEventListener('change', this.orientationChangeHandler);
132
+ Dimensions.removeEventListener('change', this.orientationChangeHandler);
116
133
  this.previousChildrenIds = [];
134
+ this.sendCommandToCameraView("componentWillUnmount");
117
135
  }
118
136
 
119
137
  evaluateComponentState = () => {
@@ -159,5 +177,24 @@ export class ScanbotBarcodeCameraView extends React.Component<Properties, {}> {
159
177
  // Invalidates the component so that it gets recreated on the next render
160
178
  _invalidate = () => {
161
179
  this.isDirty = true;
180
+ this.cameraViewReference = React.createRef();
162
181
  };
163
- }
182
+
183
+ sendCommandToCameraView = (command: string, args: any = []) => {
184
+ const viewId = findNodeHandle(this.cameraViewReference.current);
185
+ if (!viewId) {
186
+ return;
187
+ }
188
+ this.sendCommandToViewId(viewId, command, args);
189
+ }
190
+
191
+ sendCommandToViewId = (viewId: number, command: string, args: any = []) => {
192
+ let commandId: number
193
+ if (Platform.OS == 'android') {
194
+ commandId = (UIManager as any).ScanbotBarcodeCameraView.Commands[command].toString();
195
+ } else {
196
+ commandId = UIManager.getViewManagerConfig('ScanbotBarcodeCameraView').Commands[command];
197
+ }
198
+ UIManager.dispatchViewManagerCommand(viewId, commandId, args);
199
+ }
200
+ }
@@ -1,28 +0,0 @@
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;
7
-
8
- import android.content.Context;
9
- import android.graphics.Bitmap;
10
- import android.net.Uri;
11
-
12
- import java.io.File;
13
- import java.io.FileOutputStream;
14
- import java.io.IOException;
15
-
16
- public class BitmapHelper {
17
- public static File storeImageAsFile(final Bitmap image, final int quality, final Context context) throws IOException {
18
- final File pictureFile = StorageUtils.generateRandomPluginStorageFile("jpg", context);
19
- final FileOutputStream fos = new FileOutputStream(pictureFile);
20
- image.compress(Bitmap.CompressFormat.JPEG, quality, fos);
21
- fos.close();
22
- return pictureFile;
23
- }
24
-
25
- public static Uri storeImage(final Bitmap image, final int quality, final Context context) throws IOException {
26
- return Uri.fromFile(storeImageAsFile(image, quality, context));
27
- }
28
- }
@@ -1,272 +0,0 @@
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;
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
- import org.json.JSONArray;
23
-
24
- import java.util.ArrayList;
25
- import java.util.EnumSet;
26
- import java.util.List;
27
- import java.util.Objects;
28
-
29
- import io.scanbot.sdk.barcode.entity.BarcodeDocumentFormat;
30
- import io.scanbot.sdk.barcode.entity.BarcodeFormat;
31
- import io.scanbot.sdk.barcode.entity.BarcodeScannerAdditionalConfig;
32
- import io.scanbot.sdk.barcode.entity.EngineMode;
33
- import io.scanbot.sdk.barcode.entity.MSIPlesseyChecksumAlgorithm;
34
- import io.scanbot.sdk.ui.view.barcode.configuration.BarcodeFilter;
35
- import io.scanbot.sdk.ui.view.barcode.configuration.BarcodeScannerAdditionalConfiguration;
36
- import io.scanbot.sdk.ui.view.base.configuration.CameraOrientationMode;
37
-
38
- public final class JSONUtils {
39
-
40
- private JSONUtils() {}
41
-
42
- public static class WritableMapBuilder {
43
-
44
- private final WritableNativeMap _writableMap = new WritableNativeMap();
45
-
46
- public WritableMapBuilder putBoolean(@NonNull String key, boolean value) {
47
- _writableMap.putBoolean(key, value);
48
- return this;
49
- }
50
-
51
- public WritableMapBuilder putDouble(@NonNull String key, double value) {
52
- _writableMap.putDouble(key, value);
53
- return this;
54
- }
55
-
56
- public WritableMapBuilder putInt(@NonNull String key, int value) {
57
- _writableMap.putInt(key, value);
58
- return this;
59
- }
60
-
61
- public WritableMapBuilder putNull(@NonNull String key) {
62
- _writableMap.putNull(key);
63
- return this;
64
- }
65
-
66
- public WritableMapBuilder putString(@NonNull String key, @Nullable String value) {
67
- _writableMap.putString(key, value);
68
- return this;
69
- }
70
-
71
- public WritableMapBuilder putMap(@NonNull String key, @Nullable ReadableMap value) {
72
- _writableMap.putMap(key, value);
73
- return this;
74
- }
75
-
76
- public WritableMapBuilder putArray(@NonNull String key, @Nullable ReadableArray value) {
77
- _writableMap.putArray(key, value);
78
- return this;
79
- }
80
-
81
- public WritableMap build() {
82
- return this._writableMap;
83
- }
84
- }
85
-
86
- public static WritableArray sdkPolygonToWritableArray(final List<PointF> polygon) {
87
- WritableArray points = Arguments.createArray();
88
- if (polygon != null) {
89
- for (final PointF p: polygon) {
90
- WritableMap pointRecord = Arguments.createMap();
91
- pointRecord.putDouble("x", p.x);
92
- pointRecord.putDouble("y", p.y);
93
- points.pushMap(pointRecord);
94
- }
95
- }
96
- return points;
97
- }
98
-
99
- public static ArrayList<BarcodeFormat> extractBarcodeFormats(@NotNull ReadableMap configuration) {
100
- ArrayList<BarcodeFormat> nativeBarcodeFormats = new ArrayList<>();
101
- if (configuration.hasKey("barcodeFormats")) {
102
- ReadableArray barcodeFormats = configuration.getArray("barcodeFormats");
103
- if (barcodeFormats != null) {
104
- for (int i = 0; i < barcodeFormats.size(); ++i) {
105
- nativeBarcodeFormats.add(BarcodeFormat.valueOf(barcodeFormats.getString(i)));
106
- }
107
- }
108
- }
109
- return nativeBarcodeFormats;
110
- }
111
-
112
- public static ArrayList<BarcodeDocumentFormat> extractBarcodeDocumentFormats(final ReadableMap configuration) {
113
- ArrayList<BarcodeDocumentFormat> nativeBarcodeDocumentFormats = new ArrayList<>();
114
- ArrayList<String> barcodeDocumentFormats = JSONUtils.getStringArrayListFromMap(configuration, "acceptedDocumentFormats");
115
-
116
- for (String format : barcodeDocumentFormats) {
117
- nativeBarcodeDocumentFormats.add(BarcodeDocumentFormat.valueOf(format));
118
- }
119
-
120
- return nativeBarcodeDocumentFormats;
121
- }
122
-
123
- public static @Nullable CameraOrientationMode extractCameraOrientationMode(final ReadableMap configuration) {
124
- if (configuration.hasKey("allowedInterfaceOrientations")) {
125
- String orientation = configuration.getString("allowedInterfaceOrientations");
126
- if (orientation == null) {
127
- orientation = "NONE";
128
- }
129
- switch (orientation) {
130
- case "NONE":
131
- break;
132
- case "PORTRAIT":
133
- case "PORTRAIT_UPSIDE_DOWN":
134
- return CameraOrientationMode.PORTRAIT;
135
- case "LANDSCAPE_LEFT":
136
- case "LANDSCAPE_RIGHT":
137
- case "LANDSCAPE":
138
- return CameraOrientationMode.LANDSCAPE;
139
- default:
140
- return null;
141
- }
142
- }
143
-
144
- return null;
145
- }
146
-
147
- public static @Nullable BarcodeScannerAdditionalConfig extractBarcodeScannerAdditionalConfig(final ReadableMap configuration) {
148
- boolean changed = false;
149
-
150
- int minimumTextLength = BarcodeScannerAdditionalConfig.DEFAULT_MIN_TEXT_LENGTH;
151
- if (configuration.hasKey("minimumTextLength")) {
152
- minimumTextLength = configuration.getInt("minimumTextLength");
153
- changed = true;
154
- }
155
-
156
- int maximumTextLength = BarcodeScannerAdditionalConfig.DEFAULT_MAX_TEXT_LENGTH;
157
- if (configuration.hasKey("maximumTextLength")) {
158
- maximumTextLength = configuration.getInt("maximumTextLength");
159
- changed = true;
160
- }
161
-
162
- int minimum1DQuietZoneSize = BarcodeScannerAdditionalConfig.DEFAULT_MIN_1D_QUIET_ZONE_SIZE;
163
- if (configuration.hasKey("minimum1DBarcodesQuietZone")) {
164
- minimum1DQuietZoneSize = configuration.getInt("minimum1DBarcodesQuietZone");
165
- changed = true;
166
- }
167
-
168
- boolean gs1DecodingEnabled = BarcodeScannerAdditionalConfig.DEFAULT_GS1_DECODING_ENABLED;
169
- if (configuration.hasKey("gs1DecodingEnabled")) {
170
- gs1DecodingEnabled = configuration.getBoolean("gs1DecodingEnabled");
171
- changed = true;
172
- }
173
-
174
- EnumSet<MSIPlesseyChecksumAlgorithm> msiPlesseyChecksumAlgorithms =
175
- BarcodeScannerAdditionalConfig.Companion.getDEFAULT_MSI_PLESSEY_CHECKSUM_ALGORITHMS();
176
- if (configuration.hasKey("msiPlesseyChecksumAlgorithm")) {
177
- msiPlesseyChecksumAlgorithms.clear();
178
- String algorithm = configuration.getString("msiPlesseyChecksumAlgorithm");
179
- msiPlesseyChecksumAlgorithms.add(MSIPlesseyChecksumAlgorithm.valueOf(algorithm));
180
- changed = true;
181
- }
182
-
183
- boolean stripCheckDigits = BarcodeScannerAdditionalConfig.DEFAULT_STRIP_CHECK_DIGITS;
184
- if (configuration.hasKey("stripCheckDigits")) {
185
- stripCheckDigits = configuration.getBoolean("stripCheckDigits");
186
- changed = true;
187
- }
188
-
189
- boolean lowPowerMode = BarcodeScannerAdditionalConfig.DEFAULT_LOW_POWER_MODE;
190
- if (configuration.hasKey("lowPowerMode")) {
191
- lowPowerMode = configuration.getBoolean("lowPowerMode");
192
- changed = true;
193
- }
194
-
195
- return changed ? new BarcodeScannerAdditionalConfig(
196
- minimumTextLength,
197
- maximumTextLength,
198
- minimum1DQuietZoneSize,
199
- gs1DecodingEnabled,
200
- msiPlesseyChecksumAlgorithms,
201
- stripCheckDigits,
202
- lowPowerMode
203
- ) : null;
204
- }
205
-
206
- public static @Nullable BarcodeScannerAdditionalConfiguration extractBarcodeScannerAdditionalConfiguration(final ReadableMap configuration) {
207
- final BarcodeScannerAdditionalConfig config = extractBarcodeScannerAdditionalConfig(configuration);
208
- return config != null ? new BarcodeScannerAdditionalConfiguration(
209
- config.getMinimumTextLength(),
210
- config.getMaximumTextLength(),
211
- config.getMinimum1DQuietZoneSize(),
212
- config.getGs1DecodingEnabled(),
213
- config.getMsiPlesseyChecksumAlgorithms(),
214
- config.getStripCheckDigits(),
215
- config.getLowPowerMode()
216
- ) : null;
217
- }
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
-
238
- public static ArrayList<String> getStringArrayListFromMap(final ReadableMap configuration, final String key) {
239
- ArrayList<String> out = new ArrayList<>();
240
- if(!configuration.hasKey(key)) {
241
- return out;
242
- }
243
- ReadableArray nullable = configuration.getArray(key);
244
- if (nullable != null) {
245
- ArrayList<Object> objects = nullable.toArrayList();
246
- for (Object obj : objects) {
247
- try { out.add(Objects.toString(obj)); }
248
- catch (ClassCastException ignored) {}
249
- }
250
- }
251
- return out;
252
- }
253
-
254
- public static EngineMode extractEngineMode(ReadableMap configuration) {
255
- if (!configuration.hasKey("engineMode")) {
256
- return EngineMode.NextGen;
257
- }
258
-
259
- String mode = configuration.getString("engineMode");
260
- if ("LEGACY".equals(mode)) {
261
- return EngineMode.Legacy;
262
- }
263
- return EngineMode.NextGen;
264
- }
265
-
266
- public static boolean getBoolOrFalse(final ReadableMap map, final String key) {
267
- if (!map.hasKey(key)) {
268
- return false;
269
- }
270
- return map.getBoolean(key);
271
- }
272
- }
@@ -1,40 +0,0 @@
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;
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
- }