react-native-scanbot-barcode-scanner-sdk 4.0.4 → 4.2.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.
Files changed (83) hide show
  1. package/LICENSE +1 -1
  2. package/Libraries.txt +85 -419
  3. package/RNScanbotBarcodeSDK.podspec +3 -3
  4. package/android/build.gradle +12 -13
  5. package/android/src/main/AndroidManifest.xml +2 -2
  6. package/android/src/main/java/io/scanbot/barcodesdk/plugin/reactnative/ScanbotBarcodeSdkModule.kt +179 -0
  7. package/android/src/main/java/io/scanbot/barcodesdk/plugin/reactnative/ScanbotBarcodeSdkPackage.kt +23 -0
  8. package/android/src/main/java/io/scanbot/barcodesdk/plugin/reactnative/ScanbotBarcodeSdkPluginResultDelegate.kt +23 -0
  9. package/android/src/main/java/io/scanbot/barcodesdk/plugin/reactnative/components/barcodecameraview/ScanbotBarcodeCameraView.java +79 -70
  10. package/android/src/main/java/io/scanbot/barcodesdk/plugin/reactnative/extensions/JSONObject.kt +90 -0
  11. package/android/src/main/java/io/scanbot/barcodesdk/plugin/reactnative/extensions/ReadableMap.kt +53 -0
  12. package/android/src/main/java/io/scanbot/barcodesdk/plugin/reactnative/utils/JSONUtils.kt +24 -0
  13. package/android/src/main/java/io/scanbot/barcodesdk/plugin/reactnative/utils/ScanbotViewUtils.java +4 -0
  14. package/android/src/new-architecture/io/scanbot/barcodesdk/plugin/reactnative/components/barcodecameraview/ScanbotBarcodeCameraViewManager.java +0 -2
  15. package/index.d.ts +24 -29
  16. package/index.js +9 -2
  17. package/ios/Components/BarcodeCameraView/NewArchitecture/RTNScanbotBarcodeCameraView.h +0 -1
  18. package/ios/Components/BarcodeCameraView/NewArchitecture/RTNScanbotBarcodeCameraView.mm +120 -148
  19. package/ios/Components/BarcodeCameraView/OldArchitecture/RNScanbotBarcodeCameraView.h +0 -31
  20. package/ios/Components/BarcodeCameraView/OldArchitecture/RNScanbotBarcodeCameraView.mm +45 -158
  21. package/ios/Components/BarcodeCameraView/OldArchitecture/RNScanbotBarcodeCameraViewManager.mm +0 -1
  22. package/ios/ScanbotBarcodeSdk.h +1 -12
  23. package/ios/ScanbotBarcodeSdk.m +64 -489
  24. package/ios/ScanbotBarcodeSdkPluginResultDelegate.h +18 -0
  25. package/ios/ScanbotBarcodeSdkPluginResultDelegate.m +36 -0
  26. package/js/{RTNScanbotBarcodeCameraViewNativeComponent.tsx → RTNScanbotBarcodeCameraViewNativeComponent.ts} +7 -35
  27. package/package.json +5 -2
  28. package/src/components/barcode-camera-view/{scanbot-barcode-camera-view-types.tsx → scanbot-barcode-camera-view-types.ts} +57 -16
  29. package/src/components/barcode-camera-view/scanbot-barcode-camera-view.tsx +14 -4
  30. package/src/configurations.ts +374 -0
  31. package/src/customConfigurations.ts +97 -0
  32. package/src/customResults.ts +6 -0
  33. package/src/customTypes.ts +10 -0
  34. package/src/results.ts +38 -0
  35. package/src/types.ts +1355 -0
  36. package/android/.project +0 -34
  37. package/android/.settings/org.eclipse.buildship.core.prefs +0 -13
  38. package/android/gradle/wrapper/gradle-wrapper.jar +0 -0
  39. package/android/gradle/wrapper/gradle-wrapper.properties +0 -5
  40. package/android/gradlew +0 -185
  41. package/android/gradlew.bat +0 -89
  42. package/android/src/main/java/com/reactlibrary/ScanbotBarcodeSdkModule.java +0 -19
  43. package/android/src/main/java/com/reactlibrary/ScanbotBarcodeSdkPackage.java +0 -38
  44. package/android/src/main/java/io/scanbot/barcodesdk/plugin/reactnative/ObjectMapper.java +0 -166
  45. package/android/src/main/java/io/scanbot/barcodesdk/plugin/reactnative/ScanbotBarcodeSdkConfiguration.java +0 -75
  46. package/android/src/main/java/io/scanbot/barcodesdk/plugin/reactnative/ScanbotBarcodeSdkModule.java +0 -460
  47. package/android/src/main/java/io/scanbot/barcodesdk/plugin/reactnative/ScanbotBarcodeSdkPackage.java +0 -36
  48. package/android/src/main/java/io/scanbot/barcodesdk/plugin/reactnative/StorageUtils.java +0 -108
  49. package/android/src/main/java/io/scanbot/barcodesdk/plugin/reactnative/barcode/ScanbotBarcodeDetectorAdditionalConfigBuilder.java +0 -37
  50. package/android/src/main/java/io/scanbot/barcodesdk/plugin/reactnative/barcode/ScanbotBarcodeDetectorConfigBuilder.java +0 -45
  51. package/android/src/main/java/io/scanbot/barcodesdk/plugin/reactnative/components/barcodecameraview/ScanbotBarcodeCameraViewConfiguration.java +0 -195
  52. package/android/src/main/java/io/scanbot/barcodesdk/plugin/reactnative/filters/ReactBarcodeExtensionsFilter.java +0 -59
  53. package/android/src/main/java/io/scanbot/barcodesdk/plugin/reactnative/utils/JSONUtils.java +0 -440
  54. package/android/src/main/java/io/scanbot/barcodesdk/plugin/reactnative/utils/LogUtils.java +0 -43
  55. package/android/src/main/java/io/scanbot/barcodesdk/plugin/reactnative/utils/ResponseUtils.java +0 -33
  56. package/android/src/main/res/drawable/ic_baseline_arrow_back_24.xml +0 -10
  57. package/android/src/main/res/values/attrs.xml +0 -5
  58. package/ios/Categories/SBSDKPolygon+JSON.h +0 -16
  59. package/ios/Categories/SBSDKPolygon+JSON.m +0 -21
  60. package/ios/Categories/UIColor+JSON.h +0 -14
  61. package/ios/Categories/UIColor+JSON.m +0 -61
  62. package/ios/ScanbotBarcodeSDKConfiguration.h +0 -15
  63. package/ios/ScanbotBarcodeSDKConfiguration.m +0 -13
  64. package/ios/ScanbotBarcodeSdk.xcodeproj/project.pbxproj +0 -271
  65. package/ios/ScanbotBarcodeSdk.xcworkspace/contents.xcworkspacedata +0 -7
  66. package/ios/ScanbotBarcodeSdk.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist +0 -8
  67. package/ios/SharedConfiguration.h +0 -18
  68. package/ios/SharedConfiguration.m +0 -20
  69. package/ios/Utils/BarcodeMapping.h +0 -336
  70. package/ios/Utils/HashUtils.h +0 -46
  71. package/ios/Utils/JSONMappings.h +0 -25
  72. package/ios/Utils/LoggingUtils.h +0 -23
  73. package/ios/Utils/ObjectMapper.h +0 -26
  74. package/ios/Utils/ObjectMapper.m +0 -143
  75. package/ios/Utils/ReactBarcodeExtensionsFilter.h +0 -22
  76. package/ios/Utils/ReactBarcodeExtensionsFilter.m +0 -55
  77. package/ios/Utils/ScanbotStorageUtils.h +0 -25
  78. package/ios/Utils/ScanbotStorageUtils.m +0 -111
  79. package/src/configuration.ts +0 -328
  80. package/src/enum.ts +0 -106
  81. package/src/model.ts +0 -104
  82. package/src/result.ts +0 -45
  83. /package/src/components/barcode-camera-view/{scanbot-native-barcode-camera-view.tsx → scanbot-native-barcode-camera-view.ts} +0 -0
