react-native-scanbot-barcode-scanner-sdk 3.6.1-alpha.1 → 3.6.1-alpha.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 (18) hide show
  1. package/RNScanbotBarcodeSDK.podspec +1 -1
  2. package/android/src/main/java/io/scanbot/barcodesdk/plugin/reactnative/components/barcodecameraview/ScanbotBarcodeCameraView.java +1 -1
  3. package/ios/Components/BarcodeCameraView/NewArchitecture/RTNScanbotBarcodeCameraView.h +46 -0
  4. package/ios/Components/BarcodeCameraView/NewArchitecture/RTNScanbotBarcodeCameraView.mm +364 -0
  5. package/ios/Components/BarcodeCameraView/NewArchitecture/RTNScanbotBarcodeCameraViewManager.mm +71 -0
  6. package/ios/Components/BarcodeCameraView/{RNScanbotBarcodeCameraView.h → OldArchitecture/RNScanbotBarcodeCameraView.h} +7 -2
  7. package/ios/Components/BarcodeCameraView/{RNScanbotBarcodeCameraView.m → OldArchitecture/RNScanbotBarcodeCameraView.m} +11 -5
  8. package/ios/Components/BarcodeCameraView/{RNScanbotBarcodeCameraViewManager.h → OldArchitecture/RNScanbotBarcodeCameraViewManager.h} +6 -1
  9. package/ios/Components/BarcodeCameraView/{RNScanbotBarcodeCameraViewManager.m → OldArchitecture/RNScanbotBarcodeCameraViewManager.m} +8 -3
  10. package/ios/ScanbotBarcodeSdk.h +1 -1
  11. package/ios/ScanbotBarcodeSdk.m +6 -6
  12. package/ios/Utils/BarcodeMapping.h +37 -30
  13. package/ios/Utils/ReactBarcodeExtensionsFilter.h +1 -1
  14. package/js/RTNScanbotBarcodeCameraViewNativeComponent.tsx +27 -1
  15. package/package.json +4 -4
  16. package/src/components/barcode-camera-view/scanbot-barcode-camera-view-types.tsx +8 -1
  17. package/src/components/barcode-camera-view/scanbot-barcode-camera-view.tsx +44 -15
  18. package/src/components/barcode-camera-view/scanbot-native-barcode-camera-view.tsx +2 -2
@@ -17,7 +17,7 @@ Pod::Spec.new do |s|
17
17
 
18
18
 
19
19
  s.source = { :http => 'https://download.scanbot.io/barcode-scanner-sdk/react-native/react-native-scanbot-barcode-scanner-sdk-' + package['version'] + '.tgz' }
20
- s.source_files = "ios/**/*.{h,m,swift}"
20
+ s.source_files = "ios/**/*.{h,m,mm,swift}"
21
21
  s.requires_arc = true
22
22
 
23
23
  install_modules_dependencies(s)
