react-native-scanbot-barcode-scanner-sdk 4.3.0-beta.1 → 4.3.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.
@@ -3,6 +3,7 @@ package io.scanbot.barcodesdk.plugin.reactnative.components.barcode_scanner_view
3
3
  import android.content.res.Resources
4
4
  import com.facebook.react.bridge.ReadableArray
5
5
  import com.facebook.react.bridge.ReadableMap
6
+ import com.facebook.react.common.MapBuilder
6
7
  import com.facebook.react.module.annotations.ReactModule
7
8
  import com.facebook.react.uimanager.ThemedReactContext
8
9
  import com.facebook.react.uimanager.annotations.ReactProp
@@ -41,11 +42,13 @@ class ScanbotBarcodeScannerViewManager :
41
42
  return ScanbotBarcodeScannerView(context)
42
43
  }
43
44
 
44
- override fun getExportedCustomDirectEventTypeConstants(): MutableMap<String, Any>? {
45
- return mutableMapOf(
46
- BarcodeScannerResultEvent.NAME to mapOf("registrationName" to "onBarcodeScannerResult")
47
- )
48
- }
45
+ override fun getExportedCustomDirectEventTypeConstants(): MutableMap<String, Any>? =
46
+ MapBuilder.builder<String, Any>()
47
+ .put(
48
+ BarcodeScannerResultEvent.NAME,
49
+ MapBuilder.of("registrationName", "onBarcodeScannerResult")
50
+ )
51
+ .build()
49
52
 
50
53
  //region Commands
51
54
 
@@ -94,12 +94,11 @@ exports.ScanbotBarcodeCameraView = (0, react_1.forwardRef)(function (_a, forward
94
94
  };
95
95
  }, []);
96
96
  var _onBarcodeScannerResult = (0, react_1.useCallback)(function (event) {
97
- var result = react_native_1.Platform.select({
98
- ios: JSON.parse(event.nativeEvent.result),
99
- android: event.nativeEvent.result
100
- });
97
+ var result = event.nativeEvent.result;
101
98
  if (props.onBarcodeScannerResult && result) {
102
- props.onBarcodeScannerResult(result);
99
+ react_native_1.Platform.OS === 'ios' ?
100
+ props.onBarcodeScannerResult(JSON.parse(result)) :
101
+ props.onBarcodeScannerResult(result);
103
102
  }
104
103
  }, [props.onBarcodeScannerResult]);
105
104
  return <ScanbotBarcodeScannerViewNativeComponent_1.default
@@ -1,9 +1,3 @@
1
- //
2
- // RNScanbotBarcodeScannerPaperView.h
3
- // RNScanbotBarcodeSDK
4
- //
5
- // Created by Stefan Krzhovski on 27.05.24.
6
- //
7
1
 
8
2
  #if !defined(RCT_NEW_ARCH_ENABLED)
9
3
 
@@ -1,9 +1,4 @@
1
- //
2
- // RNScanbotBarcodeScannerPaperView.m
3
- // RNScanbotBarcodeSDK
4
- //
5
- // Created by Stefan Krzhovski on 27.05.24.
6
- //
1
+
7
2
  #if !defined(RCT_NEW_ARCH_ENABLED)
8
3
  #import "RNScanbotBarcodeScannerLegacyView.h"
9
4
  #import "RCTComponent.h"
@@ -22,7 +17,7 @@
22
17
  _scannerViewController = [RNScanbotBarcodeScannerViewControllerWrapper initController];
23
18
  _scannerViewController.delegate = self;
24
19
  }
25
-
20
+
26
21
  return self;
27
22
  }
28
23
 
@@ -1,8 +1,4 @@
1
- //
2
- // RNScanbotBarcodeScannerView.h
3
- //
4
- // Created by Stefan Krzhovski on 21.05.24.
5
- //
1
+
6
2
  #ifdef RCT_NEW_ARCH_ENABLED
7
3
  #import <React/RCTViewComponentView.h>
8
4
  #import <UIKit/UIKit.h>
@@ -14,6 +10,8 @@
14
10
  NS_ASSUME_NONNULL_BEGIN
15
11
 
16
12
  @interface RNScanbotBarcodeScannerView : RCTViewComponentView<SBSDKBarcodeScannerViewControllerDelegate>
13
+ - (void) freezeCamera;
14
+ - (void) unfreezeCamera;
17
15
  @end
18
16
 
19
17
  NS_ASSUME_NONNULL_END
@@ -1,9 +1,4 @@
1
- //
2
- // RNScanbotBarcodeScannerView.m
3
- // RNScanbotBarcodeSDK
4
- //
5
- // Created by Stefan Krzhovski on 21.05.24.
6
- //
1
+
7
2
  #ifdef RCT_NEW_ARCH_ENABLED
