dynamsoft-capture-vision-react-native 1.0.0

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 (31) hide show
  1. package/.gitattributes +1 -0
  2. package/LICENSE +5 -0
  3. package/Legal.txt +551 -0
  4. package/README.md +247 -0
  5. package/android/build.gradle +54 -0
  6. package/android/gradle/wrapper/gradle-wrapper.jar +0 -0
  7. package/android/gradle/wrapper/gradle-wrapper.properties +6 -0
  8. package/android/src/main/AndroidManifest.xml +6 -0
  9. package/android/src/main/java/com/dynamsoft/reactlibrary/RNDCECameraView.java +90 -0
  10. package/android/src/main/java/com/dynamsoft/reactlibrary/RNDCECameraViewManager.java +156 -0
  11. package/android/src/main/java/com/dynamsoft/reactlibrary/RNDynamsoftBarcodeReaderModule.java +253 -0
  12. package/android/src/main/java/com/dynamsoft/reactlibrary/RNDynamsoftCaptrueVisionPackage.java +28 -0
  13. package/dynamsoft-capture-vision-react-native.podspec +22 -0
  14. package/ios/RNDynamsoftCaptureVision/DYSCameraView.h +26 -0
  15. package/ios/RNDynamsoftCaptureVision/DYSCameraView.m +71 -0
  16. package/ios/RNDynamsoftCaptureVision/DYSCameraViewManager.h +17 -0
  17. package/ios/RNDynamsoftCaptureVision/DYSCameraViewManager.m +77 -0
  18. package/ios/RNDynamsoftCaptureVision/RCTDynamsoftBarcodeReader.h +14 -0
  19. package/ios/RNDynamsoftCaptureVision/RCTDynamsoftBarcodeReader.m +223 -0
  20. package/ios/RNDynamsoftCaptureVision/StaticClass.h +26 -0
  21. package/ios/RNDynamsoftCaptureVision/StaticClass.m +21 -0
  22. package/ios/RNDynamsoftCaptureVision.xcodeproj/project.pbxproj +337 -0
  23. package/js/BarcodeSettings.d.ts +112 -0
  24. package/js/BarcodeSettings.js +66 -0
  25. package/js/DynamsoftBarcodeReader.d.ts +14 -0
  26. package/js/DynamsoftBarcodeReader.js +75 -0
  27. package/js/DynamsoftCameraView.d.ts +10 -0
  28. package/js/DynamsoftCameraView.js +107 -0
  29. package/js/index.d.ts +3 -0
  30. package/js/index.js +3 -0
  31. package/package.json +31 -0