@@ -46,7 +46,7 @@ import kotlin.Unit;
46
46
  public class ScanbotBarcodeCameraView extends FrameLayout implements BarcodeDetectorFrameHandler.ResultHandler {
47
47
  // From Java to JavaScript
48
48
  public enum NativeEvents implements ScanbotEventEmitter.NativeEvent {
49
- BARCODE_SCANNER_RESULT("onBarcodeScannerResult");
49
+ BARCODE_SCANNER_RESULT("onNativeBarcodeScannerResult");
50
50
 
51
51
  private final String name;
52
52
  NativeEvents(final String name) {
@@ -0,0 +1,46 @@
1
+ //
2
+ // RTNScanbotBarcodeCameraView.h
3
+ // RTNScanbotSDK
4
+ //
5
+ // Created by Marco Saia on 18.05.21.
6
+ //
7
+
8
+ // We use this compilation pragma to expose this implementation for the NEW ARCHITECTURE only
9
+ #ifdef RCT_NEW_ARCH_ENABLED
10
+
11
+ #ifndef RTNScanbotCameraView_h
12
+ #define RTNScanbotCameraView_h
13
+
14
+ #import <React/RCTViewComponentView.h>
15
+ #import <React/RCTView.h>
16
+ #import <UIKit/UIKit.h>
17
+
18
+ #import <ScanbotBarcodeScannerSDK/ScanbotBarcodeScannerSDK.h>
19
+ #import <react/renderer/components/RTNScanbotBarcodeCameraViewSpecs/Props.h>
20
+
21
+ NS_ASSUME_NONNULL_BEGIN
22
+
23
+ @interface RTNScanbotBarcodeCameraView: RCTViewComponentView<SBSDKBarcodeScannerViewControllerDelegate>
24
+
25
+ @property SBSDKBarcodeScannerViewController* _Nullable cameraViewController;
26
+ @property NSMutableArray* _Nonnull barcodes;
27
+
28
+ // TODO: Check if required
29
+ @property (nonatomic, copy) RCTBubblingEventBlock _Nullable requestComponentReload;
30
+
31
+ @property (nonatomic) facebook::react::RTNScanbotBarcodeCameraViewConfigurationStruct configuration;
32
+
33
+ - (void) createCameraViewController;
34
+ - (UIViewController* _Nullable) getParentViewController;
35
+
36
+ - (void) componentDidMount;
37
+ - (void) componentDidUpdate;
38
+ - (void) componentWillUnmount;
39
+ - (void) orientationChanged;
40
+
41
+ @end
42
+
43
+ NS_ASSUME_NONNULL_END
44
+
45
+ #endif /* RTNScanbotCameraView_h */
46
+ #endif // ifdef RCT_NEW_ARCH_ENABLED
@@ -0,0 +1,364 @@
1
+ //
2
+ // RTNScanbotBarcodeCameraView.mm
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 NEW ARCHITECTURE only
9
+ #ifdef RCT_NEW_ARCH_ENABLED
10
+
11
+ #import <react/renderer/components/RTNScanbotBarcodeCameraViewSpecs/ComponentDescriptors.h>
12
+ #import <react/renderer/components/RTNScanbotBarcodeCameraViewSpecs/EventEmitters.h>
13
+ #import <react/renderer/components/RTNScanbotBarcodeCameraViewSpecs/Props.h>
14
+ #import <react/renderer/components/RTNScanbotBarcodeCameraViewSpecs/RCTComponentViewHelpers.h>
15
+
16
+ #import "RTNScanbotBarcodeCameraView.h"
17
+ #import "ObjectMapper.h"
18
+ #import "BarcodeMapping.h"
19
+ #import "RCTFabricComponentsPlugins.h"
20
+
21
+ #import <ScanbotBarcodeScannerSDK/ScanbotBarcodeScannerSDK.h>
22
+ #import <Foundation/Foundation.h>
23
+
24
+ using namespace facebook::react;
25
+
26
+ static inline NSString* toNSString(std::string value) {
27
+ return [[NSString alloc] initWithCString:value.c_str() encoding:NSUTF8StringEncoding];
28
+ }
29
+
30
+ static inline bool isUndefined(facebook::react::Float value) {
31
+ return isnan(value) || value == -1;
32
+ }
33
+
34
+ @interface RTNScanbotBarcodeCameraView () <RCTRTNScanbotBarcodeCameraViewViewProtocol>
35
+ @end
36
+
37
+ @implementation RTNScanbotBarcodeCameraView {
38
+ RTNScanbotBarcodeCameraViewConfigurationStruct _configuration;
39
+ SBSDKBarcodeScannerViewController* viewController;
40
+ SBSDKUIBarcodeFilter* _barcodeFilter;
41
+ CGFloat _userDefinedCameraZoomFactor;
42
+ BOOL _isFirstLaunch;
43
+ }
44
+
45
+ + (ComponentDescriptorProvider)componentDescriptorProvider
46
+ {
47
+ return concreteComponentDescriptorProvider<RTNScanbotBarcodeCameraViewComponentDescriptor>();
48
+ }
49
+
50
+ - (instancetype)initWithFrame:(CGRect)frame {
51
+ self = [super initWithFrame:frame];
52
+ if (self) {
53
+ _isFirstLaunch = true;
54
+ static const auto defaultProps = std::make_shared<const RTNScanbotBarcodeCameraViewProps>();
55
+ _props = defaultProps;
56
+
57
+ self.barcodes = [[NSMutableArray alloc] init];
58
+ _userDefinedCameraZoomFactor = -1;
59
+ }
60
+ return self;
61
+ }
62
+
63
+ - (void)layoutSubviews {
64
+ if (_cameraViewController) {
65
+ _cameraViewController.view.frame = [self bounds];
66
+ return;
67
+ }
68
+
69
+ __weak RTNScanbotBarcodeCameraView* weakSelf = self;
70
+
71
+ dispatch_async(dispatch_get_main_queue(), ^{
72
+ [weakSelf createCameraViewController];
73
+ });
74
+ }
75
+
76
+ - (void)createCameraViewController {
77
+ UIViewController* parentViewController = [self getParentViewController];
78
+ if (!parentViewController) {
79
+ return;
80
+ }
81
+
82
+ if (!_cameraViewController) {
83
+ viewController = [[SBSDKBarcodeScannerViewController alloc] initWithParentViewController:parentViewController
84
+ parentView:self
85
+ delegate:self];
86
+
87
+ _cameraViewController = viewController;
88
+ }
89
+ }
90
+
91
+ - (void)handleCommand:(const NSString *)commandName args:(const NSArray *)args {
92
+ if ([commandName isEqualToString:@"componentDidMount"]) {
93
+ [self componentDidMount];
94
+ } else if ([commandName isEqualToString:@"componentDidUpdate"]) {
95
+ [self componentDidUpdate];
96
+ } else if ([commandName isEqualToString:@"componentWillUnmount"]) {
97
+ [self componentWillUnmount];
98
+ } else if ([commandName isEqualToString:@"orientationChanged"]) {
99
+ [self orientationChanged];
100
+ } else {
101
+ NSLog(@"Unhandled React Native Command: %@", commandName);
102
+ }
103
+ }
104
+
105
+ - (UIViewController* _Nullable)getParentViewController {
106
+ UIResponder* parentResponder = self;
107
+ while (parentResponder) {
108
+ parentResponder = parentResponder.nextResponder;
109
+ if (parentResponder && [parentResponder isKindOfClass:[UIViewController class]]) {
110
+ return (UIViewController*) parentResponder;
111
+ }
112
+ }
113
+ return NULL;
114
+ }
115
+
116
+ - (void)sendScanResults:(NSArray<SBSDKBarcodeScannerResult*>*) results onImage:(UIImage*)image {
117
+ if (_eventEmitter == nullptr) {
118
+ return;
119
+ }
120
+
121
+ if(!results || results.count == 0) {
122
+ return;
123
+ }
124
+
125
+ if (_barcodeFilter != nil) {
126
+ results = filterBarcodeResults(results, _barcodeFilter);
127
+ }
128
+
129
+ NSDictionary* outResult = @{
130
+ @"result": @{
131
+ @"status": @"OK",
132
+ @"barcodes": jsonFromBarcodeResults(results)
133
+ }
134
+ };
135
+
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 = 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;
166
+ }
167
+
168
+ // MARK: - React Native Lifecycle
169
+ - (void)applyProps:(const facebook::react::Props::Shared &)props oldProps:(const facebook::react::Props::Shared &)oldProps forceUpdate:(bool)forceUpdate {
170
+ const auto &oldViewProps = *std::static_pointer_cast<RTNScanbotBarcodeCameraViewProps const>(_props);
171
+ const auto &newViewProps = *std::static_pointer_cast<RTNScanbotBarcodeCameraViewProps const>(props);
172
+
173
+ // -----------------------------------------
174
+ // START OF ViewFinderConfiguration MAPPING
175
+ // -----------------------------------------
176
+
177
+ // In order for the mapping to work we need to alloc, init and set a new SBSDKBaseScannerViewFinderConfiguration object
178
+ // in the Scanbot SDK ViewController configuration. Applying hot changes on the existing object does not update
179
+ // the component.
180
+
181
+ SBSDKBaseScannerViewFinderConfiguration* viewFinderConfiguration = [SBSDKBaseScannerViewFinderConfiguration defaultConfiguration];
182
+
183
+ viewFinderConfiguration.viewFinderEnabled = newViewProps.configuration.shouldUseFinderView;
184
+
185
+ if (!isUndefined(newViewProps.configuration.finderLineWidth)) {
186
+ viewFinderConfiguration.lineWidth = newViewProps.configuration.finderLineWidth;
187
+
188
+ }
189
+
190
+ if (!newViewProps.configuration.finderLineColor.empty()) {
191
+ viewFinderConfiguration.lineColor = [UIColor colorFromHexString:toNSString(newViewProps.configuration.finderLineColor)];
192
+ }
193
+
194
+ if (!newViewProps.configuration.finderBackgroundColor.empty()) {
195
+ viewFinderConfiguration.backgroundColor = [UIColor colorFromHexString:toNSString(newViewProps.configuration.finderBackgroundColor)];
196
+ }
197
+
198
+ if (!isUndefined(newViewProps.configuration.finderBackgroundOpacity)) {
199
+ UIColor* bgColor = viewController.viewFinderConfiguration.backgroundColor;
200
+ viewFinderConfiguration.backgroundColor = [bgColor colorWithAlphaComponent:newViewProps.configuration.finderBackgroundOpacity];
201
+ }
202
+
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];
209
+ }
210
+
211
+
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);
221
+ }
222
+
223
+ viewController.viewFinderConfiguration = viewFinderConfiguration;
224
+ // ---------------------------------------
225
+ // END OF ViewFinderConfiguration MAPPING
226
+ // ---------------------------------------
227
+
228
+ if (forceUpdate || oldViewProps.configuration.lowPowerMode != newViewProps.configuration.lowPowerMode) {
229
+ // TODO: verify behavior
230
+ }
231
+
232
+ if (forceUpdate || oldViewProps.configuration.minimumTextLength != newViewProps.configuration.minimumTextLength) {
233
+ if (!isUndefined(newViewProps.configuration.minimumTextLength)) {
234
+ viewController.additionalDetectionParameters.minimumTextLength = newViewProps.configuration.minimumTextLength;
235
+ }
236
+ }
237
+
238
+ if (forceUpdate || oldViewProps.configuration.maximumTextLength != newViewProps.configuration.maximumTextLength) {
239
+ if (!isUndefined(newViewProps.configuration.maximumTextLength)) {
240
+ viewController.additionalDetectionParameters.maximumTextLength = newViewProps.configuration.maximumTextLength;
241
+ }
242
+ }
243
+
244
+ if (forceUpdate || oldViewProps.configuration.minimum1DBarcodesQuietZone != newViewProps.configuration.minimum1DBarcodesQuietZone) {
245
+ if (!isUndefined(newViewProps.configuration.minimum1DBarcodesQuietZone)) {
246
+ viewController.additionalDetectionParameters.minimum1DBarcodesQuietZone = newViewProps.configuration.minimum1DBarcodesQuietZone;
247
+ }
248
+ }
249
+
250
+ if (forceUpdate || oldViewProps.configuration.stripCheckDigits != newViewProps.configuration.stripCheckDigits) {
251
+ viewController.additionalDetectionParameters.stripCheckDigits = newViewProps.configuration.stripCheckDigits;
252
+ }
253
+
254
+ if (forceUpdate || oldViewProps.configuration.gs1DecodingEnabled != newViewProps.configuration.gs1DecodingEnabled) {
255
+ viewController.additionalDetectionParameters.enableGS1Decoding = newViewProps.configuration.gs1DecodingEnabled;
256
+ }
257
+
258
+ if (forceUpdate || oldViewProps.configuration.msiPlesseyChecksumAlgorithm != newViewProps.configuration.msiPlesseyChecksumAlgorithm) {
259
+ viewController.additionalDetectionParameters.msiPlesseyChecksumAlgorithm = extractMsiPlesseyChecksumAlgorithm(toNSString(newViewProps.configuration.msiPlesseyChecksumAlgorithm));
260
+ }
261
+
262
+ if (forceUpdate || oldViewProps.configuration.codeDensity != newViewProps.configuration.codeDensity) {
263
+ viewController.additionalDetectionParameters.codeDensity = extractBarcodeDensity(toNSString(newViewProps.configuration.codeDensity));
264
+ }
265
+
266
+ if (forceUpdate || oldViewProps.configuration.flashEnabled != newViewProps.configuration.flashEnabled) {
267
+ viewController.flashLightEnabled = newViewProps.configuration.flashEnabled;
268
+ }
269
+
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
+ viewController.acceptedBarcodeTypes = [barcodeFormats copy];
280
+ }
281
+ }
282
+
283
+ if (forceUpdate || oldViewProps.configuration.engineMode != newViewProps.configuration.engineMode) {
284
+ viewController.engineMode = extractEngineMode(toNSString(newViewProps.configuration.engineMode));
285
+ }
286
+
287
+ if (forceUpdate || oldViewProps.configuration.cameraZoomFactor != newViewProps.configuration.cameraZoomFactor) {
288
+ if (!isUndefined(newViewProps.configuration.cameraZoomFactor)) {
289
+ if (newViewProps.configuration.cameraZoomFactor != _userDefinedCameraZoomFactor || _userDefinedCameraZoomFactor == -1) {
290
+ viewController.cameraZoomFactor = newViewProps.configuration.cameraZoomFactor;
291
+ _userDefinedCameraZoomFactor = newViewProps.configuration.cameraZoomFactor;
292
+ }
293
+ }
294
+ }
295
+
296
+ if (forceUpdate || oldViewProps.configuration.barcodeFilter != newViewProps.configuration.barcodeFilter) {
297
+ _barcodeFilter = extractBarcodeFilter(toNSString(newViewProps.configuration.barcodeFilter));
298
+ }
299
+ }
300
+
301
+ - (void)updateProps:(const facebook::react::Props::Shared &)props oldProps:(const facebook::react::Props::Shared &)oldProps {
302
+ const auto &newViewProps = *std::static_pointer_cast<RTNScanbotBarcodeCameraViewProps const>(props);
303
+
304
+ _configuration = newViewProps.configuration;
305
+
306
+ [self applyProps:props oldProps:oldProps forceUpdate:_isFirstLaunch];
307
+ _isFirstLaunch = false;
308
+
309
+ [super updateProps:props oldProps:oldProps];
310
+ }
311
+
312
+ - (void)componentDidMount {
313
+ _isFirstLaunch = true;
314
+ [self applyProps:_props oldProps:_props forceUpdate:_isFirstLaunch];
315
+ }
316
+ - (void)componentDidUpdate {}
317
+ - (void)componentWillUnmount {
318
+ [_cameraViewController removeFromParentViewController];
319
+ _cameraViewController = NULL;
320
+ }
321
+ - (void)orientationChanged {}
322
+
323
+ // MARK: - SBSDKBarcodeScannerViewControllerDelegate
324
+
325
+ - (void)barcodeScannerController:(SBSDKBarcodeScannerViewController *)controller
326
+ didDetectBarcodes:(NSArray<SBSDKBarcodeScannerResult *> *)codes
327
+ onImage:(nonnull UIImage *)image {
328
+
329
+ [self sendScanResults:codes onImage:image];
330
+ }
331
+
332
+ - (BOOL)barcodeScannerControllerShouldDetectBarcodes:(SBSDKBarcodeScannerViewController *)controller {
333
+ return true;
334
+ }
335
+
336
+ - (void)barcodeScannerController:(nonnull SBSDKBarcodeScannerViewController *)controller didDetectBarcodes:(nonnull NSArray<SBSDKBarcodeScannerResult *> *)codes {
337
+ [self sendScanResults:codes onImage:nil];
338
+ }
339
+
340
+
341
+ - (NSArray*)hashedBarcodes {
342
+ NSMutableArray* outArray = [[NSMutableArray alloc] init];
343
+ for (NSDictionary* barcode in self.barcodes) {
344
+ NSString* hash = [RTNScanbotBarcodeCameraView hashFromBarcode:barcode];
345
+ [outArray addObject:hash];
346
+ }
347
+ return outArray;
348
+ }
349
+
350
+ + (NSString*)hashFromBarcode: (NSDictionary* _Nonnull)barcode {
351
+ NSString* text = [barcode objectForKey:@"barcode"];
352
+ NSString* type = [barcode objectForKey:@"type"];
353
+ return [[NSString stringWithFormat:@"%@_%@", text, type] lowercaseString];
354
+ }
355
+
356
+ @end
357
+
358
+ Class<RCTComponentViewProtocol> RTNScanbotBarcodeCameraViewCls(void)
359
+ {
360
+ return RTNScanbotBarcodeCameraView.class;
361
+ }
362
+
363
+ #endif // ifdef RCT_NEW_ARCH_ENABLED
364
+
@@ -0,0 +1,71 @@
1
+ //
2
+ // RNScanbotBarcodeCameraViewManager.mm
3
+ // RNScanbotBarcodeSDK
4
+ //
5
+ // Created by Marco Saia on 28.08.23.
6
+ //
7
+
8
+ // We use this compilation pragma to expose this implementation for the NEW ARCHITECTURE only
9
+ #ifdef RCT_NEW_ARCH_ENABLED
10
+
11
+ #import <React/RCTLog.h>
12
+ #import <React/RCTUIManager.h>
13
+ #import <React/RCTViewManager.h>
14
+ #import <Foundation/Foundation.h>
15
+ #import "RTNScanbotBarcodeCameraView.h"
16
+
17
+ typedef void (^NativeViewBlock)(RTNScanbotBarcodeCameraView* _Nonnull);
18
+
19
+ @interface RTNScanbotBarcodeCameraViewManager : RCTViewManager
20
+ @end
21
+
22
+ @implementation RTNScanbotBarcodeCameraViewManager
23
+
24
+ RCT_EXPORT_MODULE(RTNScanbotBarcodeCameraView)
25
+ RCT_EXPORT_VIEW_PROPERTY(configuration, NSDictionary*)
26
+ RCT_EXPORT_VIEW_PROPERTY(onNativeBarcodeScannerResult, RCTDirectEventBlock);
27
+
28
+ // componentDidMount
29
+ RCT_EXPORT_METHOD(componentDidMount:(nonnull NSNumber*) reactTag) {
30
+ [self callNativeMethodWithReactTag: reactTag andBlock: ^void (RTNScanbotBarcodeCameraView* nativeView) {
31
+ [nativeView componentDidMount];
32
+ }];
33
+ }
34
+
35
+ // componentDidUpdate
36
+ RCT_EXPORT_METHOD(componentDidUpdate:(nonnull NSNumber*) reactTag) {
37
+ [self callNativeMethodWithReactTag: reactTag andBlock: ^void (RTNScanbotBarcodeCameraView* nativeView) {
38
+ [nativeView componentDidUpdate];
39
+ }];
40
+ }
41
+
42
+ // componentWillUnmount
43
+ RCT_EXPORT_METHOD(componentWillUnmount:(nonnull NSNumber*) reactTag) {
44
+ [self callNativeMethodWithReactTag: reactTag andBlock: ^void (RTNScanbotBarcodeCameraView* nativeView) {
45
+ [nativeView componentWillUnmount];
46
+ }];
47
+ }
48
+
49
+ // orientationChanged
50
+ RCT_EXPORT_METHOD(orientationChanged:(nonnull NSNumber*) reactTag) {
51
+ [self callNativeMethodWithReactTag: reactTag andBlock: ^void (RTNScanbotBarcodeCameraView* nativeView) {
52
+ [nativeView orientationChanged];
53
+ }];
54
+ }
55
+
56
+ - (void) callNativeMethodWithReactTag:(nonnull NSNumber*) reactTag andBlock:(NativeViewBlock)block {
57
+ [self.bridge.uiManager addUIBlock:^(RCTUIManager *uiManager, NSDictionary<NSNumber *,UIView *> *viewRegistry) {
58
+ RTNScanbotBarcodeCameraView* view = (RTNScanbotBarcodeCameraView*) viewRegistry[reactTag];
59
+ if (!view || ![view isKindOfClass:[RTNScanbotBarcodeCameraView class]]) {
60
+ RCTLogError(@"Cannot find native view with tag #%@", reactTag);
61
+ return;
62
+ }
63
+ block(view);
64
+ }];
65
+ }
66
+
67
+ @end
68
+
69
+
70
+
71
+ #endif
@@ -1,10 +1,13 @@
1
1
  //