@@ -0,0 +1,53 @@
1
+ package io.scanbot.barcodesdk.plugin.reactnative.extensions
2
+
3
+ import com.facebook.react.bridge.ReadableArray
4
+ import com.facebook.react.bridge.ReadableMap
5
+ import com.facebook.react.bridge.ReadableType
6
+ import org.json.JSONArray
7
+ import org.json.JSONException
8
+ import org.json.JSONObject
9
+
10
+
11
+ @Throws(JSONException::class)
12
+ fun ReadableMap.toJSON(): JSONObject {
13
+ val jsonResult = JSONObject()
14
+
15
+ val iterator = this.keySetIterator()
16
+
17
+ while (iterator.hasNextKey()) {
18
+ val key = iterator.nextKey()
19
+
20
+ when (this.getType(key)) {
21
+ ReadableType.Boolean -> jsonResult.put(key, this.getBoolean(key))
22
+ ReadableType.Number -> jsonResult.put(key, this.getDouble(key))
23
+ ReadableType.String -> jsonResult.put(key, this.getString(key))
24
+ ReadableType.Map -> jsonResult.put(key, this.getMap(key)?.toJSON())
25
+ ReadableType.Array -> jsonResult.put(key, this.getArray(key)?.toJSONArray())
26
+ ReadableType.Null -> {
27
+ // NO-OP
28
+ }
29
+ }
30
+ }
31
+
32
+ return jsonResult
33
+ }
34
+
35
+ @Throws(JSONException::class)
36
+ fun ReadableArray.toJSONArray(): JSONArray {
37
+ val jsonResult = JSONArray()
38
+
39
+ for (i in 0 until this.size()) {
40
+ when (this.getType(i)) {
41
+ ReadableType.Boolean -> jsonResult.put(this.getBoolean(i))
42
+ ReadableType.Number -> jsonResult.put(this.getDouble(i))
43
+ ReadableType.String -> jsonResult.put(this.getString(i))
44
+ ReadableType.Map -> jsonResult.put(this.getMap(i).toJSON())
45
+ ReadableType.Array -> jsonResult.put(this.getArray(i).toJSONArray())
46
+ ReadableType.Null -> {
47
+ // NO-OP
48
+ }
49
+ }
50
+ }
51
+
52
+ return jsonResult
53
+ }
@@ -0,0 +1,24 @@
1
+ /*
2
+ Scanbot Barcode Scanner SDK React Native Plugin
3
+ Copyright (c) 2024 Scanbot SDK GmbH. All rights reserved.
4
+ https://scanbot.io/sdk
5
+ */
6
+ package io.scanbot.barcodesdk.plugin.reactnative.utils
7
+
8
+ import com.facebook.react.bridge.ReadableMap
9
+ import io.scanbot.barcodesdk.plugin.reactnative.extensions.toJSON
10
+ import io.scanbot.barcodesdk.plugin.reactnative.extensions.toWritableMap
11
+ import org.json.JSONObject
12
+
13
+ object JSONUtils {
14
+
15
+ @JvmStatic
16
+ fun jsonToWritableMap(jsonObject: JSONObject): ReadableMap {
17
+ return jsonObject.toWritableMap()
18
+ }
19
+
20
+ @JvmStatic
21
+ fun readableMapToJson(readableMap: ReadableMap): JSONObject {
22
+ return readableMap.toJSON()
23
+ }
24
+ }
@@ -36,4 +36,8 @@ public class ScanbotViewUtils {
36
36
  public static int convertDpToPx(Resources resources, int dp) {
37
37
  return (int) Math.floor(dp * resources.getDisplayMetrics().density);
38
38
  }
39
+
40
+ public static int convertDpToPx(Resources resources, float dp) {
41
+ return (int) Math.floor(dp * resources.getDisplayMetrics().density);
42
+ }
39
43
  }
@@ -1,7 +1,5 @@
1
1
  package io.scanbot.barcodesdk.plugin.reactnative.components.barcodecameraview;
2
2
 
3
- import android.util.Log;
4
-
5
3
  import androidx.annotation.NonNull;
6
4
  import androidx.annotation.Nullable;
7
5
 
