react-native-scanbot-barcode-scanner-sdk 4.2.0 → 4.3.0-beta.1

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 (64) hide show
  1. package/Libraries.txt +31 -31
  2. package/RNScanbotBarcodeSDK.podspec +1 -4
  3. package/android/build.gradle +6 -5
  4. package/android/src/main/java/io/scanbot/barcodesdk/plugin/reactnative/ScanbotBarcodeSdkPackage.kt +9 -7
  5. package/android/src/main/java/io/scanbot/barcodesdk/plugin/reactnative/components/barcode_scanner_view/ScanbotBarcodeScannerView.kt +114 -0
  6. package/android/src/main/java/io/scanbot/barcodesdk/plugin/reactnative/components/barcode_scanner_view/ScanbotBarcodeScannerViewEvents.kt +56 -0
  7. package/android/src/main/java/io/scanbot/barcodesdk/plugin/reactnative/components/barcode_scanner_view/ScanbotBarcodeScannerViewManager.kt +256 -0
  8. package/android/src/main/java/io/scanbot/barcodesdk/plugin/reactnative/extensions/JSONObject.kt +18 -2
  9. package/android/src/main/java/io/scanbot/barcodesdk/plugin/reactnative/extensions/ReadableMap.kt +3 -4
  10. package/android/src/newarch/ScanbotBarcodeScannerViewManagerSpec.kt +19 -0
  11. package/android/src/oldarch/ScanbotBarcodeScannerViewManagerSpec.kt +29 -0
  12. package/dist/components/barcode-camera-view/ScanbotBarcodeCameraView.d.ts +3 -0
  13. package/dist/components/barcode-camera-view/ScanbotBarcodeCameraView.js +122 -0
  14. package/dist/components/barcode-camera-view/ScanbotBarcodeCameraViewProperties.d.ts +89 -0
  15. package/dist/components/barcode-camera-view/ScanbotBarcodeCameraViewProperties.js +2 -0
  16. package/dist/components/spec/ScanbotBarcodeScannerViewNativeComponent.d.ts +54 -0
  17. package/dist/components/spec/ScanbotBarcodeScannerViewNativeComponent.js +12 -0
  18. package/dist/configurations.d.ts +241 -0
  19. package/dist/configurations.js +2 -0
  20. package/dist/customConfigurations.d.ts +94 -0
  21. package/dist/customConfigurations.js +2 -0
  22. package/dist/customResults.d.ts +5 -0
  23. package/dist/customResults.js +2 -0
  24. package/dist/customTypes.d.ts +7 -0
  25. package/dist/customTypes.js +2 -0
  26. package/dist/index.d.ts +26 -0
  27. package/dist/index.js +34 -0
  28. package/dist/results.d.ts +29 -0
  29. package/dist/results.js +2 -0
  30. package/dist/types.d.ts +1194 -0
  31. package/dist/types.js +2 -0
  32. package/ios/Components/BarcodeScannerView/RNScanbotBarcodeScannerLegacyView.h +25 -0
  33. package/ios/Components/BarcodeScannerView/RNScanbotBarcodeScannerLegacyView.m +194 -0
  34. package/ios/Components/BarcodeScannerView/RNScanbotBarcodeScannerView.h +20 -0
  35. package/ios/Components/BarcodeScannerView/RNScanbotBarcodeScannerView.mm +259 -0
  36. package/ios/Components/BarcodeScannerView/RNScanbotBarcodeScannerViewControllerWrapper.h +99 -0
  37. package/ios/Components/BarcodeScannerView/RNScanbotBarcodeScannerViewControllerWrapper.m +196 -0
  38. package/ios/Components/BarcodeScannerView/RNScanbotBarcodeScannerViewManager.mm +73 -0
  39. package/package.json +16 -21
  40. package/src/components/barcode-camera-view/ScanbotBarcodeCameraView.tsx +112 -0
  41. package/src/components/barcode-camera-view/ScanbotBarcodeCameraViewProperties.ts +106 -0
  42. package/src/components/spec/ScanbotBarcodeScannerViewNativeComponent.ts +59 -0
  43. package/src/index.ts +58 -0
  44. package/android/src/main/java/io/scanbot/barcodesdk/plugin/reactnative/components/barcodecameraview/ScanbotBarcodeCameraView.java +0 -401
  45. package/android/src/main/java/io/scanbot/barcodesdk/plugin/reactnative/components/base/communication/ScanbotEventEmitter.java +0 -78
  46. package/android/src/main/java/io/scanbot/barcodesdk/plugin/reactnative/components/base/communication/ScanbotEventReceiver.java +0 -119
  47. package/android/src/main/java/io/scanbot/barcodesdk/plugin/reactnative/components/base/ui/ScanbotViewWrapper.java +0 -26
  48. package/android/src/main/java/io/scanbot/barcodesdk/plugin/reactnative/utils/JSONUtils.kt +0 -24
  49. package/android/src/main/java/io/scanbot/barcodesdk/plugin/reactnative/utils/ScanbotViewUtils.java +0 -43
  50. package/android/src/new-architecture/io/scanbot/barcodesdk/plugin/reactnative/components/barcodecameraview/ScanbotBarcodeCameraViewManager.java +0 -125
  51. package/android/src/old-architecture/io/scanbot/barcodesdk/plugin/reactnative/components/barcodecameraview/ScanbotBarcodeCameraViewManager.java +0 -114
  52. package/index.d.ts +0 -42
  53. package/index.js +0 -20
  54. package/ios/Components/BarcodeCameraView/NewArchitecture/RTNScanbotBarcodeCameraView.h +0 -44
  55. package/ios/Components/BarcodeCameraView/NewArchitecture/RTNScanbotBarcodeCameraView.mm +0 -338
  56. package/ios/Components/BarcodeCameraView/NewArchitecture/RTNScanbotBarcodeCameraViewManager.mm +0 -71
  57. package/ios/Components/BarcodeCameraView/OldArchitecture/RNScanbotBarcodeCameraView.h +0 -36
  58. package/ios/Components/BarcodeCameraView/OldArchitecture/RNScanbotBarcodeCameraView.mm +0 -181
  59. package/ios/Components/BarcodeCameraView/OldArchitecture/RNScanbotBarcodeCameraViewManager.h +0 -28
  60. package/ios/Components/BarcodeCameraView/OldArchitecture/RNScanbotBarcodeCameraViewManager.mm +0 -89
  61. package/js/RTNScanbotBarcodeCameraViewNativeComponent.ts +0 -186
  62. package/src/components/barcode-camera-view/scanbot-barcode-camera-view-types.ts +0 -175
  63. package/src/components/barcode-camera-view/scanbot-barcode-camera-view.tsx +0 -270
  64. package/src/components/barcode-camera-view/scanbot-native-barcode-camera-view.ts +0 -7