2
- // RNScanbotCameraView.h
2
+ // RNScanbotBarcodeCameraView.h
3
3
  // RNScanbotSDK
4
4
  //
5
5
  // Created by Marco Saia on 18.05.21.
6
6
  //
7
7
 
8
+ // We use this compilation pragma to expose this implementation for the OLD ARCHITECTURE only
9
+ #ifndef RCT_NEW_ARCH_ENABLED
10
+
8
11
  #ifndef RNScanbotCameraView_h
9
12
  #define RNScanbotCameraView_h
10
13
 
@@ -15,7 +18,7 @@
15
18
 
16
19
  @property SBSDKBarcodeScannerViewController* _Nullable cameraViewController;
17
20
  @property NSMutableArray* _Nonnull barcodes;
18
- @property (nonatomic, copy) RCTBubblingEventBlock _Nullable onBarcodeScannerResult;
21
+ @property (nonatomic, copy) RCTBubblingEventBlock _Nullable onNativeBarcodeScannerResult;
19
22
  @property (nonatomic, copy) RCTBubblingEventBlock _Nullable requestComponentReload;
20
23
  @property (nonatomic) BOOL shouldUseFinderView;
21
24
  @property (nonatomic, copy) NSDictionary* _Nullable configuration;
@@ -58,3 +61,5 @@
58
61
  @end
