react-native-scanbot-barcode-scanner-sdk 3.7.1-beta.1 → 3.7.1-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.
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.1-beta.1",
4
+ "version": "3.7.1-beta.2",
5
5
  "scanbot": {
6
6
  "iosVersion": "4.0.0"
7
7
  },
@@ -3,7 +3,7 @@ import { EmitterSubscription, findNodeHandle, NativeMethods, Platform, UIManager
3
3
  import { Dimensions } from 'react-native';
4
4
  import { ScanbotBarcodeCameraNativeViewProperties, ScanbotBarcodeCameraViewConfiguration, ScanbotBarcodeCameraViewProperties } from './scanbot-barcode-camera-view-types';
5
5
  import ScanbotNativeBarcodeCameraView, { Commands } from './scanbot-native-barcode-camera-view';
6
- import { BarcodeResult } from 'react-native-scanbot-barcode-scanner-sdk/src/result';
6
+ import { BarcodeResult } from '../../result';
7
7
 
8
8
  const Device = {
9
9
  isPortrait: () => {
@@ -1,290 +0,0 @@
1
- //
2
- // RNScanbotCameraView.m
3
- // RNScanbotSDK
4
- //
5
- // Created by Marco Saia on 18.05.21.
6
- //
7
-
8
- // We use this compilation pragma to expose this implementation for the OLD ARCHITECTURE only
9
- #ifndef RCT_NEW_ARCH_ENABLED
10
-
11
- #import "RNScanbotBarcodeCameraView.h"
12
- #import "ObjectMapper.h"
13
- #import "BarcodeMapping.h"
14
-
15
- @import ScanbotBarcodeScannerSDK;
16
- @import Foundation;
17
-
18
- @implementation RNScanbotBarcodeCameraView {
19
- SBSDKBarcodeScannerViewController* viewController;
20
- RNScanbotCameraViewConfiguration* _cameraViewConfiguration;
21
- CGFloat _userDefinedCameraZoomFactor;
22
- }
23
-
24
- - (instancetype)initWithFrame:(CGRect)frame {
25
- self = [super initWithFrame:frame];
26
- self.barcodes = [[NSMutableArray alloc] init];
27
- self.shouldUseFinderView = false;
28
- _cameraViewConfiguration = [[RNScanbotCameraViewConfiguration alloc] init];
29
- _userDefinedCameraZoomFactor = -1;
30
- return self;
31
- }
32
-
33
- - (void)layoutSubviews {
34
- if (_cameraViewController) {
35
- _cameraViewController.view.frame = [self bounds];
36
- return;
37
- }
38
-
39
- __weak typeof(self) weakSelf = self;
40
-
41
- dispatch_async(dispatch_get_main_queue(), ^{
42
- [weakSelf createCameraViewController];
43
- });
44
- }
45
-
46
- - (void)createCameraViewController {
47
- UIViewController* parentViewController = [self getParentViewController];
48
- if (!parentViewController) {
49
- return;
50
- }
51
-
52
- if (!_cameraViewController) {
53
- viewController = [[SBSDKBarcodeScannerViewController alloc] initWithParentViewController:parentViewController
54
- parentView:self
55
- delegate:self];
56
- _cameraViewController = viewController;
57
- }
58
-
59
- [self updateWithConfiguration];
60
- }
61
-
62
- - (void)setConfiguration:(NSDictionary *)configuration {
63
- _configuration = configuration;
64
- if (configuration == NULL) {
65
- return;
66
- }
67
- RNScanbotCameraViewConfiguration* cameraViewConfiguration = [[RNScanbotCameraViewConfiguration alloc] init];
68
-
69
- NSMutableDictionary* config = [configuration mutableCopy];
70
- if ([config objectForKey:@"barcodeFormats"]) {
71
- cameraViewConfiguration.barcodeFormats = extractBarcodeTypesFromConfiguration(config);
72
- [config removeObjectForKey:@"barcodeFormats"];
73
- }
74
-
75
- if ([config objectForKey:@"barcodeFilter"]) {
76
- cameraViewConfiguration.barcodeFilter = extractBarcodeFilterFromConfiguration(config);
77
- [config removeObjectForKey:@"barcodeFilter"];
78
- }
79
-
80
- @try {
81
- [ObjectMapper populateInstance:cameraViewConfiguration fromDictionary:config];
82
- NSNumber *gs1Decoding = [config objectForKey:@"gs1DecodingEnabled"];
83
- if (gs1Decoding != nil) {
84
- cameraViewConfiguration.gs1DecodingEnabled = gs1Decoding;
85
- }
86
-
87
- // We also need to manually extract the MSI-Plessey Checksum Algorithm since it can't be mapped automatically
88
- cameraViewConfiguration.msiPlesseyChecksumAlgorithm = extractMsiPlesseyChecksumAlgorithmFromConfiguration(configuration);
89
- cameraViewConfiguration.codeDensity = extractBarcodeDensityFromConfiguration(config);
90
- cameraViewConfiguration.finderInset = [self populateFinderInset:config];
91
-
92
- self.shouldUseFinderView = [[config objectForKey:@"shouldUseFinderView"] boolValue];
93
-
94
- } @catch (NSException *exception) {
95
- NSLog(@"%@", [exception reason]);
96
- return;
97
- }
98
-
99
- _cameraViewConfiguration = cameraViewConfiguration;
100
-
101
- if(viewController) {
102
- [self updateWithConfiguration];
103
- }
104
- }
105
-
106
- - (void)updateWithConfiguration {
107
-
108
- SBSDKBaseScannerViewFinderConfiguration *configuration = [[SBSDKBaseScannerViewFinderConfiguration alloc] init];
109
- configuration.lineWidth = _cameraViewConfiguration.finderLineWidth;
110
- configuration.lineColor = _cameraViewConfiguration.finderLineColor;
111
- configuration.backgroundColor = _cameraViewConfiguration.finderBackgroundColor;
112
- configuration.backgroundColor = [configuration.backgroundColor colorWithAlphaComponent:_cameraViewConfiguration.finderBackgroundOpacity];
113
- configuration.aspectRatio = _cameraViewConfiguration.finderAspectRatio;
114
- if (self.finderInsetAvailable) {
115
- configuration.minimumInset = UIEdgeInsetsMake(_cameraViewConfiguration.finderInset.top,
116
- _cameraViewConfiguration.finderInset.left,
117
- _cameraViewConfiguration.finderInset.bottom,
118
- _cameraViewConfiguration.finderInset.right);
119
- }
120
- configuration.viewFinderEnabled = self.shouldUseFinderView;
121
- viewController.viewFinderConfiguration = configuration;
122
- if (_cameraViewConfiguration.barcodeFormats) {
123
- viewController.acceptedBarcodeTypes = _cameraViewConfiguration.barcodeFormats;
124
- }
125
- if (_cameraViewConfiguration.acceptedDocumentFormats) {
126
- viewController.acceptedDocumentTypes = _cameraViewConfiguration.acceptedDocumentFormats;
127
- }
128
-
129
- // Map Additional Parameters
130
- SBSDKBarcodeAdditionalParameters* additionalParameters = [[SBSDKBarcodeAdditionalParameters alloc] init];
131
-
132
- if (_cameraViewConfiguration.gs1DecodingEnabled) {
133
- additionalParameters.enableGS1Decoding = [_cameraViewConfiguration.gs1DecodingEnabled boolValue];
134
- }
135
- if (_cameraViewConfiguration.maximumTextLength) {
136
- additionalParameters.maximumTextLength = [_cameraViewConfiguration.maximumTextLength intValue];
137
- }
138
- if (_cameraViewConfiguration.minimumTextLength) {
139
- additionalParameters.minimumTextLength = [_cameraViewConfiguration.minimumTextLength intValue];
140
- }
141
- if (_cameraViewConfiguration.msiPlesseyChecksumAlgorithm != -1) {
142
- additionalParameters.msiPlesseyChecksumAlgorithm = _cameraViewConfiguration.msiPlesseyChecksumAlgorithm;
143
- }
144
- if (_cameraViewConfiguration.stripCheckDigits) {
145
- additionalParameters.stripCheckDigits = [_cameraViewConfiguration.stripCheckDigits boolValue];
146
- }
147
- if (_cameraViewConfiguration.codeDensity) {
148
- additionalParameters.codeDensity = _cameraViewConfiguration.codeDensity;
149
- }
150
-
151
- viewController.additionalDetectionParameters = additionalParameters;
152
-
153
- if (_cameraViewConfiguration.cameraZoomFactor) {
154
- CGFloat value = [_cameraViewConfiguration.cameraZoomFactor floatValue];
155
- if (value != _userDefinedCameraZoomFactor || _userDefinedCameraZoomFactor == -1) {
156
- viewController.cameraZoomFactor = value;
157
- _userDefinedCameraZoomFactor = value;
158
- }
159
- }
160
- if (_cameraViewConfiguration.engineMode != -1) {
161
- viewController.engineMode = _cameraViewConfiguration.engineMode;
162
- }
163
- if (_cameraViewConfiguration.flashEnabled) {
164
- viewController.flashLightEnabled = [_cameraViewConfiguration.flashEnabled boolValue];
165
- }
166
- }
167
-
168
-
169
- - (UIEdgeInsets)populateFinderInset: (NSMutableDictionary*)config {
170
- UIEdgeInsets finderInset = UIEdgeInsetsZero;
171
- NSMutableDictionary* jsonConfig = [config objectForKey:@"finderInset"];
172
- if (jsonConfig) {
173
- double left = [[jsonConfig objectForKey:@"left"] doubleValue];
174
- double top = [[jsonConfig objectForKey:@"top"] doubleValue];
175
- double right = [[jsonConfig objectForKey:@"right"] doubleValue];
176
- double bottom = [[jsonConfig objectForKey:@"bottom"] doubleValue];
177
-
178
- finderInset = UIEdgeInsetsMake(top, left, bottom, right);
179
- self.finderInsetAvailable = true;
180
- } else {
181
- self.finderInsetAvailable = false;
182
- }
183
- return finderInset;
184
- }
185
-
186
-
187
- - (UIViewController* _Nullable)getParentViewController {
188
- UIResponder* parentResponder = self;
189
- while (parentResponder) {
190
- parentResponder = parentResponder.nextResponder;
191
- if (parentResponder && [parentResponder isKindOfClass:[UIViewController class]]) {
192
- return (UIViewController*) parentResponder;
193
- }
194
- }
195
- return NULL;
196
- }
197
-
198
- - (void)sendScanResults:(NSArray<SBSDKBarcodeScannerResult*>*) results onImage:(UIImage*)image {
199
- if(!self.onNativeBarcodeScannerResult) {
200
- return;
201
- }
202
-
203
- if(!results || results.count == 0) {
204
- return;
205
- }
206
-
207
- if (_cameraViewConfiguration.barcodeFilter != nil) {
208
- results = filterBarcodeResults(results, _cameraViewConfiguration.barcodeFilter);
209
- }
210
-
211
- NSDictionary* outResult = @{
212
- @"result": @{
213
- @"status": @"OK",
214
- @"barcodes": jsonFromBarcodeResults(results)
215
- }
216
- };
217
-
218
- self.onNativeBarcodeScannerResult(outResult);
219
- }
220
-
221
- // MARK: - React Native Lifecycle
222
- - (void)componentDidMount {}
223
- - (void)componentDidUpdate {}
224
- - (void)componentWillUnmount {}
225
- - (void)orientationChanged {}
226
-
227
- // MARK: - SBSDKBarcodeScannerViewControllerDelegate
228
-
229
- - (void)barcodeScannerController:(SBSDKBarcodeScannerViewController *)controller
230
- didDetectBarcodes:(NSArray<SBSDKBarcodeScannerResult *> *)codes
231
- onImage:(nonnull UIImage *)image {
232
-
233
- [self sendScanResults:codes onImage:image];
234
- }
235
-
236
- - (BOOL)barcodeScannerControllerShouldDetectBarcodes:(SBSDKBarcodeScannerViewController *)controller {
237
- return true;
238
- }
239
-
240
- - (void)barcodeScannerController:(nonnull SBSDKBarcodeScannerViewController *)controller didDetectBarcodes:(nonnull NSArray<SBSDKBarcodeScannerResult *> *)codes {
241
- [self sendScanResults:codes onImage:nil];
242
- }
243
-
244
-
245
- - (NSArray*)hashedBarcodes {
246
- NSMutableArray* outArray = [[NSMutableArray alloc] init];
247
- for (NSDictionary* barcode in self.barcodes) {
248
- NSString* hash = [RNScanbotBarcodeCameraView hashFromBarcode:barcode];
249
- [outArray addObject:hash];
250
- }
251
- return outArray;
252
- }
253
-
254
- + (NSString*)hashFromBarcode: (NSDictionary* _Nonnull)barcode {
255
- NSString* text = [barcode objectForKey:@"barcode"];
256
- NSString* type = [barcode objectForKey:@"type"];
257
- return [[NSString stringWithFormat:@"%@_%@", text, type] lowercaseString];
258
- }
259
-
260
- @end
261
-
262
- @implementation RNScanbotCameraViewConfiguration
263
-
264
- - (instancetype)init
265
- {
266
- self = [super init];
267
- if (self) {
268
- self.shouldUseFinderView = false;
269
- self.finderLineWidth = 1.0;
270
- self.finderLineColor = UIColor.whiteColor;
271
- self.finderAspectRatio = [[SBSDKAspectRatio alloc] initWithWidth:1 andHeight:1];
272
- self.finderBackgroundColor = UIColor.blackColor;
273
- self.finderBackgroundOpacity = 0.6;
274
- self.acceptedDocumentFormats = nil;
275
- self.gs1DecodingEnabled = nil;
276
- self.maximumTextLength = nil;
277
- self.minimumTextLength = nil;
278
- self.msiPlesseyChecksumAlgorithm = -1;
279
- self.cameraZoomFactor = nil;
280
- self.engineMode = -1;
281
- self.flashEnabled = nil;
282
- self.finderInset = UIEdgeInsetsMake(32, 32, 32, 32);
283
- }
284
- return self;
285
- }
286
-
287
- @end
288
-
289
- #endif // ifndef RCT_NEW_ARCH_ENABLED
290
-
@@ -1,76 +0,0 @@
1
- //
2
- // RNScanbotBarcodeCameraViewManager.m
3
- // RNScanbotSDK
4
- //
5
- // Created by Marco Saia on 17.05.21.
6
- //
7
-
8
- // We use this compilation pragma to expose this implementation for the OLD ARCHITECTURE only
9
- #ifndef RCT_NEW_ARCH_ENABLED
10
-
11
- #import <Foundation/Foundation.h>
12
- #import "RNScanbotBarcodeCameraViewManager.h"
13
- #import "RNScanbotBarcodeCameraView.h"
14
- #import <React/RCTViewManager.h>
15
- #import <React/RCTUIManager.h>
16
-
17
- @import UIKit;
18
- @import ScanbotBarcodeScannerSDK;
19
-
20
- @implementation RNScanbotBarcodeCameraViewManager
21
-
22
- RCT_EXPORT_MODULE(RTNScanbotBarcodeCameraView)
23
-
24
- RCT_EXPORT_VIEW_PROPERTY(onNativeBarcodeScannerResult, RCTBubblingEventBlock)
25
- RCT_EXPORT_VIEW_PROPERTY(requestComponentReload, RCTBubblingEventBlock)
26
- RCT_EXPORT_VIEW_PROPERTY(shouldUseFinderView, BOOL)
27
- RCT_EXPORT_VIEW_PROPERTY(configuration, NSDictionary*)
28
-
29
- - (UIView *) view
30
- {
31
- return [[RNScanbotBarcodeCameraView alloc] init];
32
- }
33
-
34
- // componentDidMount
35
- RCT_EXPORT_METHOD(componentDidMount:(nonnull NSNumber*) reactTag) {
36
- [self callNativeMethodWithReactTag: reactTag andBlock: ^void (RNScanbotBarcodeCameraView* nativeView) {
37
- [nativeView componentDidMount];
38
- }];
39
- }
40
-
41
- // componentDidUpdate
42
- RCT_EXPORT_METHOD(componentDidUpdate:(nonnull NSNumber*) reactTag) {
43
- [self callNativeMethodWithReactTag: reactTag andBlock: ^void (RNScanbotBarcodeCameraView* nativeView) {
44
- [nativeView componentDidUpdate];
45
- }];
46
- }
47
-
48
- // componentWillUnmount
49
- RCT_EXPORT_METHOD(componentWillUnmount:(nonnull NSNumber*) reactTag) {
50
- [self callNativeMethodWithReactTag: reactTag andBlock: ^void (RNScanbotBarcodeCameraView* nativeView) {
51
- [nativeView componentWillUnmount];
52
- }];
53
- }
54
-
55
- // orientationChanged
56
- RCT_EXPORT_METHOD(orientationChanged:(nonnull NSNumber*) reactTag) {
57
- [self callNativeMethodWithReactTag: reactTag andBlock: ^void (RNScanbotBarcodeCameraView* nativeView) {
58
- [nativeView orientationChanged];
59
- }];
60
- }
61
-
62
-
63
- - (void) callNativeMethodWithReactTag:(nonnull NSNumber*) reactTag andBlock:(NativeViewBlock)block {
64
- [self.bridge.uiManager addUIBlock:^(RCTUIManager *uiManager, NSDictionary<NSNumber *,UIView *> *viewRegistry) {
65
- RNScanbotBarcodeCameraView* view = (RNScanbotBarcodeCameraView*) viewRegistry[reactTag];
66
- if (!view || ![view isKindOfClass:[RNScanbotBarcodeCameraView class]]) {
67
- RCTLogError(@"Cannot find native view with tag #%@", reactTag);
68
- return;
69
- }
70
- block(view);
71
- }];
72
- }
73
-
74
- @end
75
-
76
- #endif // ifndef RCT_NEW_ARCH_ENABLED