8
3
  #import "RNScanbotBarcodeScannerView.h"
9
4
 
@@ -38,7 +33,7 @@ using namespace facebook::react;
38
33
  _scannerViewController = [RNScanbotBarcodeScannerViewControllerWrapper initController];
39
34
  _scannerViewController.delegate = self;
40
35
  }
41
-
36
+
42
37
  return self;
43
38
  }
44
39
 
@@ -58,7 +53,7 @@ using namespace facebook::react;
58
53
  {
59
54
  const auto &oldViewProps = *std::static_pointer_cast<ScanbotBarcodeScannerViewProps const>(_props);
60
55
  const auto &newViewProps = *std::static_pointer_cast<ScanbotBarcodeScannerViewProps const>(props);
61
-
56
+
62
57
  SBSDKBaseScannerViewFinderConfiguration *finderConfig = self.scannerViewController.viewFinderConfiguration;
63
58
  SBSDKBaseScannerZoomConfiguration *zoomConfig = self.scannerViewController.zoomConfiguration;
64
59
  SBSDKBarcodeAdditionalParameters *additionalConfig = self.scannerViewController.additionalDetectionParameters;
@@ -70,7 +65,7 @@ using namespace facebook::react;
70
65
  @"gs1HandlingMode": toNSString(newViewProps.detectorConfig.gs1HandlingMode),
71
66
  @"msiPlesseyChecksumAlgorithm": toNSString(newViewProps.detectorConfig.msiPlesseyChecksumAlgorithm),
72
67
  }];
73
-
68
+
74
69
  if(oldViewProps.flashEnabled != newViewProps.flashEnabled){
75
70
  [RNScanbotBarcodeScannerViewControllerWrapper setFlashEnabled:self.scannerViewController value:newViewProps.flashEnabled];
76
71
  }
@@ -167,7 +162,7 @@ using namespace facebook::react;
167
162
  self.scannerViewController.viewFinderConfiguration = finderConfig;
168
163
  self.scannerViewController.zoomConfiguration = zoomConfig;
169
164
  self.scannerViewController.additionalDetectionParameters = additionalConfig;
170
-
165
+
171
166
  [super updateProps:props oldProps:oldProps];
172
167
  }
173
168
 
@@ -189,7 +184,7 @@ using namespace facebook::react;
189
184
  - (void)barcodeScannerController:(SBSDKBarcodeScannerViewController *)controller