59
62
 
60
63
  #endif /* RNScanbotCameraView_h */
64
+
65
+ #endif // ifndef RCT_NEW_ARCH_ENABLED
@@ -5,6 +5,9 @@
5
5
  // Created by Marco Saia on 18.05.21.
6
6
  //
7
7
 
8
+ // We use this compilation pragma to expose this implementation for the OLD ARCHITECTURE only
9
+ #ifndef RCT_NEW_ARCH_ENABLED
10
+
8
11
  #import "RNScanbotBarcodeCameraView.h"
9
12
  #import "ObjectMapper.h"
10
13
  #import "BarcodeMapping.h"
@@ -70,7 +73,7 @@
70
73
  }
71
74
 
72
75
  if ([config objectForKey:@"barcodeFilter"]) {
73
- cameraViewConfiguration.barcodeFilter = extractBarcodeFilter(config);
76
+ cameraViewConfiguration.barcodeFilter = extractBarcodeFilterFromConfiguration(config);
74
77
  [config removeObjectForKey:@"barcodeFilter"];
75
78
  }
76
79
 
@@ -82,8 +85,8 @@
82
85
  }
83
86
 
84
87
  // We also need to manually extract the MSI-Plessey Checksum Algorithm since it can't be mapped automatically
85
- cameraViewConfiguration.msiPlesseyChecksumAlgorithm = extractPlesseyChecksumAlgorithmFromConfiguration(configuration);
86
- cameraViewConfiguration.codeDensity = extractBarcodeDensity(config);
88
+ cameraViewConfiguration.msiPlesseyChecksumAlgorithm = extractMsiPlesseyChecksumAlgorithmFromConfiguration(configuration);
89
+ cameraViewConfiguration.codeDensity = extractBarcodeDensityFromConfiguration(config);
87
90
  cameraViewConfiguration.finderInset = [self populateFinderInset:config];