@@ -0,0 +1,253 @@
1
+
2
+ package com.dynamsoft.reactlibrary;
3
+
4
+ import android.util.Log;
5
+
6
+ import com.dynamsoft.dbr.BarcodeReader;
7
+ import com.dynamsoft.dbr.BarcodeReaderException;
8
+ import com.dynamsoft.dbr.DBRLicenseVerificationListener;
9
+ import com.dynamsoft.dbr.EnumBarcodeFormat_2;
10
+ import com.dynamsoft.dbr.EnumConflictMode;
11
+ import com.dynamsoft.dbr.EnumPresetTemplate;
12
+ import com.dynamsoft.dbr.ImageData;
13
+ import com.dynamsoft.dbr.LocalizationResult;
14
+ import com.dynamsoft.dbr.Point;
15
+ import com.dynamsoft.dbr.PublicRuntimeSettings;
16
+ import com.dynamsoft.dbr.TextResult;
17
+ import com.dynamsoft.dbr.TextResultListener;
18
+ import com.facebook.react.bridge.Arguments;
19
+ import com.facebook.react.bridge.Promise;
20
+ import com.facebook.react.bridge.ReactApplicationContext;
21
+ import com.facebook.react.bridge.ReactContextBaseJavaModule;
22
+ import com.facebook.react.bridge.ReactMethod;
23
+ import com.facebook.react.bridge.ReadableMap;
24
+ import com.facebook.react.bridge.WritableArray;
25
+ import com.facebook.react.bridge.WritableMap;
26
+ import com.facebook.react.modules.core.DeviceEventManagerModule;
27
+
28
+ import static com.dynamsoft.reactlibrary.RNDCECameraViewManager.mCamera;
29
+
30
+ public class RNDynamsoftBarcodeReaderModule extends ReactContextBaseJavaModule {
31
+
32
+ private final ReactApplicationContext mReactContext;
33
+ private BarcodeReader mReader;
34
+
35
+ private boolean mIsCameraAttached;
36
+
37
+ public RNDynamsoftBarcodeReaderModule(ReactApplicationContext reactContext) {
38
+ super(reactContext);
39
+ mReactContext = reactContext;
40
+ mIsCameraAttached = false;
41
+ }
42
+
43
+ @Override
44
+ public String getName() {
45
+ return "RNDynamsoftBarcodeReader";
46
+ }
47
+
48
+
49
+ @ReactMethod
50
+ public void initLicense(String license, final Promise promise) {
51
+ BarcodeReader.initLicense(license, new DBRLicenseVerificationListener() {
52
+ @Override
53
+ public void DBRLicenseVerificationCallback(boolean b, Exception e) {
54
+ if (b) {
55
+ promise.resolve(true);
56
+ } else {
57
+ BarcodeReaderException be = (BarcodeReaderException) e;
58
+ promise.reject(be.getErrorCode() + "", e);
59
+ }
60
+ }
61
+ });
62
+ }
63
+
64
+ @ReactMethod
65
+ public void createInstance() {
66
+ try {
67
+ mReader = new BarcodeReader();
68
+ } catch (BarcodeReaderException e) {
69
+ e.printStackTrace();
70
+ }
71
+ mReader.setCameraEnhancer(mCamera);
72
+ }
73
+
74
+ @ReactMethod
75
+ public void getVersion(Promise promise) {
76
+ promise.resolve(mReader.getVersion());
77
+ }
78
+
79
+ @ReactMethod
80
+ public void addResultListener() {
81
+ mReader.setTextResultListener(new TextResultListener() {
82
+ @Override
83
+ public void textResultCallback(int i, ImageData imageData, final TextResult[] textResults) {
84
+ WritableArray results = serializeResults(textResults);
85
+ mReactContext.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class).emit(
86
+ "resultEvent",
87
+ results);
88
+ }
89
+ });
90
+ }
91
+
92
+ @ReactMethod
93
+ public void addListener(String eventName) {
94
+
95
+ }
96
+
97
+ @ReactMethod
98
+ public void removeListeners(Integer count) {
99
+
100
+ }
101
+
102
+
103
+ @ReactMethod
104
+ public void startBarcodeScanning() {
105
+ if (!mIsCameraAttached) {
106
+ mReader.setCameraEnhancer(mCamera);
107
+ mIsCameraAttached = true;
108
+ }
109
+ mReader.startScanning();
110
+ }
111
+
112
+ @ReactMethod
113
+ public void stopBarcodeScanning() {
114
+ mReader.stopScanning();
115
+ }
116
+
117
+ @ReactMethod
118
+ public void updateSettingsFromDictionary(ReadableMap map, Promise promise) {
119
+ if (map == null) {
120
+ promise.resolve(false);
121
+ return;
122
+ }
123
+ try {
124
+ PublicRuntimeSettings settings = mReader.getRuntimeSettings();
125
+ settings.barcodeFormatIds = map.getInt("barcodeFormatIds");
126
+ settings.barcodeFormatIds_2 = map.getInt("barcodeFormatIds_2");
127
+ settings.expectedBarcodesCount = map.getInt("expectedBarcodesCount");
128
+ settings.timeout = map.getInt("timeout");
129
+ mReader.updateRuntimeSettings(settings);
130
+ promise.resolve(true);
131
+ } catch (BarcodeReaderException e) {
132
+ e.printStackTrace();
133
+ promise.resolve(false);
134
+ }
135
+ }
136
+
137
+ @ReactMethod
138
+ public void updateSettingsFromNumber(int PresetTpl, Promise promise) {
139
+ if (PresetTpl >= 0 && PresetTpl <= 6) {
140
+ mReader.updateRuntimeSettings(EnumPresetTemplate.fromValue(PresetTpl));
141
+ promise.resolve(true);
142
+ } else {
143
+ promise.resolve(false);
144
+ }
145
+ }
146
+
147
+ @ReactMethod
148
+ public void updateSettingsFromString(String settingsStr, Promise promise) {
149
+ try {
150
+ mReader.initRuntimeSettingsWithString(settingsStr, EnumConflictMode.CM_OVERWRITE);
151
+ promise.resolve(true);
152
+ } catch (BarcodeReaderException e) {
153
+ e.printStackTrace();
154
+ promise.resolve(false);
155
+ }
156
+ }
157
+
158
+ @ReactMethod
159
+ public void resetSettings(Promise promise) {
160
+ try {
161
+ mReader.resetRuntimeSettings();
162
+ } catch (BarcodeReaderException e) {
163
+ e.printStackTrace();
164
+ promise.resolve(false);
165
+ }
166
+ promise.resolve(true);
167
+ }
168
+
169
+ @ReactMethod
170
+ public void outputSettings(Promise promise) {
171
+ try {
172
+ promise.resolve(mReader.outputSettingsToString(""));
173
+ } catch (BarcodeReaderException e) {
174
+ e.printStackTrace();
175
+ promise.reject(e.getErrorCode() + "", e.getCause());
176
+ }
177
+ }
178
+
179
+ @ReactMethod
180
+ public void getSettings(Promise promise) {
181
+ WritableMap settingsMap = Arguments.createMap();
182
+ try {
183
+ PublicRuntimeSettings settings = mReader.getRuntimeSettings();
184
+ settingsMap.putInt("barcodeFormatIds", settings.barcodeFormatIds);
185
+ settingsMap.putInt("barcodeFormatIds_2", settings.barcodeFormatIds_2);
186
+ settingsMap.putInt("expectedBarcodesCount", settings.expectedBarcodesCount);
187
+ settingsMap.putInt("timeout", settings.timeout);
188
+ } catch (BarcodeReaderException e) {
189
+ e.printStackTrace();
190
+ promise.reject(e.getErrorCode() + "", e.getCause());
191
+ }
192
+ promise.resolve(settingsMap);
193
+ // return settingsMap;
194
+ }
195
+
196
+ private WritableArray serializeResults(TextResult[] barcodes) {
197
+ WritableArray barcodeList = Arguments.createArray();
198
+
199
+ for (int i = 0; i < barcodes.length; i++) {
200
+ TextResult barcode = barcodes[i];
201
+ WritableMap serializedBarcode = Arguments.createMap();
202
+
203
+ if (barcode.barcodeFormat_2 != EnumBarcodeFormat_2.BF2_NULL) {
204
+ serializedBarcode.putString("barcodeFormatString", barcode.barcodeFormatString_2);
205
+ } else {
206
+ serializedBarcode.putString("barcodeFormatString", barcode.barcodeFormatString);
207
+ }
208
+ serializedBarcode.putString("barcodeText", barcode.barcodeText);
209
+ serializedBarcode.putMap("barcodeLocation", handleLocationResult(barcode.localizationResult));
210
+ barcodeList.pushMap(serializedBarcode);
211
+ }
212
+
213
+ return barcodeList;
214
+ }
215
+
216
+ private WritableMap handleLocationResult(LocalizationResult result) {
217
+ if (result == null) {
218
+ return null;
219
+ }
220
+ WritableMap location = Arguments.createMap();
221
+ location.putInt("angle", result.angle);
222
+ location.putMap("quadrilateral", handleQuadrilateral(result.resultPoints));
223
+ return location;
224
+ }
225
+
226
+ private WritableMap handleQuadrilateral(Point[] points) {
227
+ if (points == null) {
228
+ return null;
229
+ }
230
+ WritableMap quadrilateral = Arguments.createMap();
231
+
232
+ quadrilateral.putArray("points", handlePoints(points));
233
+ return quadrilateral;
234
+ }
235
+
236
+ private WritableArray handlePoints(Point[] points) {
237
+ if (points == null) {
238
+ return null;
239
+ }
240
+ WritableArray pointArray = Arguments.createArray();
241
+ for (int i = 0; i < 4; i++) {
242
+ pointArray.pushMap(handleSinglePoint(points[i]));
243
+ }
244
+ return pointArray;
245
+ }
246
+
247
+ private WritableMap handleSinglePoint(Point point) {
248
+ WritableMap pointMap = Arguments.createMap();
249
+ pointMap.putInt("x", point.x);
250
+ pointMap.putInt("y", point.y);
251
+ return pointMap;
252
+ }
253
+ }
@@ -0,0 +1,28 @@
1
+
2
+ package com.dynamsoft.reactlibrary;
3
+
4
+ import java.util.Arrays;
5
+ import java.util.Collections;
6
+ import java.util.List;
7
+
8
+ import com.facebook.react.ReactPackage;
9
+ import com.facebook.react.bridge.NativeModule;
10
+ import com.facebook.react.bridge.ReactApplicationContext;
11
+ import com.facebook.react.uimanager.ViewManager;
12
+ import com.facebook.react.bridge.JavaScriptModule;
13
+ public class RNDynamsoftCaptrueVisionPackage implements ReactPackage {
14
+ @Override
15
+ public List<NativeModule> createNativeModules(ReactApplicationContext reactContext) {
16
+ return Arrays.<NativeModule>asList(new RNDynamsoftBarcodeReaderModule(reactContext));
17
+ }
18
+
19
+ // Deprecated from RN 0.47
20
+ public List<Class<? extends JavaScriptModule>> createJSModules() {
21
+ return Collections.emptyList();
22
+ }
23
+
24
+ @Override
25
+ public List<ViewManager> createViewManagers(ReactApplicationContext reactContext) {
26
+ return Arrays.<ViewManager>asList(new RNDCECameraViewManager(reactContext));
27
+ }
28
+ }
@@ -0,0 +1,22 @@
1
+ require "json"
2
+
3
+ package = JSON.parse(File.read(File.join(__dir__, "package.json")))
4
+
5
+ Pod::Spec.new do |s|
6
+ s.name = package["name"]
7
+ s.version = package["version"]
8
+ s.summary = package["description"]
9
+ s.homepage = package["homepage"]
10
+
11
+ s.authors = { package["author"]["name"] => package["author"]["email"] }
12
+ s.platforms = { :ios => "10.0" }
13
+ s.source = { :git => "https://github.com/Dynamsoft/capture-vision-react-native.git", :tag => "#{s.version}" }
14
+ s.source_files = "ios/RNDynamsoftCaptureVision/**/*.{h,m}"
15
+ s.requires_arc = true
16
+ s.module_name = "RNDynamsoftCaptureVision"
17
+ s.header_dir = "RNDynamsoftCaptureVision"
18
+ s.dependency 'DynamsoftCameraEnhancer', '= 2.1.4'
19
+ s.dependency 'DynamsoftBarcodeReader', '= 9.0.2'
20
+
21
+ s.dependency "React"
22
+ end
@@ -0,0 +1,26 @@
1
+ //
2
+ // DYSCameraView.h
3
+ // RCTDynamsoftBarcodeReader
4
+ //
5
+ // Created by dynamsoft on 2022/3/16.
6
+ //
7
+
8
+ #import <UIKit/UIKit.h>
9
+ #import <React/RCTComponent.h>
10
+
11
+ NS_ASSUME_NONNULL_BEGIN
12
+
13
+ @interface DYSCameraView : UIView
14
+
15
+ @property (nonatomic) BOOL scanRegionVisible;
16
+
17
+ @property (nonatomic) BOOL overlayVisible;
18
+
19
+ @property (nonatomic, strong, nullable) NSDictionary *scanRegion;
20
+
21
+ - (void)open;
22
+ - (void)close;
23
+
24
+ @end
25
+
26
+ NS_ASSUME_NONNULL_END
@@ -0,0 +1,71 @@
1
+ //
2
+ // DYSCameraView.m
3
+ // RCTDynamsoftBarcodeReader
4
+ //
5
+ // Created by dynamsoft on 2022/3/16.
6
+ //
7
+
8
+ #import "DYSCameraView.h"
9
+ #import <React/RCTLog.h>
10
+ #import "StaticClass.h"
11
+
12
+ @implementation DYSCameraView
13
+
14
+ @synthesize overlayVisible;
15
+ @synthesize scanRegionVisible = _scanRegionVisible;
16
+ @synthesize scanRegion;
17
+
18
+ - (instancetype)init {
19
+ self = [super init];
20
+ if (self) {
21
+ [self addSubview:[StaticClass instance].view];
22
+ }
23
+ return self;
24
+ }
25
+
26
+ - (void)layoutSubviews {
27
+ [super layoutSubviews];
28
+ [StaticClass instance].view.frame = self.bounds;
29
+ }
30
+
31
+ - (void)setOverlayVisible:(BOOL)overlayVisible{
32
+ [StaticClass instance].view.overlayVisible = overlayVisible;
33
+ }
34
+
35
+ - (void)setScanRegionVisible:(BOOL)scanRegionVisible{
36
+ _scanRegionVisible = scanRegionVisible;
37
+ [StaticClass instance].dce.scanRegionVisible = scanRegionVisible;
38
+ }
39
+
40
+ - (BOOL)scanRegionVisible{
41
+ return _scanRegionVisible;
42
+ }
43
+
44
+ - (void)setScanRegion:(NSDictionary *)scanRegion{
45
+ if (scanRegion) {
46
+ NSNumber *regionTop = [scanRegion valueForKey:@"regionTop"];
47
+ NSNumber *regionLeft = [scanRegion valueForKey:@"regionLeft"];
48
+ NSNumber *regionRight = [scanRegion valueForKey:@"regionRight"];
49
+ NSNumber *regionBottom = [scanRegion valueForKey:@"regionBottom"];
50
+ NSNumber *regionMeasuredByPercentage = [scanRegion valueForKey:@"regionTop"];
51
+ iRegionDefinition *region = [iRegionDefinition new];
52
+ region.regionTop = regionTop.integerValue;
53
+ region.regionLeft = regionLeft.integerValue;
54
+ region.regionRight = regionRight.integerValue;
55
+ region.regionBottom = regionBottom.integerValue;
56
+ region.regionMeasuredByPercentage = regionMeasuredByPercentage.boolValue;
57
+ NSError *err = [NSError new];
58
+ [[StaticClass instance].dce setScanRegion:region error:&err];
59
+ [StaticClass instance].dce.scanRegionVisible = _scanRegionVisible;
60
+ }
61
+ }
62
+
63
+ - (void)open{
64
+ [[StaticClass instance].dce open];
65
+ }
66
+
67
+ - (void)close{
68
+ [[StaticClass instance].dce close];
69
+ }
70
+
71
+ @end
@@ -0,0 +1,17 @@
1
+ //
2
+ // DYSCameraViewManager.h
3
+ // RCTDynamsoftBarcodeReader
4
+ //
5
+ // Created by dynamsoft on 2022/3/16.
6
+ //
7
+
8
+ #import <React/RCTViewManager.h>
9
+ #import <React/RCTBridgeModule.h>
10
+
11
+ NS_ASSUME_NONNULL_BEGIN
12
+
13
+ @interface DYSCameraViewManager : RCTViewManager
14
+
15
+ @end
16
+
17
+ NS_ASSUME_NONNULL_END
@@ -0,0 +1,77 @@
1
+ //
2
+ // DYSCameraViewManager.m
3
+ // RCTDynamsoftBarcodeReader
4
+ //
5
+ // Created by dynamsoft on 2022/3/16.
6
+ //
7
+
8
+ #import <React/RCTUIManager.h>
9
+ #import "DYSCameraViewManager.h"
10
+ #import "DYSCameraView.h"
11
+ #import "StaticClass.h"
12
+
13
+ @implementation DYSCameraViewManager
14
+
15
+ RCT_EXPORT_MODULE(DYSCameraView)
16
+
17
+ - (instancetype)init {
18
+ self = [super init];
19
+ if (self) {
20
+ CGFloat heigth = UIScreen.mainScreen.bounds.size.height;
21
+ CGFloat width = UIScreen.mainScreen.bounds.size.width;
22
+ [StaticClass instance].view = [[DCECameraView alloc] initWithFrame:CGRectMake(0, 0, width, heigth)];
23
+ [StaticClass instance].dce = [[DynamsoftCameraEnhancer alloc] initWithView:[StaticClass instance].view];
24
+ }
25
+ return self;
26
+ }
27
+
28
+ + (BOOL)requiresMainQueueSetup{
29
+ return YES;
30
+ }
31
+
32
+ - (UIView *)view {
33
+ return [[DYSCameraView alloc] init];
34
+ }
35
+
36
+ RCT_EXPORT_VIEW_PROPERTY(scanRegionVisible, BOOL)
37
+ RCT_EXPORT_VIEW_PROPERTY(overlayVisible, BOOL)
38
+ RCT_EXPORT_VIEW_PROPERTY(scanRegion, NSDictionary)
39
+
40
+ RCT_EXPORT_METHOD(open:(nonnull NSNumber *)reactTag) {
41
+ [self.bridge.uiManager addUIBlock:
42
+ ^(__unused RCTUIManager *uiManager, NSDictionary<NSNumber *, UIView *> *viewRegistry) {
43
+ id view = viewRegistry[reactTag];
44
+ if (!view || ![view isKindOfClass:[DYSCameraView class]]) {
45
+ RCTLogError(@"Cannot find DYSCameraView with tag #%@", reactTag);
46
+ } else {
47
+ [((DYSCameraView *)view) open];
48
+ }
49
+ }];
50
+ }
51
+
52
+ RCT_EXPORT_METHOD(close:(nonnull NSNumber *)reactTag) {
53
+ [self.bridge.uiManager addUIBlock:
54
+ ^(__unused RCTUIManager *uiManager, NSDictionary<NSNumber *, UIView *> *viewRegistry) {
55
+ id view = viewRegistry[reactTag];
56
+ if (!view || ![view isKindOfClass:[DYSCameraView class]]) {
57
+ RCTLogError(@"Cannot find DYSCameraView with tag #%@", reactTag);
58
+ } else {
59
+ [((DYSCameraView *)view) close];
60
+ }
61
+ }];
62
+ }
63
+
64
+ RCT_EXPORT_METHOD(setScanRegion:(nonnull NSNumber *)reactTag
65
+ scanRegion:(NSDictionary *)scanRegion) {
66
+ [self.bridge.uiManager addUIBlock:
67
+ ^(__unused RCTUIManager *uiManager, NSDictionary<NSNumber *, UIView *> *viewRegistry) {
68
+ id view = viewRegistry[reactTag];
69
+ if (!view || ![view isKindOfClass:[DYSCameraView class]]) {
70
+ RCTLogError(@"Cannot find DYSCameraView with tag #%@", reactTag);
71
+ } else {
72
+ [((DYSCameraView *)view) setScanRegion:scanRegion];
73
+ }
74
+ }];
75
+ }
76
+
77
+ @end
@@ -0,0 +1,14 @@
1
+ //
2
+ // RCTDynamsoftBarcodeReader.h
3
+ // RCTDynamsoftBarcodeReader
4
+ //
5
+ // Created by dynamsoft on 2022/3/16.
6
+ //
7
+
8
+ #import <Foundation/Foundation.h>
9
+ #import <React/RCTBridgeModule.h>
10
+ #import <React/RCTEventEmitter.h>
11
+
12
+ @interface RCTDynamsoftBarcodeReader : RCTEventEmitter <RCTBridgeModule>
13
+
14
+ @end