package/index.d.ts CHANGED
@@ -1,42 +1,30 @@
1
- import { InitializationOptions } from "./src/model";
2
- import { BarcodeScannerConfiguration, BatchBarcodeScannerConfiguration, DetectBarcodesOnImageArguments } from "./src/configuration";
3
- import { BarcodeDocumentFormat, BarcodeFormat, EngineMode } from "./src/enum";
4
- import { BarcodeResult, BarcodeScannerResult, BatchBarcodeScannerResult, GetLicenseInfoResult } from "./src/result";
5
- import { ScanbotBarcodeCameraView } from "./src/components/barcode-camera-view/scanbot-barcode-camera-view";
6
- import { ScanbotBarcodeCameraViewConfiguration} from "./src/components/barcode-camera-view/scanbot-barcode-camera-view-types";
7
-
8
- export {
9
- BarcodeScannerConfiguration,
10
- BatchBarcodeScannerConfiguration,
11
- BarcodeDocumentFormat,
12
- BarcodeFormat,
13
- BarcodeResult,
14
- BarcodeScannerResult,
15
- BatchBarcodeScannerResult,
16
- ScanbotBarcodeCameraView,
17
- ScanbotBarcodeCameraViewConfiguration,
18
- EngineMode,
19
- GetLicenseInfoResult
20
- }
1
+ import { BarcodeScannerConfiguration, BatchBarcodeScannerConfiguration, ScanbotBarcodeSdkConfiguration } from "./src/configurations";
2
+ import { DetectBarcodesOnImageArguments, ExtractImagesFromPdfArguments } from "./src/customConfigurations";
3
+ import { ResultWrapper } from "./src/customResults";
4
+ import { BarcodeScannerResult, BatchBarcodeScannerResult, GetLicenseInfoResult } from "./src/results";
21
5
 
22
6
  export interface ScanbotBarcodeSdk {
23
7
  // SDK Internal
24
- initializeSdk(options: InitializationOptions): Promise<{ result: string }>;
25
- getLicenseInfo(): Promise<GetLicenseInfoResult>;
8
+ initializeSdk(config: ScanbotBarcodeSdkConfiguration): Promise<ResultWrapper<string>>;
9
+ getLicenseInfo(): Promise<ResultWrapper<GetLicenseInfoResult>>;
26
10
 
27
- cleanup(): Promise<void>;
11
+ cleanup(): Promise<ResultWrapper<string>>;
28
12
 
29
13
  // RTU-UI Barcode Scanning
30
- startBarcodeScanner(configuration: BarcodeScannerConfiguration): Promise<BarcodeScannerResult>;
31
- closeBarcodeScanner(): Promise<void>;
14
+ startBarcodeScanner(config: BarcodeScannerConfiguration): Promise<ResultWrapper<BarcodeScannerResult>>;
15
+ closeBarcodeScanner(): Promise<ResultWrapper<undefined>>;
32
16
 
33
- startBatchBarcodeScanner(configuration: BatchBarcodeScannerConfiguration): Promise<BatchBarcodeScannerResult>;
34
- closeBatchBarcodeScanner(): Promise<void>;
17
+ startBatchBarcodeScanner(config: BatchBarcodeScannerConfiguration): Promise<ResultWrapper<BatchBarcodeScannerResult>>;
18
+ closeBatchBarcodeScanner(): Promise<ResultWrapper<undefined>>;
35
19
 
36
20
  // Other Barcode Scanning functionalities
37
21
  detectBarcodesOnImage(
38
22
  args: DetectBarcodesOnImageArguments
39
- ): Promise<BarcodeResult>;
23
+ ): Promise<ResultWrapper<BarcodeScannerResult>>;
24
+
25
+ extractImagesFromPDF(
26
+ args: ExtractImagesFromPdfArguments
27
+ ): Promise<ResultWrapper<string[]>>;
40
28
  }
41
29
 
42
30
  declare var ScanbotBarcodeSDK: ScanbotBarcodeSdk;
@@ -44,4 +32,11 @@ declare var ScanbotBarcodeSDK: ScanbotBarcodeSdk;
44
32
  export default ScanbotBarcodeSDK;
45
33
 
46
34
  export * from './src/components/barcode-camera-view/scanbot-barcode-camera-view';
47
- export * from './src/components/barcode-camera-view/scanbot-barcode-camera-view-types';
35
+ export * from './src/components/barcode-camera-view/scanbot-barcode-camera-view-types';
36
+
37
+ export * from './src/types'
38
+ export * from './src/customTypes'
39
+ export * from './src/results'
40
+ export * from './src/customResults'
41
+ export * from './src/configurations'
42
+ export * from './src/customConfigurations'
package/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  /*
2
2
  Scanbot Barcode Scanner SDK React Native Plugin
3
- Copyright (c) 2023 Scanbot SDK GmbH. All rights reserved.
3
+ Copyright (c) 2024 Scanbot SDK GmbH. All rights reserved.
4
4
  https://scanbot.io/sdk
5
5
  */
6
6
  import { NativeModules } from 'react-native';
@@ -10,4 +10,11 @@ const { ScanbotBarcodeSdk } = NativeModules;
10
10
  export default ScanbotBarcodeSdk;
11
11
 
12
12
  export * from './src/components/barcode-camera-view/scanbot-barcode-camera-view';
13
- export * from './src/components/barcode-camera-view/scanbot-barcode-camera-view-types';
13
+ export * from './src/components/barcode-camera-view/scanbot-barcode-camera-view-types';
14
+
15
+ export * from './src/types'
16
+ export * from './src/customTypes'
17
+ export * from './src/results'
18
+ export * from './src/customResults'
19
+ export * from './src/configurations'
20
+ export * from './src/customConfigurations'
@@ -22,7 +22,6 @@ NS_ASSUME_NONNULL_BEGIN
22
22
  @interface RTNScanbotBarcodeCameraView: RCTViewComponentView<SBSDKBarcodeScannerViewControllerDelegate>
23
23
 
24
24
  @property SBSDKBarcodeScannerViewController* _Nullable cameraViewController;
25
- @property NSMutableArray* _Nonnull barcodes;
26
25
 
27
26
  // TODO: Check if required
28
27
  @property (nonatomic, copy) RCTBubblingEventBlock _Nullable requestComponentReload;