88
91
 
89
92
  self.shouldUseFinderView = [[config objectForKey:@"shouldUseFinderView"] boolValue];
@@ -193,7 +196,7 @@
193
196
  }
194
197
 
195
198
  - (void)sendScanResults:(NSArray<SBSDKBarcodeScannerResult*>*) results onImage:(UIImage*)image {
196
- if(!self.onBarcodeScannerResult) {
199
+ if(!self.onNativeBarcodeScannerResult) {
197
200
  return;
198
201
  }
199
202
 
@@ -212,7 +215,7 @@
212
215
  }
213
216
  };
214
217
 
215
- self.onBarcodeScannerResult(outResult);
218
+ self.onNativeBarcodeScannerResult(outResult);
216
219
  }
217
220
 
218
221
  // MARK: - React Native Lifecycle
@@ -282,3 +285,6 @@
282
285
  }
283
286
 
284
287
  @end
288
+
289
+ #endif // ifndef RCT_NEW_ARCH_ENABLED
290
+
@@ -1,10 +1,13 @@
1
1
  //
2
- // RNScanbotClassicComponents.h
2
+ // RNScanbotBarcodeCameraViewManager.h
3
3
  // Pods
4
4
  //
5
5
  // Created by Marco Saia on 17.05.21.
6
6
  //
7
7
 
8
+ // We use this compilation pragma to expose this implementation for the OLD ARCHITECTURE only
9
+ #ifndef RCT_NEW_ARCH_ENABLED
10
+
8
11
  #ifndef RNScanbotClassicComponents_h
9
12
  #define RNScanbotClassicComponents_h
10
13
 
@@ -20,3 +23,5 @@ typedef void (^NativeViewBlock)(RNScanbotBarcodeCameraView* _Nonnull);
20
23
  @end
21
24
 
22
25
  #endif /* RNScanbotClassicComponents_h */
26
+
27
+ #endif // ifndef RCT_NEW_ARCH_ENABLED
@@ -1,10 +1,13 @@
1
1
  //
2
- // RNScanbotClassicComponents.m
2
+ // RNScanbotBarcodeCameraViewManager.m
3
3
  // RNScanbotSDK
4
4
  //
5
5
  // Created by Marco Saia on 17.05.21.
6
6
  //
7
7
 
8
+ // We use this compilation pragma to expose this implementation for the OLD ARCHITECTURE only
9
+ #ifndef RCT_NEW_ARCH_ENABLED
10
+
8
11
  #import <Foundation/Foundation.h>
9
12
  #import "RNScanbotBarcodeCameraViewManager.h"
10
13
  #import "RNScanbotBarcodeCameraView.h"
@@ -16,9 +19,9 @@
16
19
 
17
20
  @implementation RNScanbotBarcodeCameraViewManager
18
21
 
19
- RCT_EXPORT_MODULE(ScanbotBarcodeCameraView)
22
+ RCT_EXPORT_MODULE(RTNScanbotBarcodeCameraView)
20
23
 
21
- RCT_EXPORT_VIEW_PROPERTY(onBarcodeScannerResult, RCTBubblingEventBlock)
24
+ RCT_EXPORT_VIEW_PROPERTY(onNativeBarcodeScannerResult, RCTBubblingEventBlock)
22
25
  RCT_EXPORT_VIEW_PROPERTY(requestComponentReload, RCTBubblingEventBlock)
23
26
  RCT_EXPORT_VIEW_PROPERTY(shouldUseFinderView, BOOL)
24
27
  RCT_EXPORT_VIEW_PROPERTY(configuration, NSDictionary*)
@@ -69,3 +72,5 @@ RCT_EXPORT_METHOD(orientationChanged:(nonnull NSNumber*) reactTag) {
69
72
  }
70
73
 
71
74
  @end
75
+
76
+ #endif // ifndef RCT_NEW_ARCH_ENABLED
@@ -5,7 +5,7 @@
5
5
  // https://scanbot.io/sdk
6
6
  //
7
7
  #import <React/RCTBridgeModule.h>
8
- @import ScanbotBarcodeScannerSDK;
8
+ #import <ScanbotBarcodeScannerSDK/ScanbotBarcodeScannerSDK.h>
9
9
 
10
10
  @interface ScanbotBarcodeSdk : NSObject <RCTBridgeModule>
11
11
 
@@ -136,7 +136,7 @@ RCT_EXPORT_METHOD(startBarcodeScanner:(NSDictionary*)configuration
136
136
  }
137
137
 
138
138
  // Barcode Filter (at the moment used for UPC Extension filters)
139
- SBSDKUIBarcodeFilter* barcodeFilter = extractBarcodeFilter(configuration);
139
+ SBSDKUIBarcodeFilter* barcodeFilter = extractBarcodeFilterFromConfiguration(configuration);
140
140
  if (barcodeFilter != nil) {
141
141
  behaviorConfig.barcodeFilter = barcodeFilter;
142
142
  }