190
185
  didDetectBarcodes:(NSArray<SBSDKBarcodeScannerResult *> *)codes {
191
186
  if (_eventEmitter == nullptr) return;
192
-
187
+
193
188
  NSString *result = [RNScanbotBarcodeScannerViewControllerWrapper jsonFromResultOrNil:codes];
194
189
  if(result != nil){
195
190
  const auto &eventEmitter = std::dynamic_pointer_cast<const facebook::react::ScanbotBarcodeScannerViewEventEmitter>(_eventEmitter);
@@ -214,17 +209,17 @@ bool operator!=(ScanbotBarcodeScannerViewCameraZoomRangeStruct const &i, Scanbot
214
209
  }
215
210
 
216
211
  bool operator!=(std::vector<std::string> const &v1, std::vector<std::string> const &v2) {
217
-
212
+
218
213
  bool differentItems = false;
219
214
  if(v1.size() != v2.size()) return true;
220
-
215
+
221
216
  for(int i = 0; i< v1.size(); i++){
222
217
  if(!(v1[i] != v2[i])){
223
218
  differentItems = true;
224
219
  break;
225
220
  }
226
221
  }
227
-
222
+
228
223
  return differentItems;
229
224
  }
230
225
 
@@ -234,11 +229,11 @@ NSString* toNSString(std::string value) {
234
229
 
235
230
  - (NSArray*)vectorStringToNSArray:(std::vector<std::string>) vector {
236
231
  NSMutableArray* nsArray = [NSMutableArray array];
237
-
232
+
238
233
  for (auto const& value : vector) {
239
234
  [nsArray addObject: toNSString(value)];
240
235
  }
241
-
236
+
242
237
  return nsArray;
243
238
  }
244
239
 
@@ -1,9 +1,3 @@
1
- //
2
- // RNScanbotBarcodeScannerViewHandler.h
3
- // RNScanbotBarcodeSDK
4
- //
5
- // Created by Stefan Krzhovski on 27.05.24.
6
- //
7
1
 
8
2
  #ifndef RNScanbotBarcodeScannerViewControllerWrapper_h
9
3
  #define RNScanbotBarcodeScannerViewControllerWrapper_h
@@ -1,9 +1,3 @@
1
- //
2
- // RNScanbotBarcodeScannerViewHandler.m
3
- // RNScanbotBarcodeSDK
4
- //
5
- // Created by Stefan Krzhovski on 27.05.24.
6
- //
7
1
 
8
2
  #import <Foundation/Foundation.h>
9
3
  #import "RNScanbotBarcodeScannerViewControllerWrapper.h"
@@ -13,32 +7,32 @@
13
7
 
14
8
  + hexStringToColor:(NSString *)hexString
15
9
  {
16
-
10
+
17
11
  if ([hexString hasPrefix:@"#"]) {
18
12
  hexString = [hexString substringFromIndex:1];
19
13
  } else {
20
14
  return nil;
21
15
  }
22
-
16
+
23
17
  NSUInteger length = [hexString length];
24
18
  if (length != 6 && length != 8) {
25
19
  return nil;
26
20
  }
27
-
21
+
28
22
  unsigned int red, green, blue, alpha = 255;
29
23
  NSString *redString = [hexString substringWithRange:NSMakeRange(0, 2)];
30
24
  NSString *greenString = [hexString substringWithRange:NSMakeRange(2, 2)];
31
25
  NSString *blueString = [hexString substringWithRange:NSMakeRange(4, 2)];
32
-
26
+
33
27
  if (length == 8) {
34
28
  NSString *alphaString = [hexString substringWithRange:NSMakeRange(6, 2)];
35
29
  [[NSScanner scannerWithString:alphaString] scanHexInt:&alpha];
36
30
  }
37
-
31
+
38
32
  [[NSScanner scannerWithString:redString] scanHexInt:&red];
39
33
  [[NSScanner scannerWithString:greenString] scanHexInt:&green];
40
34
  [[NSScanner scannerWithString:blueString] scanHexInt:&blue];
41
-
35
+
42
36
  return [UIColor colorWithRed:(CGFloat)red/255.0
43
37
  green:(CGFloat)green/255.0
44
38
  blue:(CGFloat)blue/255.0
@@ -46,13 +40,13 @@
46
40
  }
47
41
 
48
42
  + (SBSDKBarcodeScannerViewController *)initController {
49
-
43
+
50
44
  SBSDKBarcodeScannerViewController *scannerViewController = [[SBSDKBarcodeScannerViewController alloc] init];
51
45
  scannerViewController.viewFinderConfiguration = [SBSDKBaseScannerViewFinderConfiguration defaultConfiguration];
52
46
  scannerViewController.generalConfiguration = [SBSDKBaseScannerGeneralConfiguration defaultConfiguration];
53
47
  scannerViewController.zoomConfiguration = [SBSDKBaseScannerZoomConfiguration defaultConfiguration];
54
48
  scannerViewController.energyConfiguration = [SBSDKBaseScannerEnergyConfiguration defaultConfiguration];
55
-
49
+
56
50
  return scannerViewController;
57
51
  }
58
52
 
@@ -70,7 +64,7 @@
70
64
 
71
65
  + (void)setFinderStrokeColor:(SBSDKBaseScannerViewFinderConfiguration *)config value:(UIColor *)value {
72
66
  config.lineColor = value;
73
-
67
+
74
68
  }
75
69
 
76
70
  + (void)setFinderOverlayColor:(SBSDKBaseScannerViewFinderConfiguration *)config value:(UIColor *)value {
@@ -181,13 +175,13 @@
181
175
 
182
176
  + (NSString *) jsonFromResultOrNil:(NSArray<SBSDKBarcodeScannerResult *> *)codes {
183
177
  if(!codes || codes.count == 0) return nil;
184
-
178
+
185
179
  NSDictionary* _Nullable result = [SBBWrapperBarcodeScannerResult nativeResultsToDictionary:codes];
186
180
  if(result != NULL) {
187
181
  NSData *data = [NSJSONSerialization dataWithJSONObject:result options:NSJSONWritingFragmentsAllowed error:nil];
188
182
  return [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
189
183
  }
190
-
184
+
191
185
  return nil;
192
186
  }
193
187
 
@@ -1,19 +1,18 @@
1
- //
2
- // RNScanbotBarcodeScannerViewManager.m
3
- // RNScanbotBarcodeSDK
4
- //
5
- // Created by Stefan Krzhovski on 21.05.24.
6
- //
7
1
 
8
- #if !defined(RCT_NEW_ARCH_ENABLED)
9
2
  #import <Foundation/Foundation.h>
10
3
  #import <React/RCTLog.h>
11
4
  #import <React/RCTUIManager.h>
12
5
  #import <React/RCTViewManager.h>
13
6
  #import <UIKit/UIKit.h>
14
- #import "RNScanbotBarcodeScannerLegacyView.h"
15
7
 
8
+
9
+ #if !defined(RCT_NEW_ARCH_ENABLED)
10
+ #import "RNScanbotBarcodeScannerLegacyView.h"
16
11
  typedef void (^NativeViewBlock)(RNScanbotBarcodeScannerLegacyView* _Nonnull);
12
+ #else
13
+ #import "RNScanbotBarcodeScannerView.h"
14
+ #endif
15
+
17
16
 
18
17
  @interface RNScanbotBarcodeScannerViewManager: RCTViewManager
19
18
  @end
@@ -23,7 +22,11 @@ typedef void (^NativeViewBlock)(RNScanbotBarcodeScannerLegacyView* _Nonnull);
23
22
  RCT_EXPORT_MODULE(ScanbotBarcodeScannerView)
24
23
 
25
24
  - (UIView *)view {
25
+ #if !defined(RCT_NEW_ARCH_ENABLED)
26
26
  return [[RNScanbotBarcodeScannerLegacyView alloc] init];
27
+ #else
28
+ return [[RNScanbotBarcodeScannerView alloc] init];
29
+ #endif
27
30
  }
28
31
 
29
32
  RCT_EXPORT_VIEW_PROPERTY(onBarcodeScannerResult, RCTDirectEventBlock)
@@ -44,7 +47,7 @@ RCT_EXPORT_VIEW_PROPERTY(detectorConfig, NSDictionary)
44
47
  RCT_EXPORT_VIEW_PROPERTY(scanningEnabled, BOOL)
45
48
 
46
49
  //Commands
47
-
50
+ #if !defined(RCT_NEW_ARCH_ENABLED)
48
51
  RCT_EXPORT_METHOD(freezeCamera:(nonnull NSNumber*) reactTag) {
49
52
  [self callNativeMethodWithReactTag: reactTag andBlock: ^void (RNScanbotBarcodeScannerLegacyView *nativeView) {
50
53
  [nativeView freezeCamera];
@@ -67,7 +70,7 @@ RCT_EXPORT_METHOD(unfreezeCamera:(nonnull NSNumber*) reactTag) {
67
70
  block(view);
68
71
  }];
69
72
  }
73
+ #endif
70
74
 
71
- @end
72
75
 
73
- #endif
76
+ @end
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "react-native-scanbot-barcode-scanner-sdk",
3
3
  "title": "Scanbot Barcode Scanner SDK for React Native",
4
- "version": "4.3.0-beta.1",
4
+ "version": "4.3.0-beta.2",
5
5
  "packageManager": "yarn@3.8.1",
6
6
  "react-native": "src/index.ts",
7
7
  "main": "dist/index.js",
@@ -1,6 +1,9 @@
1
1
  import React, { forwardRef, useCallback, useImperativeHandle, useRef } from 'react';
2
- import NativeBarcodeCameraView, {Commands} from '../spec/ScanbotBarcodeScannerViewNativeComponent';
3
- import { ScanbotBarcodeCameraViewHandle, ScanbotBarcodeCameraViewProperties } from './ScanbotBarcodeCameraViewProperties';
2
+ import NativeBarcodeCameraView, { Commands } from '../spec/ScanbotBarcodeScannerViewNativeComponent';
3
+ import {
4
+ ScanbotBarcodeCameraViewHandle,
5
+ ScanbotBarcodeCameraViewProperties,
6
+ } from './ScanbotBarcodeCameraViewProperties';
4
7
  import { NativeSyntheticEvent, Platform } from 'react-native';
5
8
  import { BarcodeScannerResult } from '../../results';
6
9
 
@@ -65,12 +68,11 @@ export const ScanbotBarcodeCameraView = forwardRef<ScanbotBarcodeCameraViewHandl
65
68
  }, []);
66
69
 
67
70
  const _onBarcodeScannerResult = useCallback((event: NativeSyntheticEvent<any>) => {
68
- const result = Platform.select({
69
- ios: JSON.parse(event.nativeEvent.result),
70
- android: event.nativeEvent.result
71
- }) as (BarcodeScannerResult | undefined)
72
- if(props.onBarcodeScannerResult && result){
73
- props.onBarcodeScannerResult(result);
71
+ const result = event.nativeEvent.result;
72
+ if (props.onBarcodeScannerResult && result) {
73
+ Platform.OS === 'ios' ?
74
+ props.onBarcodeScannerResult(JSON.parse(result) as BarcodeScannerResult) :
75
+ props.onBarcodeScannerResult(result as BarcodeScannerResult);
74
76
  }
75
77
  }, [props.onBarcodeScannerResult]);
76
78