@@ -14,11 +14,10 @@
14
14
  #import <react/renderer/components/RTNScanbotBarcodeCameraViewSpecs/RCTComponentViewHelpers.h>
15
15
 
16
16
  #import "RTNScanbotBarcodeCameraView.h"
17
- #import "ObjectMapper.h"
18
- #import "BarcodeMapping.h"
19
17
  #import "RCTFabricComponentsPlugins.h"
20
18
 
21
19
  #import <ScanbotBarcodeScannerSDK/ScanbotBarcodeScannerSDK.h>
20
+ #import <ScanbotBarcodeSDKWrapper/ScanbotBarcodeSDKWrapper-Swift.h>
22
21
  #import <Foundation/Foundation.h>
23
22
 
24
23
  using namespace facebook::react;
@@ -27,14 +26,18 @@ static inline NSString* toNSString(std::string value) {
27
26
  return [[NSString alloc] initWithCString:value.c_str() encoding:NSUTF8StringEncoding];
28
27
  }
29
28
 
30
- static inline bool isUndefined(facebook::react::Float value) {
31
- return isnan(value) || value == -1;
29
+ static inline bool isFloatDefined(facebook::react::Float value) {
30
+ // If value is not set from the typescript, by default -1 is allocated from the props
31
+ return !(isnan(value) || value == -1);
32
+ }
33
+
34
+ static inline bool isIntDefined(int value) {
35
+ // If value is not set from the typescript, by default -1 is allocated from the props
36
+ return !(isnan(value) || value == -1);
32
37
  }
33
38
 
34
39
  @interface RTNScanbotBarcodeCameraView () <RCTRTNScanbotBarcodeCameraViewViewProtocol>
35
40
  @property(nonatomic, strong) SBSDKBarcodeScannerViewController *viewController;
36
- @property(nonatomic, strong) SBSDKUIBarcodeFilter *barcodeFilter;
37
- @property(nonatomic) CGFloat userDefinedCameraZoomFactor;
38
41
  @property(nonatomic) BOOL isFirstLaunch;
39
42
  @property(nonatomic) BOOL scanningEnabled;
40
43
  @end
@@ -53,8 +56,6 @@ static inline bool isUndefined(facebook::react::Float value) {
53
56
  static const auto defaultProps = std::make_shared<const RTNScanbotBarcodeCameraViewProps>();
54
57
  _props = defaultProps;
55
58
 
56
- self.barcodes = [[NSMutableArray alloc] init];
57
- _userDefinedCameraZoomFactor = -1;
58
59
  _scanningEnabled = true;
59
60
  }
60
61
  return self;
@@ -113,7 +114,7 @@ static inline bool isUndefined(facebook::react::Float value) {
113
114
  return NULL;
114
115
  }
115
116
 
116
- - (void)sendScanResults:(NSArray<SBSDKBarcodeScannerResult*>*) results onImage:(UIImage*)image {
117
+ - (void)sendScanResults:(NSArray<SBSDKBarcodeScannerResult*>*) results {
117
118
  if (_eventEmitter == nullptr) {
118
119
  return;
119
120
  }
@@ -122,54 +123,42 @@ static inline bool isUndefined(facebook::react::Float value) {
122
123
  return;
123
124
  }
124
125
 
125
- if (self.barcodeFilter != nil) {
126
- results = filterBarcodeResults(results, _barcodeFilter);
127
- }
128
-
129
- NSDictionary* outResult = @{
130
- @"result": @{
131
- @"status": @"OK",
132
- @"barcodes": jsonFromBarcodeResults(results)
133
- }
134
- };
126
+ NSDictionary* _Nullable result = [SBBWrapperBarcodeScannerResult nativeResultsToDictionary:results];
135
127
 
136
- NSData *data = [NSJSONSerialization dataWithJSONObject:outResult options:NSJSONWritingFragmentsAllowed error:nil];
137
- NSString *jsonResult = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
138
-
139
- const auto &eventEmitter = std::dynamic_pointer_cast<const facebook::react::RTNScanbotBarcodeCameraViewEventEmitter>(_eventEmitter);
140
- eventEmitter->onNativeBarcodeScannerResult(facebook::react::RTNScanbotBarcodeCameraViewEventEmitter::OnNativeBarcodeScannerResult{.jsonResult = std::string([jsonResult UTF8String])});
141
- }
142
-
143
- // MARK: - Utility View Configuration Methods
144
-
145
- /* TODO: A single property change requires us to create a new ViewFinder configuration */
146
- - (SBSDKBaseScannerViewFinderConfiguration*)createViewFinderConfigurationCopy
147
- {
148
- SBSDKBaseScannerViewFinderConfiguration* oldConfig = self.viewController.viewFinderConfiguration;
149
- SBSDKBaseScannerViewFinderConfiguration* newConfig = [SBSDKBaseScannerViewFinderConfiguration defaultConfiguration];
150
-
151
- newConfig.viewFinderEnabled = oldConfig.viewFinderEnabled;
152
- newConfig.aspectRatio = oldConfig.aspectRatio;
153
- newConfig.minimumInset = oldConfig.minimumInset;
154
- newConfig.preferredHeight = oldConfig.preferredHeight;
155
- newConfig.ignoresSafeAreaInsets = oldConfig.ignoresSafeAreaInsets;
156
- newConfig.secondaryAspectRatio = oldConfig.secondaryAspectRatio;
157
- newConfig.secondaryMinimumInset = oldConfig.secondaryMinimumInset;
158
- newConfig.lineColor = oldConfig.lineColor;
159
- newConfig.backgroundColor = oldConfig.backgroundColor;
160
- newConfig.lineCornerRadius = oldConfig.lineCornerRadius;
161
- newConfig.lineWidth = oldConfig.lineWidth;
162
- newConfig.animateChanges = oldConfig.animateChanges;
163
- newConfig.backgroundEffect = oldConfig.backgroundEffect;
164
-
165
- return newConfig;
128
+ if(result != NULL) {
129
+ NSDictionary* outResult = @{
130
+ @"result": result
131
+ };
132
+
133
+ NSData *data = [NSJSONSerialization dataWithJSONObject:outResult options:NSJSONWritingFragmentsAllowed error:nil];
134
+ NSString *jsonResult = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
135
+
136
+ const auto &eventEmitter = std::dynamic_pointer_cast<const facebook::react::RTNScanbotBarcodeCameraViewEventEmitter>(_eventEmitter);
137
+
138
+ eventEmitter->onNativeBarcodeScannerResult(facebook::react::RTNScanbotBarcodeCameraViewEventEmitter::OnNativeBarcodeScannerResult{.jsonResult = std::string([jsonResult UTF8String])});
139
+ }
166
140
  }
167
141
 
168
142
  // MARK: - React Native Lifecycle
169
143
  - (void)applyProps:(const facebook::react::Props::Shared &)props oldProps:(const facebook::react::Props::Shared &)oldProps forceUpdate:(bool)forceUpdate {
144
+
170
145
  const auto &oldViewProps = *std::static_pointer_cast<RTNScanbotBarcodeCameraViewProps const>(_props);
171
146
  const auto &newViewProps = *std::static_pointer_cast<RTNScanbotBarcodeCameraViewProps const>(props);
172
147
 
148
+ NSDictionary *oldViewPropsAsDictionary = [[NSDictionary alloc] init];
149
+ oldViewPropsAsDictionary = [self barcodeCameraViewConfigurationStructToDictionary:oldViewProps.configuration];
150
+
151
+ SBBWrapperBarcodeCameraViewConfiguration* oldBarcodeCameraViewConfiguration = [SBBWrapperBarcodeCameraViewConfiguration fromDicitonary:oldViewPropsAsDictionary];
152
+
153
+ NSDictionary *newViewPropsAsDictionary = [[NSDictionary alloc] init];
154
+ newViewPropsAsDictionary = [self barcodeCameraViewConfigurationStructToDictionary:newViewProps.configuration];
155
+
156
+ SBBWrapperBarcodeCameraViewConfiguration* newBarcodeCameraViewConfiguration = [SBBWrapperBarcodeCameraViewConfiguration fromDicitonary:newViewPropsAsDictionary];
157
+
158
+ if(newBarcodeCameraViewConfiguration == NULL || oldBarcodeCameraViewConfiguration == NULL) {
159
+ return;
160
+ }
161
+
173
162
  // -----------------------------------------
174
163
  // START OF ViewFinderConfiguration MAPPING
175
164
  // -----------------------------------------
@@ -180,124 +169,86 @@ static inline bool isUndefined(facebook::react::Float value) {
180
169
 
181
170
  SBSDKBaseScannerViewFinderConfiguration* viewFinderConfiguration = [SBSDKBaseScannerViewFinderConfiguration defaultConfiguration];
182
171
 
183
- viewFinderConfiguration.viewFinderEnabled = newViewProps.configuration.shouldUseFinderView;
184
-
185
- if (!isUndefined(newViewProps.configuration.finderLineWidth)) {
186
- viewFinderConfiguration.lineWidth = newViewProps.configuration.finderLineWidth;
187
-
188
- }
172
+ viewFinderConfiguration.viewFinderEnabled = newBarcodeCameraViewConfiguration.shouldUseFinderView;
189
173
 
190
- if (!newViewProps.configuration.finderLineColor.empty()) {
191
- viewFinderConfiguration.lineColor = [UIColor colorFromHexString:toNSString(newViewProps.configuration.finderLineColor)];
174
+ if (isIntDefined(newBarcodeCameraViewConfiguration.finderLineWidth)) {
175
+ viewFinderConfiguration.lineWidth = newBarcodeCameraViewConfiguration.finderLineWidth;
192
176
  }
193
-
194
- if (!newViewProps.configuration.finderBackgroundColor.empty()) {
195
- viewFinderConfiguration.backgroundColor = [UIColor colorFromHexString:toNSString(newViewProps.configuration.finderBackgroundColor)];
177
+
178
+ if(![newBarcodeCameraViewConfiguration.finderLineColor isEqual: @""]) {
179
+ viewFinderConfiguration.lineColor = newBarcodeCameraViewConfiguration.finderLineColorAsUIColor;
196
180
  }
197
-
198
- if (!isUndefined(newViewProps.configuration.finderBackgroundOpacity)) {
199
- UIColor* bgColor = self.viewController.viewFinderConfiguration.backgroundColor;
200
- viewFinderConfiguration.backgroundColor = [bgColor colorWithAlphaComponent:newViewProps.configuration.finderBackgroundOpacity];
181
+
182
+ if(![newBarcodeCameraViewConfiguration.finderBackgroundColor isEqual: @""] && isFloatDefined(newBarcodeCameraViewConfiguration.finderBackgroundOpacity)) {
183
+ viewFinderConfiguration.backgroundColor = [newBarcodeCameraViewConfiguration.finderBackgroundColorAsUIColor colorWithAlphaComponent:newBarcodeCameraViewConfiguration.finderBackgroundOpacity];
201
184
  }
202
185
 
203
- if (
204
- !isUndefined(newViewProps.configuration.finderAspectRatio.width) &&
205
- !isUndefined(newViewProps.configuration.finderAspectRatio.height)
206
- ) {
207
- viewFinderConfiguration.aspectRatio = [[SBSDKAspectRatio alloc] initWithWidth:newViewProps.configuration.finderAspectRatio.width
208
- andHeight:newViewProps.configuration.finderAspectRatio.height];
186
+ if (isIntDefined(newBarcodeCameraViewConfiguration.finderAspectRatio.width) && isIntDefined(newBarcodeCameraViewConfiguration.finderAspectRatio.height)) {
187
+ viewFinderConfiguration.aspectRatio = [[SBSDKAspectRatio alloc] initWithWidth:newBarcodeCameraViewConfiguration.finderAspectRatio.width andHeight:newBarcodeCameraViewConfiguration.finderAspectRatio.height];
209
188
  }
210
-
211
189
 
212
- if (!isUndefined(newViewProps.configuration.finderInset.left) &&
213
- !isUndefined(newViewProps.configuration.finderInset.top) &&
214
- !isUndefined(newViewProps.configuration.finderInset.right) &&
215
- !isUndefined(newViewProps.configuration.finderInset.bottom)
216
- ) {
217
- viewFinderConfiguration.minimumInset = UIEdgeInsetsMake(newViewProps.configuration.finderInset.top,
218
- newViewProps.configuration.finderInset.left,
219
- newViewProps.configuration.finderInset.bottom,
220
- newViewProps.configuration.finderInset.right);
190
+ if (newBarcodeCameraViewConfiguration.finderInset.insetsAreSet) {
191
+ viewFinderConfiguration.minimumInset = newBarcodeCameraViewConfiguration.finderInset.insets;
221
192
  }
222
193
 
223
194
  self.viewController.viewFinderConfiguration = viewFinderConfiguration;
224
195
  // ---------------------------------------
225
196
  // END OF ViewFinderConfiguration MAPPING
226
197
  // ---------------------------------------
227
-
228
- if (forceUpdate || oldViewProps.configuration.lowPowerMode != newViewProps.configuration.lowPowerMode) {
229
- // TODO: verify behavior
230
- }
231
198
 
232
- if (forceUpdate || oldViewProps.configuration.minimumTextLength != newViewProps.configuration.minimumTextLength) {
233
- if (!isUndefined(newViewProps.configuration.minimumTextLength)) {
234
- self.viewController.additionalDetectionParameters.minimumTextLength = newViewProps.configuration.minimumTextLength;
235
- }
199
+ if (isIntDefined(newBarcodeCameraViewConfiguration.minimumTextLength) && (forceUpdate || oldBarcodeCameraViewConfiguration.minimumTextLength != newBarcodeCameraViewConfiguration.minimumTextLength)) {
200
+ self.viewController.additionalDetectionParameters.minimumTextLength = newBarcodeCameraViewConfiguration.minimumTextLength;
236
201
  }
237
202
 
238
- if (forceUpdate || oldViewProps.configuration.maximumTextLength != newViewProps.configuration.maximumTextLength) {
239
- if (!isUndefined(newViewProps.configuration.maximumTextLength)) {
240
- self.viewController.additionalDetectionParameters.maximumTextLength = newViewProps.configuration.maximumTextLength;
241
- }
203
+ if (isIntDefined(newBarcodeCameraViewConfiguration.maximumTextLength) && (forceUpdate || oldBarcodeCameraViewConfiguration.maximumTextLength != newBarcodeCameraViewConfiguration.maximumTextLength)) {
204
+ self.viewController.additionalDetectionParameters.maximumTextLength = newBarcodeCameraViewConfiguration.maximumTextLength;
242
205
  }
243
206
 
244
- if (forceUpdate || oldViewProps.configuration.minimum1DBarcodesQuietZone != newViewProps.configuration.minimum1DBarcodesQuietZone) {
245
- if (!isUndefined(newViewProps.configuration.minimum1DBarcodesQuietZone)) {
246
- self.viewController.additionalDetectionParameters.minimum1DBarcodesQuietZone = newViewProps.configuration.minimum1DBarcodesQuietZone;
247
- }
207
+ if (isIntDefined(newBarcodeCameraViewConfiguration.minimum1DBarcodesQuietZone) && (forceUpdate || oldBarcodeCameraViewConfiguration.minimum1DBarcodesQuietZone != newBarcodeCameraViewConfiguration.minimum1DBarcodesQuietZone)) {
208
+ self.viewController.additionalDetectionParameters.minimum1DBarcodesQuietZone = newBarcodeCameraViewConfiguration.minimum1DBarcodesQuietZone;
248
209
  }
249
210
 
250
- if (forceUpdate || oldViewProps.configuration.stripCheckDigits != newViewProps.configuration.stripCheckDigits) {
251
- self.viewController.additionalDetectionParameters.stripCheckDigits = newViewProps.configuration.stripCheckDigits;
211
+ if (forceUpdate || oldBarcodeCameraViewConfiguration.stripCheckDigits != newBarcodeCameraViewConfiguration.stripCheckDigits) {
212
+ self.viewController.additionalDetectionParameters.stripCheckDigits = newBarcodeCameraViewConfiguration.stripCheckDigits;
252
213
  }
253
214
 
254
- if (forceUpdate || oldViewProps.configuration.gs1DecodingEnabled != newViewProps.configuration.gs1DecodingEnabled) {
255
- self.viewController.additionalDetectionParameters.enableGS1Decoding = newViewProps.configuration.gs1DecodingEnabled;
215
+ if (forceUpdate || oldBarcodeCameraViewConfiguration.gs1Handling != newBarcodeCameraViewConfiguration.gs1Handling) {
216
+ self.viewController.additionalDetectionParameters.gs1Handling = newBarcodeCameraViewConfiguration.gs1Handling;
256
217
  }
257
218
 
258
- if (forceUpdate || oldViewProps.configuration.msiPlesseyChecksumAlgorithm != newViewProps.configuration.msiPlesseyChecksumAlgorithm) {
259
- self.viewController.additionalDetectionParameters.msiPlesseyChecksumAlgorithm = extractMsiPlesseyChecksumAlgorithm(toNSString(newViewProps.configuration.msiPlesseyChecksumAlgorithm));
219
+ if (forceUpdate || oldBarcodeCameraViewConfiguration.msiPlesseyChecksumAlgorithm != newBarcodeCameraViewConfiguration.msiPlesseyChecksumAlgorithm) {
220
+ self.viewController.additionalDetectionParameters.msiPlesseyChecksumAlgorithm = newBarcodeCameraViewConfiguration.msiPlesseyChecksumAlgorithm;
260
221
  }
261
222
 
262
- if (forceUpdate || oldViewProps.configuration.codeDensity != newViewProps.configuration.codeDensity) {
263
- self.viewController.additionalDetectionParameters.codeDensity = extractBarcodeDensity(toNSString(newViewProps.configuration.codeDensity));
223
+ if (forceUpdate || oldBarcodeCameraViewConfiguration.codeDensity != newBarcodeCameraViewConfiguration.codeDensity) {
224
+ self.viewController.additionalDetectionParameters.codeDensity = newBarcodeCameraViewConfiguration.codeDensity;
264
225
  }
265
226
 
266
- if (forceUpdate || oldViewProps.configuration.flashEnabled != newViewProps.configuration.flashEnabled) {
267
- self.viewController.flashLightEnabled = newViewProps.configuration.flashEnabled;
227
+ if (forceUpdate || oldBarcodeCameraViewConfiguration.flashEnabled != newBarcodeCameraViewConfiguration.flashEnabled) {
228
+ self.viewController.flashLightEnabled = newBarcodeCameraViewConfiguration.flashEnabled;
268
229
  }
269
230
 
270
- if (forceUpdate || oldViewProps.configuration.barcodeFormats != newViewProps.configuration.barcodeFormats) {
271
- if (!newViewProps.configuration.barcodeFormats.empty()) {
272
- NSMutableArray* barcodeFormats = [NSMutableArray array];
273
- for (auto const& format : newViewProps.configuration.barcodeFormats) {
274
- SBSDKBarcodeType* type = barcodeTypeFromString(toNSString(format));
275
- if (type != nil) {
276
- [barcodeFormats addObject:type];
277
- }
278
- }
279
- self.viewController.acceptedBarcodeTypes = [barcodeFormats copy];
280
- }
231
+ if (forceUpdate || oldBarcodeCameraViewConfiguration.acceptedBarcodeTypes != newBarcodeCameraViewConfiguration.acceptedBarcodeTypes) {
232
+ self.viewController.acceptedBarcodeTypes = newBarcodeCameraViewConfiguration.acceptedBarcodeTypes;
281
233
  }
282
-
283
- if (forceUpdate || oldViewProps.configuration.engineMode != newViewProps.configuration.engineMode) {
284
- self.viewController.engineMode = extractEngineMode(toNSString(newViewProps.configuration.engineMode));
234
+
235
+ if (forceUpdate || oldBarcodeCameraViewConfiguration.acceptedDocumentTypes != newBarcodeCameraViewConfiguration.acceptedDocumentTypes) {
236
+ self.viewController.acceptedDocumentTypes = newBarcodeCameraViewConfiguration.acceptedDocumentTypes;
237
+ }
238
+
239
+ if (forceUpdate || oldBarcodeCameraViewConfiguration.engineMode != newBarcodeCameraViewConfiguration.engineMode) {
240
+ self.viewController.engineMode = newBarcodeCameraViewConfiguration.engineMode;
285
241
  }
286
242
 
287
- if (forceUpdate || oldViewProps.configuration.cameraZoomFactor != newViewProps.configuration.cameraZoomFactor) {
288
- if (!isUndefined(newViewProps.configuration.cameraZoomFactor)) {
289
- if (newViewProps.configuration.cameraZoomFactor != _userDefinedCameraZoomFactor || _userDefinedCameraZoomFactor == -1) {
290
- self.viewController.cameraZoomFactor = newViewProps.configuration.cameraZoomFactor;
291
- _userDefinedCameraZoomFactor = newViewProps.configuration.cameraZoomFactor;
292
- }
293
- }
243
+ if (isFloatDefined(newBarcodeCameraViewConfiguration.cameraZoomFactor) && (forceUpdate || oldBarcodeCameraViewConfiguration.cameraZoomFactor != newBarcodeCameraViewConfiguration.cameraZoomFactor)) {
244
+ self.viewController.cameraZoomFactor = newBarcodeCameraViewConfiguration.cameraZoomFactor;
294
245
  }
295
246
 
296
- if (forceUpdate || oldViewProps.configuration.barcodeFilter != newViewProps.configuration.barcodeFilter) {
297
- _barcodeFilter = extractBarcodeFilter(toNSString(newViewProps.configuration.barcodeFilter));
247
+ if (forceUpdate || oldBarcodeCameraViewConfiguration.barcodesExtensionFilter != newBarcodeCameraViewConfiguration.barcodesExtensionFilter) {
248
+ self.viewController.extensionFilter = newBarcodeCameraViewConfiguration.barcodesExtensionFilter;
298
249
  }
299
250
 
300
- _scanningEnabled = newViewProps.configuration.scanningEnabled;
251
+ _scanningEnabled = newBarcodeCameraViewConfiguration.scanningEnabled;
301
252
  }
302
253
 
303
254
  - (void)updateProps:(const facebook::react::Props::Shared &)props oldProps:(const facebook::react::Props::Shared &)oldProps {
@@ -311,6 +262,43 @@ static inline bool isUndefined(facebook::react::Float value) {
311
262
  [super updateProps:props oldProps:oldProps];
312
263
  }
313
264
 
265
+ - barcodeCameraViewConfigurationStructToDictionary:(facebook::react::RTNScanbotBarcodeCameraViewConfigurationStruct) configurationStruct
266
+ {
267
+ return @{
268
+ @"flashEnabled": @(configurationStruct.flashEnabled),
269
+ @"barcodeFormats": [self vectorStringToNSArray:configurationStruct.barcodeFormats],
270
+ @"acceptedDocumentFormats": [self vectorStringToNSArray:configurationStruct.acceptedDocumentFormats],
271
+ @"engineMode": toNSString(configurationStruct.engineMode),
272
+ @"cameraZoomFactor": @(configurationStruct.cameraZoomFactor),
273
+ @"barcodesExtensionFilter": toNSString(configurationStruct.barcodesExtensionFilter),
274
+ @"scanningEnabled": @(configurationStruct.scanningEnabled),
275
+ @"minimumTextLength": @(configurationStruct.minimumTextLength),
276
+ @"maximumTextLength": @(configurationStruct.maximumTextLength),
277
+ @"minimum1DBarcodesQuietZone": @(configurationStruct.minimum1DBarcodesQuietZone),
278
+ @"stripCheckDigits": @(configurationStruct.stripCheckDigits),
279
+ @"gs1HandlingMode": toNSString(configurationStruct.gs1HandlingMode),
280
+ @"msiPlesseyChecksumAlgorithm": toNSString(configurationStruct.msiPlesseyChecksumAlgorithm),
281
+ @"codeDensity": toNSString(configurationStruct.codeDensity),
282
+ @"shouldUseFinderView": @(configurationStruct.shouldUseFinderView),
283
+ @"finderLineWidth": @(configurationStruct.finderLineWidth),
284
+ @"finderLineColor": toNSString(configurationStruct.finderLineColor),
285
+ @"finderBackgroundColor": toNSString(configurationStruct.finderBackgroundColor),
286
+ @"finderBackgroundOpacity": @(configurationStruct.finderBackgroundOpacity),
287
+ @"finderAspectRatio": @{@"width": @(configurationStruct.finderAspectRatio.width), @"height": @(configurationStruct.finderAspectRatio.height)},
288
+ @"finderInset": @{@"left": @(configurationStruct.finderInset.left), @"top": @(configurationStruct.finderInset.top), @"bottom": @(configurationStruct.finderInset.bottom), @"right": @(configurationStruct.finderInset.right)}
289
+ };
290
+ }
291
+
292
+ - (NSArray*)vectorStringToNSArray:(std::vector<std::string>) vector {
293
+ NSMutableArray* nsArray = [NSMutableArray array];
294
+
295
+ for (auto const& value : vector) {
296
+ [nsArray addObject: toNSString(value)];
297
+ }
298
+
299
+ return nsArray;
300
+ }
301
+
314
302
  - (void)componentDidMount {
315
303
  _isFirstLaunch = true;
316
304
  [self applyProps:_props oldProps:_props forceUpdate:_isFirstLaunch];
@@ -328,7 +316,7 @@ static inline bool isUndefined(facebook::react::Float value) {
328
316
  didDetectBarcodes:(NSArray<SBSDKBarcodeScannerResult *> *)codes
329
317
  onImage:(nonnull UIImage *)image {
330
318
 
331
- [self sendScanResults:codes onImage:image];
319
+ [self sendScanResults:codes];
332
320
  }
333
321
 
334
322
  - (BOOL)barcodeScannerControllerShouldDetectBarcodes:(SBSDKBarcodeScannerViewController *)controller {
@@ -336,23 +324,7 @@ static inline bool isUndefined(facebook::react::Float value) {
336
324
  }
337
325
 
338
326
  - (void)barcodeScannerController:(nonnull SBSDKBarcodeScannerViewController *)controller didDetectBarcodes:(nonnull NSArray<SBSDKBarcodeScannerResult *> *)codes {
339
- [self sendScanResults:codes onImage:nil];
340
- }
341
-
342
-
343
- - (NSArray*)hashedBarcodes {
344
- NSMutableArray* outArray = [[NSMutableArray alloc] init];
345
- for (NSDictionary* barcode in self.barcodes) {
346
- NSString* hash = [RTNScanbotBarcodeCameraView hashFromBarcode:barcode];
347
- [outArray addObject:hash];
348
- }
349
- return outArray;
350
- }
351
-
352
- + (NSString*)hashFromBarcode: (NSDictionary* _Nonnull)barcode {
353
- NSString* text = [barcode objectForKey:@"barcode"];
354
- NSString* type = [barcode objectForKey:@"type"];
355
- return [[NSString stringWithFormat:@"%@_%@", text, type] lowercaseString];
327
+ [self sendScanResults:codes];
356
328
  }
357
329
 
358
330
  @end
@@ -18,12 +18,8 @@
18
18
  @interface RNScanbotBarcodeCameraView: UIView<SBSDKBarcodeScannerViewControllerDelegate>
19
19
 
20
20
  @property SBSDKBarcodeScannerViewController* _Nullable cameraViewController;
21
- @property NSMutableArray* _Nonnull barcodes;
22
21
  @property (nonatomic, copy) RCTBubblingEventBlock _Nullable onNativeBarcodeScannerResult;
23
22
  @property (nonatomic, copy) RCTBubblingEventBlock _Nullable requestComponentReload;
24
- @property (nonatomic) BOOL shouldUseFinderView;
25
- @property (nonatomic, copy) NSDictionary* _Nullable configuration;
26
- @property (nonatomic) BOOL finderInsetAvailable;
27
23
 
28
24
  - (void) createCameraViewController;
29
25
  - (UIViewController* _Nullable) getParentViewController;
@@ -35,33 +31,6 @@
35
31
 
36
32
  @end
37
33
 
38
- @interface RNScanbotCameraViewConfiguration: NSObject
39
-
40
- // Non-Nullable Properties
41
- @property (nonatomic) CGFloat finderLineWidth;
42
- @property (nonatomic) UIColor* _Nonnull finderLineColor;
43
- @property (nonatomic) UIColor* _Nonnull finderBackgroundColor;
44
- @property (nonatomic) CGFloat finderBackgroundOpacity;
45
- @property (nonatomic) SBSDKAspectRatio* _Nonnull finderAspectRatio;
46
- @property (nonatomic) BOOL scanningEnabled;
47
-
48
- // Nullable Properties (-1 for enums)
49
- @property (nonatomic, copy) NSNumber* _Nullable shouldUseFinderView;
50
- @property (nonatomic, copy) NSNumber* _Nullable flashEnabled;
51
- @property (nonatomic, copy) NSNumber* _Nullable cameraZoomFactor;
52
- @property (nonatomic, copy) NSNumber* _Nullable gs1DecodingEnabled;
53
- @property (nonatomic, copy) NSNumber* _Nullable minimumTextLength;
54
- @property (nonatomic, copy) NSNumber* _Nullable maximumTextLength;
55
- @property (nonatomic, copy) NSNumber* _Nullable stripCheckDigits;
56
- @property (nonatomic, copy) NSArray<SBSDKBarcodeType *>* _Nullable barcodeFormats;
57
- @property (nonatomic, copy) NSArray<SBSDKBarcodeDocumentType *>* _Nullable acceptedDocumentFormats;
58
- @property (nonatomic) SBSDKBarcodeMSIPlesseyChecksumAlgorithm msiPlesseyChecksumAlgorithm;
59
- @property (nonatomic) SBSDKBarcodeEngineMode engineMode;
60
- @property (nonatomic) SBSDKUIBarcodeFilter* _Nullable barcodeFilter;
61
- @property (nonatomic) SBSDKBarcodeDensity codeDensity;
62
- @property (nonatomic) UIEdgeInsets finderInset;
63
- @end
64
-
65
34
  #endif /* RNScanbotCameraView_h */
66
35
 
67
36
  #endif // ifdef RCT_NEW_ARCH_ENABLED