@@ -144,7 +144,7 @@ RCT_EXPORT_METHOD(startBarcodeScanner:(NSDictionary*)configuration
144
144
  behaviorConfig.additionalParameters = extractAdditionalParameters(configuration);
145
145
  behaviorConfig.acceptedDocumentTypes = extractBarcodeDocumentTypesFromConfiguration(configuration);
146
146
  behaviorConfig.acceptedMachineCodeTypes = extractBarcodeTypesFromConfiguration(configuration);
147
- behaviorConfig.engineMode = extractEngineMode(configuration);
147
+ behaviorConfig.engineMode = extractEngineModeFromConfiguration(configuration);
148
148
 
149
149
  uiConfig.orientationLockMode = [ObjectMapper extractOrientationLockMode:configuration];
150
150
 
@@ -194,7 +194,7 @@ RCT_EXPORT_METHOD(startBatchBarcodeScanner:(NSDictionary*)configuration
194
194
  }
195
195
 
196
196
  // Barcode Filter (at the moment used for UPC Extension filters)
197
- SBSDKUIBarcodeFilter* barcodeFilter = extractBarcodeFilter(configuration);
197
+ SBSDKUIBarcodeFilter* barcodeFilter = extractBarcodeFilterFromConfiguration(configuration);
198
198
  if (barcodeFilter != nil) {
199
199
  behaviorConfig.barcodeFilter = barcodeFilter;
200
200
  }
@@ -202,7 +202,7 @@ RCT_EXPORT_METHOD(startBatchBarcodeScanner:(NSDictionary*)configuration
202
202
  behaviorConfig.additionalDetectionParameters = extractAdditionalParameters(configuration);
203
203
  behaviorConfig.acceptedDocumentTypes = extractBarcodeDocumentTypesFromConfiguration(configuration);;
204
204
  behaviorConfig.acceptedMachineCodeTypes = extractBarcodeTypesFromConfiguration(configuration);
205
- behaviorConfig.engineMode = extractEngineMode(configuration);
205
+ behaviorConfig.engineMode = extractEngineModeFromConfiguration(configuration);
206
206
 
207
207
  uiConfig.orientationLockMode = [ObjectMapper extractOrientationLockMode:configuration];
208
208
 
@@ -253,7 +253,7 @@ RCT_EXPORT_METHOD(detectBarcodesOnImage:(NSDictionary *)configuration
253
253
  NSArray* barcodeDocumentTypes = extractBarcodeDocumentTypesFromConfiguration(configuration);
254
254
  [barcodeScanner setAcceptedDocumentTypes: barcodeDocumentTypes];
255
255
 
256
- SBSDKBarcodeEngineMode engineMode = extractEngineMode(configuration);
256
+ SBSDKBarcodeEngineMode engineMode = extractEngineModeFromConfiguration(configuration);
257
257
  [barcodeScanner setEngineMode:engineMode];
258
258
 
259
259
  SBSDKBarcodeAdditionalParameters* additionalParameters = extractAdditionalParameters(configuration);
@@ -267,7 +267,7 @@ RCT_EXPORT_METHOD(detectBarcodesOnImage:(NSDictionary *)configuration
267
267
  NSArray<SBSDKBarcodeScannerResult *> *barcodeResults = [barcodeScanner detectBarCodesOnImage:image];
268
268
 
269
269
  if (barcodeResults) {
270
- SBSDKUIBarcodeFilter* barcodeFilter = extractBarcodeFilter(configuration);
270
+ SBSDKUIBarcodeFilter* barcodeFilter = extractBarcodeFilterFromConfiguration(configuration);
271
271
  if (barcodeFilter != nil) {
272
272
  barcodeResults = filterBarcodeResults(barcodeResults, barcodeFilter);
273
273
  }
@@ -9,7 +9,7 @@
9
9
  #import "UIColor+JSON.h"
10
10
  #include "ScanbotStorageUtils.h"
11
11
  #include "ReactBarcodeExtensionsFilter.h"
12
- @import ScanbotBarcodeScannerSDK;
12
+ #import <ScanbotBarcodeScannerSDK/ScanbotBarcodeScannerSDK.h>
13
13
 
14
14
  static inline SBSDKBarcodeType* barcodeTypeFromString(NSString* string) {
15
15
  if ([string isEqualToString:@"AZTEC"]) return SBSDKBarcodeTypeAztec;
@@ -101,9 +101,7 @@ static inline NSArray<NSDictionary<NSString*, NSObject*>*>* jsonFromMappedBarcod
101
101
  return [jsonResults copy];
102
102
  }
103
103
 
104
- static inline SBSDKBarcodeMSIPlesseyChecksumAlgorithm extractPlesseyChecksumAlgorithmFromConfiguration(NSDictionary* configuration) {
105
- NSString* algorithm = [configuration objectForKey:@"msiPlesseyChecksumAlgorithm"];
106
-
104
+ static inline SBSDKBarcodeMSIPlesseyChecksumAlgorithm extractMsiPlesseyChecksumAlgorithm(NSString* algorithm) {
107
105
  if (algorithm != nil) {
108
106
  if ([algorithm isEqualToString:@"None"]) return SBSDKBarcodeMSIPlesseyChecksumAlgorithmNone;
109
107
  if ([algorithm isEqualToString:@"Mod10"]) return SBSDKBarcodeMSIPlesseyChecksumAlgorithmMod10;
@@ -113,27 +111,35 @@ static inline SBSDKBarcodeMSIPlesseyChecksumAlgorithm extractPlesseyChecksumAlgo
113
111
  if ([algorithm isEqualToString:@"Mod1110IBM"]) return SBSDKBarcodeMSIPlesseyChecksumAlgorithmMod1110IBM;
114
112
  if ([algorithm isEqualToString:@"Mod1110NCR"]) return SBSDKBarcodeMSIPlesseyChecksumAlgorithmMod1110NCR;
115
113
  }
116
-
114
+
117
115
  return SBSDKBarcodeMSIPlesseyChecksumAlgorithmMod10;
118
116
  }
119
117
 
120
- static inline SBSDKUIBarcodeFilter* extractBarcodeFilter(NSDictionary* configuration) {
121
- NSString* jsonFilterType = [configuration objectForKey:@"barcodeFilter"];
122
- if (jsonFilterType == nil) {
123
- return nil;
124
- }
125
-
126
- if ([jsonFilterType isEqualToString:@"WithExtension"]) {
118
+ static inline SBSDKBarcodeMSIPlesseyChecksumAlgorithm extractMsiPlesseyChecksumAlgorithmFromConfiguration(NSDictionary* configuration) {
119
+ return extractMsiPlesseyChecksumAlgorithm((NSString*)[configuration objectForKey:@"msiPlesseyChecksumAlgorithm"]);
120
+ }
121
+
122
+ static inline SBSDKUIBarcodeFilter* extractBarcodeFilter(NSString* barcodeFilter) {
123
+ if ([barcodeFilter isEqualToString:@"WithExtension"]) {
127
124
  return [[ReactBarcodeExtensionsFilter alloc] init:ReactBarcodeExtensionsFilterWithExtension];
128
- } else if ([jsonFilterType isEqualToString:@"WithEAN2Extension"]) {
125
+ } else if ([barcodeFilter isEqualToString:@"WithEAN2Extension"]) {
129
126
  return [[ReactBarcodeExtensionsFilter alloc] init:ReactBarcodeExtensionsFilterWithEAN2Extension];
130
- } else if ([jsonFilterType isEqualToString:@"WithEAN5Extension"]) {
127
+ } else if ([barcodeFilter isEqualToString:@"WithEAN5Extension"]) {
131
128
  return [[ReactBarcodeExtensionsFilter alloc] init:ReactBarcodeExtensionsFilterWithEAN5Extension];
132
129
  }
133
130
 
134
131
  return nil;
135
132
  }
136
133
 
134
+ static inline SBSDKUIBarcodeFilter* extractBarcodeFilterFromConfiguration(NSDictionary* configuration) {
135
+ NSString* jsonFilterType = [configuration objectForKey:@"barcodeFilter"];
136
+ if (jsonFilterType == nil) {
137
+ return nil;
138
+ }
139
+
140
+ return extractBarcodeFilter(jsonFilterType);
141
+ }
142
+
137
143
  static inline NSArray* filterBarcodeResults(NSArray<SBSDKBarcodeScannerResult *>* barcodeResults, SBSDKUIBarcodeFilter* filter) {
138
144
  NSMutableArray<SBSDKBarcodeScannerResult *>* outResults = [[NSMutableArray alloc] init];
139
145
 
@@ -181,29 +187,30 @@ static inline NSArray* extractBarcodeDocumentTypesFromConfiguration(NSDictionary
181
187
  return nil;
182
188
  }
183
189
 
184
- static inline SBSDKBarcodeDensity extractBarcodeDensity(NSDictionary* configuration) {
185
- SBSDKBarcodeDensity barcodeDensity = SBSDKBarcodeDensityLow;
186
-
187
- NSString* codeDensity = [configuration objectForKey:@"codeDensity"];
188
- if (codeDensity != nil) {
189
- if([codeDensity isEqualToString:@"HIGH"]) {
190
- barcodeDensity = SBSDKBarcodeDensityHigh;
191
- }
190
+ static inline SBSDKBarcodeDensity extractBarcodeDensity(NSString* value) {
191
+ if (value != nil && [value isEqualToString:@"HIGH"]) {
192
+ return SBSDKBarcodeDensityHigh;
192
193
  }
193
-
194
- return barcodeDensity;
194
+
195
+ return SBSDKBarcodeDensityLow;
195
196
  }
196
197
 
197
- static inline SBSDKBarcodeEngineMode extractEngineMode(NSDictionary* configuration) {
198
- NSString* mode = [configuration objectForKey:@"engineMode"];
199
-
200
- if (mode && [@"LEGACY" isEqualToString:mode]) {
198
+ static inline SBSDKBarcodeDensity extractBarcodeDensityFromConfiguration(NSDictionary* configuration) {
199
+ return extractBarcodeDensity((NSString*)[configuration objectForKey:@"codeDensity"]);
200
+ }
201
+
202
+ static inline SBSDKBarcodeEngineMode extractEngineMode(NSString* value) {
203
+ if (value && [@"LEGACY" isEqualToString:value]) {
201
204
  return SBSDKBarcodeEngineModeLegacy;
202
205
  }
203
206
 
204
207
  return SBSDKBarcodeEngineModeNextGen;
205
208
  }
206
209
 
210
+ static inline SBSDKBarcodeEngineMode extractEngineModeFromConfiguration(NSDictionary* configuration) {
211
+ return extractEngineMode((NSString*)[configuration objectForKey:@"engineMode"]);
212
+ }
213
+
207
214
  static inline SBSDKBarcodeAdditionalParameters* extractAdditionalParameters(NSDictionary* configuration) {
208
215
  SBSDKBarcodeAdditionalParameters* additionalParameters = [[SBSDKBarcodeAdditionalParameters alloc] init];
209
216
  @try {
@@ -221,9 +228,9 @@ static inline SBSDKBarcodeAdditionalParameters* extractAdditionalParameters(NSDi
221
228
  }
222
229
 
223
230
  // We also need to manually extract the MSI-Plessey Checksum Algorithm since it can't be mapped automatically
224
- additionalParameters.msiPlesseyChecksumAlgorithm = extractPlesseyChecksumAlgorithmFromConfiguration(configuration);
231
+ additionalParameters.msiPlesseyChecksumAlgorithm = extractMsiPlesseyChecksumAlgorithmFromConfiguration(configuration);
225
232
 
226
- additionalParameters.codeDensity = extractBarcodeDensity(configuration);
233
+ additionalParameters.codeDensity = extractBarcodeDensityFromConfiguration(configuration);
227
234
 
228
235
  return additionalParameters;
229
236
  }
@@ -6,7 +6,7 @@
6
6
  //
7
7
 
8
8
  #import <Foundation/Foundation.h>
9
- @import ScanbotBarcodeScannerSDK;
9
+ #import <ScanbotBarcodeScannerSDK/ScanbotBarcodeScannerSDK.h>
10
10
 
11
11
  typedef enum BarcodeFilterType : NSUInteger {
12
12
  ReactBarcodeExtensionsFilterWithExtension,
@@ -1,9 +1,34 @@
1
1
  import { ComponentType } from 'react';
2
2
  import type {HostComponent, ViewProps} from 'react-native';
3
- import { DirectEventHandler, Float, Int32 } from 'react-native/Libraries/Types/CodegenTypes';
3
+ import { BubblingEventHandler, DirectEventHandler, Float, Int32 } from 'react-native/Libraries/Types/CodegenTypes';
4
4
  import codegenNativeCommands from 'react-native/Libraries/Utilities/codegenNativeCommands';
5
5
  import codegenNativeComponent from 'react-native/Libraries/Utilities/codegenNativeComponent';
6
6
 
7
+ export interface NativeBarcodeResult {
8
+ status: string;
9
+ barcodes: Readonly<{
10
+ /*
11
+ * The barcode format.
12
+ */
13
+ type: string;
14
+
15
+ /**
16
+ * The raw text encoded in the barcode.
17
+ */
18
+ text: string;
19
+
20
+ /**
21
+ * The raw text encoded in the barcode that also includes the extension, if detected
22
+ */
23
+ textWithExtension: string;
24
+
25
+ /**
26
+ * The array of raw bytes contained in the barcode.
27
+ */
28
+ rawBytes: Int32[];
29
+ }[]>;
30
+ }
31
+
7
32
  export interface NativeProps extends ViewProps {
8
33
  configuration?: ScanbotBarcodeCameraViewConfiguration;
9
34
  // Lifecycle methods
@@ -11,6 +36,7 @@ export interface NativeProps extends ViewProps {
11
36
  onComponentDidMount: DirectEventHandler<Readonly<{}>>;
12
37
  onComponentWillUnmount: DirectEventHandler<Readonly<{}>>;
13
38
  onOrientationChanged: DirectEventHandler<Readonly<{}>>;
39
+ onNativeBarcodeScannerResult: BubblingEventHandler<Readonly<{jsonResult: string}>>;
14
40
  }
15
41
 
16
42
  export default codegenNativeComponent<NativeProps>(
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.6.1-alpha.1",
4
+ "version": "3.6.1-alpha.2",
5
5
  "scanbot": {
6
6
  "iosVersion": "3.6.0"
7
7
  },
@@ -71,11 +71,11 @@
71
71
  ],
72
72
  "react-native": "index",
73
73
  "codegenConfig": {
74
- "name": "RTNScanbotBarcodeSdkSpec",
75
- "type": "modules",
74
+ "name": "RTNScanbotBarcodeCameraViewSpecs",
75
+ "type": "components",
76
76
  "jsSrcsDir": "js",
77
77
  "android": {
78
78
  "javaPackageName": "io.scanbot.barcodesdk.plugin.reactnative"
79
79
  }
80
- }
80
+ }
81
81
  }
@@ -12,10 +12,17 @@ import { BarcodeAdditionalParameters } from '../../configuration';
12
12
 
13
13
  export interface ScanbotBarcodeCameraViewProperties {
14
14
  onBarcodeScannerResult?: (result: BarcodeResult) => void;
15
+ configuration?: ScanbotBarcodeCameraViewConfiguration;
16
+ style: StyleProp<ViewStyle>;
17
+ children?: React.ReactNode;
18
+ }
19
+
20
+ export interface ScanbotBarcodeCameraNativeViewProperties {
21
+ onNativeBarcodeScannerResult?: (result: BarcodeResult) => void;
15
22
  requestComponentReload?: () => void;
16
23
  configuration?: ScanbotBarcodeCameraViewConfiguration;
17
24
  style: StyleProp<ViewStyle>;
18
- children: React.ReactNode;
25
+ children?: React.ReactNode;
19
26
  }
20
27
 
21
28
  export interface ScanbotBarcodeCameraViewBarcode {
@@ -1,8 +1,9 @@
1
1
  import React from 'react';
2
2
  import { EmitterSubscription, findNodeHandle, NativeMethods, Platform, UIManager } from 'react-native';
3
3
  import { Dimensions } from 'react-native';
4
- import { ScanbotBarcodeCameraViewProperties } from './scanbot-barcode-camera-view-types';
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
7
 
7
8
  const Device = {
8
9
  isPortrait: () => {
@@ -23,7 +24,7 @@ type Properties = ScanbotBarcodeCameraViewProperties;
23
24
  export class ScanbotBarcodeCameraView extends React.Component<Properties, {}> {
24
25
 
25
26
  // Camera View Reference
26
- cameraViewReference: React.RefObject<React.Component<ScanbotBarcodeCameraViewProperties> & Readonly<NativeMethods>>
27
+ cameraViewReference: React.RefObject<React.Component<ScanbotBarcodeCameraNativeViewProperties> & Readonly<NativeMethods>>
27
28
 
28
29
  // String length of auto-generated component key
29
30
  static UNIQUE_VIEW_KEY_LENGTH = 6;
@@ -93,13 +94,30 @@ export class ScanbotBarcodeCameraView extends React.Component<Properties, {}> {
93
94
  });
94
95
  };
95
96
 
97
+ receiveEvent(event: any) {}
98
+
96
99
  // Maps the native bridge callback event from the Barcode Scanner
97
100
  _onBarcodeScannerResult = (event: any) => {
98
101
  if (!this.props.onBarcodeScannerResult) {
99
102
  return;
100
103
  }
101
104
 
102
- this.props.onBarcodeScannerResult(event.nativeEvent.result);
105
+ let outResult: BarcodeResult | undefined = undefined;
106
+ if (Platform.OS === 'ios') {
107
+ // The new-architecture Fabric Component callback returns a JSON string as a result
108
+ if (event.nativeEvent.jsonResult) {
109
+ outResult = JSON.parse(event.nativeEvent.jsonResult)?.result;
110
+ } else {
111
+ // Support for the old architecture
112
+ outResult = event.nativeEvent.result;
113
+ }
114
+ } else {
115
+ outResult = event.nativeEvent.result;
116
+ }
117
+
118
+ if (outResult) {
119
+ this.props.onBarcodeScannerResult(outResult);
120
+ }
103
121
  };
104
122
 
105
123
  render() {
@@ -115,7 +133,7 @@ export class ScanbotBarcodeCameraView extends React.Component<Properties, {}> {
115
133
  style={style}
116
134
  key={this.cameraKey}
117
135
  ref={this.cameraViewReference}
118
- onBarcodeScannerResult={this._onBarcodeScannerResult}
136
+ onNativeBarcodeScannerResult={this._onBarcodeScannerResult}
119
137
  />
120
138
  );
121
139
  }
@@ -170,10 +188,28 @@ export class ScanbotBarcodeCameraView extends React.Component<Properties, {}> {
170
188
  return newStyle;
171
189
  };
172
190
 
191
+ sanitizeNumbers = (obj: ScanbotBarcodeCameraViewConfiguration) => {
192
+ const outObj = {...obj};
193
+ outObj.cameraZoomFactor = obj.cameraZoomFactor ?? -1;
194
+ outObj.finderAspectRatio = obj.finderAspectRatio ?? { width: -1, height: -1 };
195
+ outObj.finderBackgroundOpacity = obj.finderBackgroundOpacity ?? -1;
196
+ outObj.finderInset = obj.finderInset ?? { left: -1, top: -1, right: -1, bottom: -1};
197
+ outObj.finderLineWidth = obj.finderLineWidth ?? -1;
198
+ outObj.maximumTextLength = obj.maximumTextLength ?? -1;
199
+ outObj.minimumTextLength = obj.minimumTextLength ?? -1;
200
+ outObj.minimum1DBarcodesQuietZone = obj.minimum1DBarcodesQuietZone ?? -1;
201
+ return outObj;
202
+ }
203
+
173
204
  preprocessProps = () => {
174
205
  const props = { ...this.props };
175
206
  delete props.style;
176
207
 
208
+ const config = props.configuration;
209
+ if (config != undefined && config != null) {
210
+ props.configuration = this.sanitizeNumbers(config as any);
211
+ }
212
+
177
213
  return props;
178
214
  };
179
215
 
@@ -216,16 +252,9 @@ export class ScanbotBarcodeCameraView extends React.Component<Properties, {}> {
216
252
  }
217
253
 
218
254
  sendCommandToViewId = (viewId: number, command: string, args: any = []) => {
219
- let commandId: number
220
- if (Platform.OS == 'android') {
221
- const cameraView = this.cameraViewReference?.current;
222
- if (cameraView) {
223
- Commands[command](cameraView);
224
- }
225
- return;
226
- } else {
227
- commandId = UIManager.getViewManagerConfig('ScanbotBarcodeCameraView').Commands[command];
228
- }
229
- UIManager.dispatchViewManagerCommand(viewId, commandId, args);
255
+ const cameraView = this.cameraViewReference?.current;
256
+ if (cameraView) {
257
+ Commands[command](cameraView);
258
+ }
230
259
  }
231
260
  }
@@ -1,8 +1,8 @@
1
1
  import { HostComponent } from "react-native";
2
- import { ScanbotBarcodeCameraViewProperties } from "./scanbot-barcode-camera-view-types";
2
+ import { ScanbotBarcodeCameraNativeViewProperties } from "./scanbot-barcode-camera-view-types";
3
3
 
4
4
  const nativeBarcodeCameraView = require('../../../js/RTNScanbotBarcodeCameraViewNativeComponent').default;
5
5
  const nativeBarcodeCameraViewCommands = require('../../../js/RTNScanbotBarcodeCameraViewNativeComponent').Commands;
6
6
 
7
- export default (nativeBarcodeCameraView as HostComponent<ScanbotBarcodeCameraViewProperties>);
7
+ export default (nativeBarcodeCameraView as HostComponent<ScanbotBarcodeCameraNativeViewProperties>);
8
8
  export const Commands = nativeBarcodeCameraViewCommands;