@@ -0,0 +1,196 @@
1
+ //
2
+ // RNScanbotBarcodeScannerViewHandler.m
3
+ // RNScanbotBarcodeSDK
4
+ //
5
+ // Created by Stefan Krzhovski on 27.05.24.
6
+ //
7
+
8
+ #import <Foundation/Foundation.h>
9
+ #import "RNScanbotBarcodeScannerViewControllerWrapper.h"
10
+
11
+
12
+ @implementation RNScanbotBarcodeScannerViewControllerWrapper
13
+
14
+ + hexStringToColor:(NSString *)hexString
15
+ {
16
+
17
+ if ([hexString hasPrefix:@"#"]) {
18
+ hexString = [hexString substringFromIndex:1];
19
+ } else {
20
+ return nil;
21
+ }
22
+
23
+ NSUInteger length = [hexString length];
24
+ if (length != 6 && length != 8) {
25
+ return nil;
26
+ }
27
+
28
+ unsigned int red, green, blue, alpha = 255;
29
+ NSString *redString = [hexString substringWithRange:NSMakeRange(0, 2)];
30
+ NSString *greenString = [hexString substringWithRange:NSMakeRange(2, 2)];
31
+ NSString *blueString = [hexString substringWithRange:NSMakeRange(4, 2)];
32
+
33
+ if (length == 8) {
34
+ NSString *alphaString = [hexString substringWithRange:NSMakeRange(6, 2)];
35
+ [[NSScanner scannerWithString:alphaString] scanHexInt:&alpha];
36
+ }
37
+
38
+ [[NSScanner scannerWithString:redString] scanHexInt:&red];
39
+ [[NSScanner scannerWithString:greenString] scanHexInt:&green];
40
+ [[NSScanner scannerWithString:blueString] scanHexInt:&blue];
41
+
42
+ return [UIColor colorWithRed:(CGFloat)red/255.0
43
+ green:(CGFloat)green/255.0
44
+ blue:(CGFloat)blue/255.0
45
+ alpha:(CGFloat)alpha/255.0];
46
+ }
47
+
48
+ + (SBSDKBarcodeScannerViewController *)initController {
49
+
50
+ SBSDKBarcodeScannerViewController *scannerViewController = [[SBSDKBarcodeScannerViewController alloc] init];
51
+ scannerViewController.viewFinderConfiguration = [SBSDKBaseScannerViewFinderConfiguration defaultConfiguration];
52
+ scannerViewController.generalConfiguration = [SBSDKBaseScannerGeneralConfiguration defaultConfiguration];
53
+ scannerViewController.zoomConfiguration = [SBSDKBaseScannerZoomConfiguration defaultConfiguration];
54
+ scannerViewController.energyConfiguration = [SBSDKBaseScannerEnergyConfiguration defaultConfiguration];
55
+
56
+ return scannerViewController;
57
+ }
58
+
59
+ + (void)setFlashEnabled:(SBSDKBarcodeScannerViewController *)controller value:(BOOL)value {
60
+ controller.flashLightEnabled = value;
61
+ }
62
+
63
+ + (void)setFinderEnabled:(SBSDKBaseScannerViewFinderConfiguration *)config value:(BOOL)value {
64
+ config.viewFinderEnabled = value;
65
+ }
66
+
67
+ + (void)setFinderStrokeWidth:(SBSDKBaseScannerViewFinderConfiguration *)config value:(int)value {
68
+ config.lineWidth = value;
69
+ }
70
+
71
+ + (void)setFinderStrokeColor:(SBSDKBaseScannerViewFinderConfiguration *)config value:(UIColor *)value {
72
+ config.lineColor = value;
73
+
74
+ }
75
+
76
+ + (void)setFinderOverlayColor:(SBSDKBaseScannerViewFinderConfiguration *)config value:(UIColor *)value {
77
+ config.backgroundColor = value;
78
+ }
79
+
80
+ + (void)setFinderInset:(SBSDKBaseScannerViewFinderConfiguration *)config
81
+ top:(float)top
82
+ left:(float)left
83
+ bottom:(float)bottom
84
+ right:(float)right {
85
+ config.minimumInset = UIEdgeInsetsMake(top, left, bottom, right);
86
+ }
87
+
88
+ + (void)setFinderRequiredAspectRatios:(SBSDKBaseScannerViewFinderConfiguration *)config
89
+ width:(double)width
90
+ height:(double)height {
91
+ config.aspectRatio = [[SBSDKAspectRatio alloc] initWithWidth:width andHeight:height];
92
+ }
93
+
94
+ + (void)setCameraZoomFactor:(SBSDKBarcodeScannerViewController *)controller value:(float)value {
95
+ controller.cameraZoomFactor = value;
96
+ }
97
+
98
+ + (void)setCameraZoomRange:(SBSDKBaseScannerZoomConfiguration *)config minZoom:(float)minZoom maxZoom:(float)maxZoom{
99
+ config.zoomRange = [[SBSDKZoomRange alloc] initWithMinZoom:minZoom andMaxZoom:maxZoom];
100
+ }
101
+
102
+ + (void)setCameraDevice:(SBSDKBarcodeScannerViewController *)controller value:(NSString *)value {
103
+ SBSDKCameraDevice *cameraConfig = controller.cameraDevice;
104
+ if([value isEqualToString:@"BACK_WIDEST"]){
105
+ cameraConfig = [SBSDKCameraDevice widestAvailableBackFacingCamera];
106
+ } else if ([value isEqualToString:@"FRONT"]){
107
+ cameraConfig = [SBSDKCameraDevice defaultFrontFacingCamera];
108
+ } else {
109
+ cameraConfig = [SBSDKCameraDevice defaultBackFacingCamera];
110
+ }
111
+ controller.cameraDevice = cameraConfig;
112
+ }
113
+
114
+ + (void)setMinFocusDistanceLock:(SBSDKBarcodeScannerViewController *)controller value:(BOOL)value {
115
+ if(value){
116
+ if(!controller.isFocusLockEnabled) [controller beginFocusLockAtLensPosition:0.0f];
117
+ } else {
118
+ if(controller.isFocusLockEnabled) [controller endFocusLock];
119
+ }
120
+ }
121
+
122
+ + (void)setLowPowerMode:(SBSDKBarcodeScannerViewController *)controller value:(BOOL)value {
123
+ if(value){
124
+ if(!controller.isEnergySavingActive) [controller startEnergySaving];
125
+ } else {
126
+ if(controller.isEnergySavingActive) [controller endEnergySaving];
127
+ }
128
+ }
129
+
130
+ + (void)setMaximumTextLenght:(SBSDKBarcodeAdditionalParameters *)config value:(int)value {
131
+ config.minimumTextLength = value;
132
+ }
133
+
134
+ + (void)setMinimumTextLenght:(SBSDKBarcodeAdditionalParameters *)config value:(int)value {
135
+ config.maximumTextLength = value;
136
+ }
137
+
138
+ + (void)setMinimum1DBarcodesQuietZone:(SBSDKBarcodeAdditionalParameters *)config value:(int)value {
139
+ config.minimum1DBarcodesQuietZone = value;
140
+ }
141
+
142
+ + (void)setStripCheckDigits:(SBSDKBarcodeAdditionalParameters *)config value:(BOOL)value {
143
+ config.stripCheckDigits = value;
144
+ }
145
+
146
+ + (void)setBarcodeFormats:(SBSDKBarcodeScannerViewController *)controller acceptedBarcodeTypes:(NSArray<SBSDKBarcodeType *> *)acceptedBarcodeTypes {
147
+ controller.acceptedBarcodeTypes = acceptedBarcodeTypes;
148
+ }
149
+
150
+ + (void)setDocumentFormats:(SBSDKBarcodeScannerViewController *)controller acceptedDocumentTypes:(NSArray<SBSDKBarcodeDocumentType *> *)acceptedDocumentTypes {
151
+ controller.acceptedDocumentTypes = acceptedDocumentTypes;
152
+ }
153
+
154
+ + (void)setEngineMode:(SBSDKBarcodeScannerViewController *)controller engineMode:(SBSDKBarcodeEngineMode)engineMode {
155
+ controller.engineMode = engineMode;
156
+ }
157
+
158
+ + (void)setBarcodeExtensionFilter:(SBSDKBarcodeScannerViewController *)controller filter:(SBSDKBarcodesExtensionFilter)filter {
159
+ controller.extensionFilter = filter;
160
+ }
161
+
162
+ + (void)setGS1HandlingMode:(SBSDKBarcodeAdditionalParameters *)config gs1HandlingMode:(SBSDKGS1Handling)gs1HandlingMode {
163
+ config.gs1Handling = gs1HandlingMode;
164
+ }
165
+
166
+ + (void)setMsiPlesseyChecksumAlgorithm:(SBSDKBarcodeAdditionalParameters *)config msiPlesseyChecksumAlgorithm:(SBSDKBarcodeMSIPlesseyChecksumAlgorithm)msiPlesseyChecksumAlgorithm {
167
+ config.msiPlesseyChecksumAlgorithm = msiPlesseyChecksumAlgorithm;
168
+ }
169
+
170
+ + (void)setCodeDensity:(SBSDKBarcodeAdditionalParameters *)config codeDencity:(SBSDKBarcodeDensity)codeDencity {
171
+ config.codeDensity = codeDencity;
172
+ }
173
+
174
+ + (void)freezeCamera:(SBSDKBarcodeScannerViewController *)controller {
175
+ [controller freezeCamera];
176
+ }
177
+
178
+ + (void)unfreezeCamera:(SBSDKBarcodeScannerViewController *)controller {
179
+ [controller unfreezeCamera];
180
+ }
181
+
182
+ + (NSString *) jsonFromResultOrNil:(NSArray<SBSDKBarcodeScannerResult *> *)codes {
183
+ if(!codes || codes.count == 0) return nil;
184
+
185
+ NSDictionary* _Nullable result = [SBBWrapperBarcodeScannerResult nativeResultsToDictionary:codes];
186
+ if(result != NULL) {
187
+ NSData *data = [NSJSONSerialization dataWithJSONObject:result options:NSJSONWritingFragmentsAllowed error:nil];
188
+ return [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
189
+ }
190
+
191
+ return nil;
192
+ }
193
+
194
+
195
+
196
+ @end
@@ -0,0 +1,73 @@
1
+ //
2
+ // RNScanbotBarcodeScannerViewManager.m
3
+ // RNScanbotBarcodeSDK
4
+ //
5
+ // Created by Stefan Krzhovski on 21.05.24.
6
+ //
7
+
8
+ #if !defined(RCT_NEW_ARCH_ENABLED)
9
+ #import <Foundation/Foundation.h>
10
+ #import <React/RCTLog.h>
11
+ #import <React/RCTUIManager.h>
12
+ #import <React/RCTViewManager.h>
13
+ #import <UIKit/UIKit.h>
14
+ #import "RNScanbotBarcodeScannerLegacyView.h"
15
+
16
+ typedef void (^NativeViewBlock)(RNScanbotBarcodeScannerLegacyView* _Nonnull);
17
+
18
+ @interface RNScanbotBarcodeScannerViewManager: RCTViewManager
19
+ @end
20
+
21
+ @implementation RNScanbotBarcodeScannerViewManager
22
+
23
+ RCT_EXPORT_MODULE(ScanbotBarcodeScannerView)
24
+
25
+ - (UIView *)view {
26
+ return [[RNScanbotBarcodeScannerLegacyView alloc] init];
27
+ }
28
+
29
+ RCT_EXPORT_VIEW_PROPERTY(onBarcodeScannerResult, RCTDirectEventBlock)
30
+
31
+ RCT_EXPORT_VIEW_PROPERTY(flashEnabled, BOOL)
32
+ RCT_EXPORT_VIEW_PROPERTY(finderEnabled, BOOL)
33
+ RCT_EXPORT_VIEW_PROPERTY(finderStrokeWidth, int)
34
+ RCT_EXPORT_VIEW_PROPERTY(finderStrokeColor, UIColor)
35
+ RCT_EXPORT_VIEW_PROPERTY(finderOverlayColor, UIColor)
36
+ //RCT_EXPORT_VIEW_PROPERTY(finderMinPadding, int)
37
+ RCT_EXPORT_VIEW_PROPERTY(finderInset, NSDictionary)
38
+ RCT_EXPORT_VIEW_PROPERTY(finderRequiredAspectRatios, NSDictionary)
39
+ RCT_EXPORT_VIEW_PROPERTY(cameraZoomFactor, float)
40
+ RCT_EXPORT_VIEW_PROPERTY(cameraZoomRange, NSDictionary)
41
+ RCT_EXPORT_VIEW_PROPERTY(cameraModule, NSString)
42
+ RCT_EXPORT_VIEW_PROPERTY(minFocusDistanceLock, BOOL)
43
+ RCT_EXPORT_VIEW_PROPERTY(detectorConfig, NSDictionary)
44
+ RCT_EXPORT_VIEW_PROPERTY(scanningEnabled, BOOL)
45
+
46
+ //Commands
47
+
48
+ RCT_EXPORT_METHOD(freezeCamera:(nonnull NSNumber*) reactTag) {
49
+ [self callNativeMethodWithReactTag: reactTag andBlock: ^void (RNScanbotBarcodeScannerLegacyView *nativeView) {
50
+ [nativeView freezeCamera];
51
+ }];
52
+ }
53
+
54
+ RCT_EXPORT_METHOD(unfreezeCamera:(nonnull NSNumber*) reactTag) {
55
+ [self callNativeMethodWithReactTag: reactTag andBlock: ^void (RNScanbotBarcodeScannerLegacyView *nativeView) {
56
+ [nativeView unfreezeCamera];
57
+ }];
58
+ }
59
+
60
+ - (void) callNativeMethodWithReactTag:(nonnull NSNumber*) reactTag andBlock:(NativeViewBlock)block {
61
+ [self.bridge.uiManager addUIBlock:^(RCTUIManager *uiManager, NSDictionary<NSNumber *,UIView *> *viewRegistry) {
62
+ RNScanbotBarcodeScannerLegacyView *view = (RNScanbotBarcodeScannerLegacyView *) viewRegistry[reactTag];
63
+ if (!view || ![view isKindOfClass:[RNScanbotBarcodeScannerLegacyView class]]) {
64
+ RCTLogError(@"Cannot find native view with tag #%@", reactTag);
65
+ return;
66
+ }
67
+ block(view);
68
+ }];
69
+ }
70
+
71
+ @end
72
+
73
+ #endif
package/package.json CHANGED
@@ -1,16 +1,19 @@
1
1
  {
2
2
  "name": "react-native-scanbot-barcode-scanner-sdk",
3
3
  "title": "Scanbot Barcode Scanner SDK for React Native",
4
- "version": "4.2.0",
5
- "scanbot": {
6
- "iosWrapperVersion": "4.2.2.0"
7
- },
4
+ "version": "4.3.0-beta.1",
5
+ "packageManager": "yarn@3.8.1",
6
+ "react-native": "src/index.ts",
7
+ "main": "dist/index.js",
8
+ "types": "dist/index.d.ts",
8
9
  "description": "Scanbot Barcode Scanner SDK React Native Plugin for Android and iOS",
9
- "main": "index.js",
10
10
  "scripts": {
11
- "prepack": "node prepare-podspec.js"
11
+ "prepack": "npm run typescript:build",
12
+ "typescript:build": "tsc",
13
+ "typescript:check": "tsc --noEmit"
12
14
  },
13
15
  "files": [
16
+ "dist",
14
17
  "src/*.js",
15
18
  "src/*.ts",
16
19
  "src/components/**/*.ts",
@@ -18,9 +21,6 @@
18
21
  "src/components/**/*.js",
19
22
  "android/**",
20
23
  "ios/**",
21
- "js/**",
22
- "index.d.ts",
23
- "index.js",
24
24
  "README.md",
25
25
  "Libraries.txt",
26
26
  "RNScanbotBarcodeSDK.podspec",
@@ -55,18 +55,14 @@
55
55
  "readmeFilename": "README.md",
56
56
  "homepage": "https://scanbot.io/developer/react-native-barcode-scanner",
57
57
  "peerDependencies": {
58
- "react": ">=16.8.1",
59
- "react-native": ">=0.60 <1.0.x"
58
+ "react": "*",
59
+ "react-native": "*"
60
60
  },
61
61
  "devDependencies": {
62
- "@types/react": "^18.2.6",
63
- "@types/react-native": "^0.72.0",
64
- "chalk": "^5.3.0",
65
- "cli-spinner": "^0.2.10",
66
- "log-update": "^5.0.1",
67
- "nunjucks": "^3.2.4",
62
+ "@types/react": "^18.2.79",
68
63
  "react": "^18.2.0",
69
- "react-native": "^0.71.8"
64
+ "react-native": "0.74.0",
65
+ "typescript": "^5.4.5"
70
66
  },
71
67
  "contributors": [
72
68
  {
@@ -75,11 +71,10 @@
75
71
  "url": "https://scanbot.io"
76
72
  }
77
73
  ],
78
- "react-native": "index",
79
74
  "codegenConfig": {
80
- "name": "RTNScanbotBarcodeCameraViewSpecs",
75
+ "name": "RNScanbotBarcodeScannerViewSpec",
81
76
  "type": "components",
82
- "jsSrcsDir": "js",
77
+ "jsSrcsDir": "src/components",
83
78
  "android": {
84
79
  "javaPackageName": "io.scanbot.barcodesdk.plugin.reactnative"
85
80
  }
@@ -0,0 +1,112 @@
1
+ import React, { forwardRef, useCallback, useImperativeHandle, useRef } from 'react';
2
+ import NativeBarcodeCameraView, {Commands} from '../spec/ScanbotBarcodeScannerViewNativeComponent';
3
+ import { ScanbotBarcodeCameraViewHandle, ScanbotBarcodeCameraViewProperties } from './ScanbotBarcodeCameraViewProperties';
4
+ import { NativeSyntheticEvent, Platform } from 'react-native';
5
+ import { BarcodeScannerResult } from '../../results';
6
+
7
+ export const ScanbotBarcodeCameraView = forwardRef<ScanbotBarcodeCameraViewHandle, ScanbotBarcodeCameraViewProperties>((
8
+ {
9
+ flashEnabled = false,
10
+ scanningEnabled = true,
11
+ ...props
12
+ },
13
+ forwardedRef,
14
+ ) => {
15
+
16
+ const finderConfig = {
17
+ ...{
18
+ viewFinderEnabled: true,
19
+ finderLineWidth: 2,
20
+ finderLineColor: '#ffffffff',
21
+ overlayColor: '#000000A9',
22
+ finderInset: {
23
+ bottom: 20,
24
+ top: 20,
25
+ left: 20,
26
+ right: 20,
27
+ },
28
+ requiredAspectRatio: {
29
+ height: 3,
30
+ width: 4,
31
+ },
32
+ minPadding: 60,
33
+ }, ...props.finderConfig,
34
+ };
35
+
36
+ const cameraConfig = {
37
+ ...{
38
+ cameraZoomRange: {
39
+ minZoom: 1,
40
+ maxZoom: 12,
41
+ },
42
+ cameraZoomFactor: 0.0,
43
+ minFocusDistanceLock: false,
44
+ }, ...props.cameraConfig,
45
+ };
46
+
47
+ const viewRef = useRef(null);
48
+
49
+ useImperativeHandle(forwardedRef, () => {
50
+ return {
51
+ freezeCamera() {
52
+ if (viewRef.current) {
53
+ //@ts-ignore
54
+ Commands.freezeCamera(viewRef.current);
55
+ }
56
+ },
57
+
58
+ unfreezeCamera() {
59
+ if (viewRef.current) {
60
+ //@ts-ignore
61
+ Commands.unfreezeCamera(viewRef.current);
62
+ }
63
+ },
64
+ };
65
+ }, []);
66
+
67
+ 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);
74
+ }
75
+ }, [props.onBarcodeScannerResult]);
76
+
77
+ return <NativeBarcodeCameraView
78
+ //FinderConfigs
79
+ finderEnabled={finderConfig.viewFinderEnabled}
80
+ finderStrokeWidth={finderConfig.finderLineWidth}
81
+ finderMinPadding={finderConfig.minPadding}
82
+ finderStrokeColor={finderConfig.finderLineColor}
83
+ finderOverlayColor={finderConfig.overlayColor}
84
+ finderInset={finderConfig.finderInset}
85
+ finderRequiredAspectRatios={finderConfig.requiredAspectRatio}
86
+
87
+ //CameraConfigs
88
+ cameraZoomFactor={Platform.select({
89
+ ios: parseFloat(cameraConfig.cameraZoomFactor.toFixed(2)),
90
+ android: cameraConfig.cameraZoomRange.minZoom +
91
+ (cameraConfig.cameraZoomRange.maxZoom - cameraConfig.cameraZoomRange.minZoom) * cameraConfig.cameraZoomFactor,
92
+ })}
93
+ cameraZoomRange={cameraConfig.cameraZoomRange}
94
+ minFocusDistanceLock={cameraConfig.minFocusDistanceLock}
95
+ cameraModule={cameraConfig.cameraModule}
96
+
97
+ //DetectorConfigs
98
+ detectorConfig={props.detectorConfig}
99
+
100
+ //Other
101
+ flashEnabled={flashEnabled}
102
+ scanningEnabled={scanningEnabled}
103
+
104
+ //View
105
+ style={[{ flex: 1 }, props.style]}
106
+ ref={viewRef}
107
+
108
+ //Result
109
+ onBarcodeScannerResult={_onBarcodeScannerResult}
110
+ />;
111
+ },
112
+ );
@@ -0,0 +1,106 @@
1
+ import { ColorValue, ViewStyle } from 'react-native';
2
+ import { BarcodeScannerResult } from '../../results';
3
+ import {
4
+ AspectRatio,
5
+ BarcodeDocumentFormat,
6
+ BarcodeFormat,
7
+ BarcodesExtensionFilter,
8
+ CameraModule,
9
+ CodeDensity,
10
+ EngineMode,
11
+ Gs1HandlingMode,
12
+ MSIPlesseyChecksumAlgorithm,
13
+ ZoomRange,
14
+ } from '../../types';
15
+ import { StyleProp } from 'react-native/Libraries/StyleSheet/StyleSheet';
16
+
17
+ export interface ScanbotBarcodeCameraViewProperties {
18
+ /** Configuration properties of the finder overlay */
19
+ finderConfig?: FinderConfig
20
+ /** Configuration properties of the camera device */
21
+ cameraConfig?: CameraConfig
22
+ /** An interface that defines parameters for barcodes detection and filtering */
23
+ detectorConfig?: DetectorConfig
24
+ /** Whether flash is toggled on or off. */
25
+ flashEnabled?: boolean
26
+ /**
27
+ * Enable or disable barcode detection.
28
+ * If disabled, the camera preview is active but no barcodes will be detected.
29
+ * Default is enabled.
30
+ */
31
+ scanningEnabled?: boolean;
32
+ /* The result of the barcode scanner */
33
+ onBarcodeScannerResult: (result: BarcodeScannerResult) => void;
34
+ style?: StyleProp<ViewStyle>
35
+ }
36
+ /** Configuration properties of the finder overlay */
37
+ export interface FinderConfig {
38
+ /** Display the region of interest. The default value is TRUE. */
39
+ viewFinderEnabled?: boolean;
40
+ /** Width of finder frame border. */
41
+ finderLineWidth?: number;
42
+ /** Color of finder frame border. */
43
+ finderLineColor?: ColorValue;
44
+ /** Background color of the detection overlay. */
45
+ overlayColor?: ColorValue;
46
+ /** The minimum space from view finders outer edges to the view edges. */
47
+ finderInset?: FinderInset;
48
+ /** Initial padding for insets. Android only. */
49
+ minPadding?: number;
50
+ /** Aspect ratio of finder frame (width \ height), which is used to build actual finder frame. */
51
+ requiredAspectRatio?: AspectRatio;
52
+ }
53
+
54
+ /** Configuration properties of the camera device */
55
+ export interface CameraConfig {
56
+ /** The relative initial zoom level of the camera in the range (0,1), where 0 is zoomed out and 1 is zoomed in. Default value is 0.0. */
57
+ cameraZoomFactor?: number
58
+ /** The range of valid camera zoom factors. Default value is (1.0; 12.0). */
59
+ cameraZoomRange?: ZoomRange;
60
+ /** The camera module to be used for barcode scanning */
61
+ cameraModule?: CameraModule;
62
+ /** Lock focus distance withing minimum possible range */
63
+ minFocusDistanceLock?: boolean;
64
+ }
65
+
66
+ /** An interface that defines parameters for barcodes detection and filtering */
67
+ export interface DetectorConfig {
68
+ /** Accepted barcode formats */
69
+ barcodeFormats?: BarcodeFormat[];
70
+ /** An optional array of barcode document formats that act as a detection filter. By default all supported document formats will be detected. */
71
+ acceptedDocumentFormats?: BarcodeDocumentFormat[];
72
+ /** The engine mode to be used for barcode scanning. The default value is NEXT_GEN. */
73
+ engineMode?: EngineMode;
74
+ /** The extension filter for EAN and UPC barcodes. */
75
+ barcodesExtensionFilter?: BarcodesExtensionFilter;
76
+ /** If `true`, enabled the mode which slightly decreases the scanning quality and the energy consumption, and increases the scanning speed. If `false` - mode is disabled. The default is `false` */
77
+ lowPowerMode?: boolean;
78
+ /** Optional minimum required text length of the detected barcode. The default is 0 (setting is turned off). NOTE - This feature works on ITF barcodes only. */
79
+ minimumTextLength?: number;
80
+ /** Optional maximum text length of the detected barcode. The default is 0 (setting is turned off). NOTE - This feature works on ITF barcodes only. */
81
+ maximumTextLength?: number;
82
+ /** Optional minimum required quiet zone on the barcode. Measured in modules (the size of minimal bar on the barcode). The default is 10. NOTE - This feature works on ITF barcodes only. */
83
+ minimum1DBarcodesQuietZone?: number;
84
+ /** With this option enabled, the scanner removes checks digits for UPC, EAN and MSI Plessey codes. Has no effect if both single and double digit MSI Plessey checksums are enabled. The default is `false` */
85
+ stripCheckDigits?: boolean;
86
+ /** The GS1 handling mode. The default value is PARSE. */
87
+ gs1HandlingMode?: Gs1HandlingMode;
88
+ /** The checksum algorithm for MSI Plessey barcodes. The default value is MOD_10. */
89
+ msiPlesseyChecksumAlgorithm?: MSIPlesseyChecksumAlgorithm;
90
+ /** The expected density of QR codes in an image. */
91
+ codeDensity?: CodeDensity;
92
+ }
93
+
94
+ export interface FinderInset {
95
+ left: number;
96
+ top: number;
97
+ bottom: number;
98
+ right: number;
99
+ }
100
+
101
+ export interface ScanbotBarcodeCameraViewHandle {
102
+ /** Freezes the cameras preview */
103
+ freezeCamera(): void
104
+ /** Unfreezes the previously frozen cameras preview */
105
+ unfreezeCamera(): void
106
+ }
@@ -0,0 +1,59 @@
1
+ import codegenNativeComponent from 'react-native/Libraries/Utilities/codegenNativeComponent';
2
+ import type { ColorValue, ViewProps } from 'react-native';
3
+ import type { DirectEventHandler, Double, Float, Int32, WithDefault } from 'react-native/Libraries/Types/CodegenTypes';
4
+ import { ComponentType } from 'react';
5
+ import codegenNativeCommands from 'react-native/Libraries/Utilities/codegenNativeCommands';
6
+
7
+
8
+ export interface NativeProps extends ViewProps {
9
+ onBarcodeScannerResult?: DirectEventHandler<Readonly<{result: string}>>;
10
+ flashEnabled?: WithDefault<boolean, false>;
11
+ finderEnabled?: WithDefault<boolean, false>;
12
+ finderStrokeWidth?: WithDefault<Int32, 2>;
13
+ finderStrokeColor?: ColorValue;
14
+ finderOverlayColor?: ColorValue;
15
+ finderMinPadding?: WithDefault<Int32, 0>;
16
+ finderInset?: {
17
+ left?: WithDefault<Int32, 10>;
18
+ top?: WithDefault<Int32, 10>;
19
+ bottom?: WithDefault<Int32, 10>;
20
+ right?: WithDefault<Int32, 10>;
21
+ };
22
+ finderRequiredAspectRatios?: {
23
+ width?: WithDefault<Double, 4>,
24
+ height?: WithDefault<Double, 3>
25
+ };
26
+ cameraZoomFactor?: WithDefault<Float, 0.0>;
27
+ cameraZoomRange?: {
28
+ minZoom?: WithDefault<Float, 1.0>,
29
+ maxZoom?: WithDefault<Float, 12.0>,
30
+ };
31
+ cameraModule?: WithDefault<string, 'BACK'>;
32
+ scanningEnabled?: WithDefault<boolean, true>;
33
+ detectorConfig?: {
34
+ barcodeFormats?: ReadonlyArray<string>;
35
+ acceptedDocumentFormats?: ReadonlyArray<string>;
36
+ engineMode?: WithDefault<string, 'NEXT_GEN'>;
37
+ barcodesExtensionFilter?: WithDefault<string, 'NO_FILTER'>;
38
+ lowPowerMode?: WithDefault<boolean, false>;
39
+ minimumTextLength?: WithDefault<Int32, 0>;
40
+ maximumTextLength?: WithDefault<Int32, 0>;
41
+ minimum1DBarcodesQuietZone?: WithDefault<Int32, 10>;
42
+ stripCheckDigits?: WithDefault<boolean, false>;
43
+ gs1HandlingMode?: WithDefault<string, 'PARSE'>;
44
+ msiPlesseyChecksumAlgorithm?: WithDefault<string, 'MOD_10'>;
45
+ codeDensity?: WithDefault<string, 'LOW'>;
46
+ };
47
+ minFocusDistanceLock?: WithDefault<boolean, false>;
48
+ }
49
+
50
+ export default codegenNativeComponent<NativeProps>('ScanbotBarcodeScannerView');
51
+
52
+ interface NativeCommands {
53
+ freezeCamera: (viewRef: React.ElementRef<ComponentType>) => void;
54
+ unfreezeCamera: (viewRef: React.ElementRef<ComponentType>) => void;
55
+ }
56
+
57
+ export const Commands = codegenNativeCommands<NativeCommands>({
58
+ supportedCommands: ['freezeCamera', 'unfreezeCamera'],
59
+ });
package/src/index.ts ADDED
@@ -0,0 +1,58 @@
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
+ import {NativeModules} from 'react-native';
7
+ import {
8
+ BarcodeScannerConfiguration,
9
+ BatchBarcodeScannerConfiguration,
10
+ ScanbotBarcodeSdkConfiguration
11
+ } from "./configurations";
12
+ import {ResultWrapper} from "./customResults";
13
+ import {BarcodeScannerResult, BatchBarcodeScannerResult, GetLicenseInfoResult} from "./results";
14
+ import {DetectBarcodesOnImageArguments, ExtractImagesFromPdfArguments} from "./customConfigurations";
15
+ import {ScanbotBarcodeCameraView} from './components/barcode-camera-view/ScanbotBarcodeCameraView';
16
+ import {ScanbotBarcodeCameraViewProperties, ScanbotBarcodeCameraViewHandle} from './components/barcode-camera-view/ScanbotBarcodeCameraViewProperties';
17
+
18
+ const {ScanbotBarcodeSdk} = NativeModules;
19
+
20
+ export interface ScanbotBarcodeSdk {
21
+ // SDK Internal
22
+ initializeSdk(config: ScanbotBarcodeSdkConfiguration): Promise<ResultWrapper<string>>;
23
+
24
+ getLicenseInfo(): Promise<ResultWrapper<GetLicenseInfoResult>>;
25
+
26
+ cleanup(): Promise<ResultWrapper<string>>;
27
+
28
+ // RTU-UI Barcode Scanning
29
+ startBarcodeScanner(config: BarcodeScannerConfiguration): Promise<ResultWrapper<BarcodeScannerResult>>;
30
+
31
+ closeBarcodeScanner(): Promise<ResultWrapper<undefined>>;
32
+
33
+ startBatchBarcodeScanner(config: BatchBarcodeScannerConfiguration): Promise<ResultWrapper<BatchBarcodeScannerResult>>;
34
+
35
+ closeBatchBarcodeScanner(): Promise<ResultWrapper<undefined>>;
36
+
37
+ // Other Barcode Scanning functionalities
38
+ detectBarcodesOnImage(
39
+ args: DetectBarcodesOnImageArguments
40
+ ): Promise<ResultWrapper<BarcodeScannerResult>>;
41
+
42
+ extractImagesFromPDF(
43
+ args: ExtractImagesFromPdfArguments
44
+ ): Promise<ResultWrapper<string[]>>;
45
+ }
46
+
47
+ const ScanbotBarcodeSDK: ScanbotBarcodeSdk = ScanbotBarcodeSdk
48
+
49
+ export default ScanbotBarcodeSDK;
50
+
51
+ export * from './types'
52
+ export * from './customTypes'
53
+ export * from './results'
54
+ export * from './customResults'
55
+ export * from './configurations'
56
+ export * from './customConfigurations'
57
+
58
+ export {ScanbotBarcodeCameraView, ScanbotBarcodeCameraViewProperties, ScanbotBarcodeCameraViewHandle}