dynamsoft-capture-vision-react-native 1.0.0 → 1.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +91 -60
- package/android/build.gradle +2 -2
- package/android/src/main/java/com/dynamsoft/reactlibrary/Constants.java +23 -0
- package/android/src/main/java/com/dynamsoft/reactlibrary/RNDCECameraView.java +5 -26
- package/android/src/main/java/com/dynamsoft/reactlibrary/RNDCECameraViewManager.java +94 -42
- package/android/src/main/java/com/dynamsoft/reactlibrary/RNDynamsoftBarcodeReaderModule.java +32 -3
- package/android/src/main/java/com/dynamsoft/reactlibrary/RNDynamsoftCaptrueVisionPackage.java +13 -2
- package/dynamsoft-capture-vision-react-native.podspec +2 -2
- package/ios/RNDynamsoftCaptureVision/DYSCameraView.h +30 -26
- package/ios/RNDynamsoftCaptureVision/DYSCameraView.m +113 -71
- package/ios/RNDynamsoftCaptureVision/DYSCameraViewManager.h +17 -17
- package/ios/RNDynamsoftCaptureVision/DYSCameraViewManager.m +79 -77
- package/ios/RNDynamsoftCaptureVision/RCTDynamsoftBarcodeReader.h +14 -14
- package/ios/RNDynamsoftCaptureVision/RCTDynamsoftBarcodeReader.m +233 -223
- package/ios/RNDynamsoftCaptureVision/StaticClass.h +26 -26
- package/ios/RNDynamsoftCaptureVision/StaticClass.m +21 -21
- package/js/BarcodeResult.d.ts +25 -0
- package/js/BarcodeResult.js +3 -0
- package/js/BarcodeSettings.d.ts +52 -100
- package/js/BarcodeSettings.js +55 -56
- package/js/BasicStructures.d.ts +20 -0
- package/js/BasicStructures.js +3 -0
- package/js/CameraSettings.d.ts +11 -0
- package/js/CameraSettings.js +9 -0
- package/js/DynamsoftBarcodeReader.d.ts +4 -3
- package/js/DynamsoftBarcodeReader.js +60 -59
- package/js/DynamsoftCameraView.d.ts +31 -7
- package/js/DynamsoftCameraView.js +90 -83
- package/js/index.d.ts +3 -0
- package/js/index.js +23 -3
- package/package.json +8 -1
package/README.md
CHANGED
|
@@ -19,7 +19,8 @@
|
|
|
19
19
|
- [System Requirements](#system-requirements)
|
|
20
20
|
- [Installation](#installation)
|
|
21
21
|
- [Build Your Barcode Scanner App](#build-your-barcode-scanner-app)
|
|
22
|
-
- [
|
|
22
|
+
- [Set up Development Environment](#set-up-development-environment)
|
|
23
|
+
- [Initialize the Project](#initialize-the-project)
|
|
23
24
|
- [Include the Library](#include-the-library)
|
|
24
25
|
- [Configure the Barcode Reader](#configure-the-barcode-reader)
|
|
25
26
|
- [Rendering the UI](#rendering-the-ui)
|
|
@@ -71,6 +72,10 @@
|
|
|
71
72
|
|
|
72
73
|
Now you will learn how to create a simple barcode scanner using Dynamsoft Capture Vision SDK.
|
|
73
74
|
|
|
75
|
+
### Set up Development Environment
|
|
76
|
+
|
|
77
|
+
If you are a beginner on React Native, please follow the guide on <a href="https://reactnative.dev/docs/environment-setup" target="_blank">React Native official website</a> to set up the development environment.
|
|
78
|
+
|
|
74
79
|
### Initialize the Project
|
|
75
80
|
|
|
76
81
|
Create a new React Native project.
|
|
@@ -83,7 +88,19 @@ npx react-native init SimpleBarcodeScanner
|
|
|
83
88
|
|
|
84
89
|
### Include the Library
|
|
85
90
|
|
|
86
|
-
Add the SDK to your new project.
|
|
91
|
+
Add the SDK to your new project. Once the SDK is added, you will see a reference to it in the **package.json**.
|
|
92
|
+
|
|
93
|
+
- **yarn**
|
|
94
|
+
|
|
95
|
+
```bash
|
|
96
|
+
yarn add dynamsoft-capture-vision-react-native
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
- **npm**
|
|
100
|
+
|
|
101
|
+
```bash
|
|
102
|
+
npm install dynamsoft-capture-vision-react-native
|
|
103
|
+
```
|
|
87
104
|
|
|
88
105
|
For iOS, you must install the necessary native frameworks from cocoapods to run the application. In order to do this, the `pod install` command needs to be run as such:
|
|
89
106
|
|
|
@@ -105,10 +122,7 @@ import {Text} from 'react-native';
|
|
|
105
122
|
import {
|
|
106
123
|
DynamsoftBarcodeReader,
|
|
107
124
|
DynamsoftCameraView,
|
|
108
|
-
|
|
109
|
-
EnumDBRPresetTemplate,
|
|
110
|
-
EnumBarcodeFormat,
|
|
111
|
-
DBRRuntimeSettings
|
|
125
|
+
EnumBarcodeFormat
|
|
112
126
|
} from 'dynamsoft-capture-vision-react-native';
|
|
113
127
|
```
|
|
114
128
|
|
|
@@ -126,37 +140,47 @@ export default App;
|
|
|
126
140
|
Next is the `componentDidMount` implementation. First up is adding the code to start barcode decoding:
|
|
127
141
|
|
|
128
142
|
```js
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
143
|
+
class App extends React.Component {
|
|
144
|
+
...
|
|
145
|
+
componentDidMount() {
|
|
146
|
+
(async () => {
|
|
147
|
+
// Initialize the license so that you can use full feature of the Barcode Reader module.
|
|
148
|
+
try {
|
|
149
|
+
await DynamsoftBarcodeReader.initLicense("DLS2eyJvcmdhbml6YXRpb25JRCI6IjIwMDAwMSJ9");
|
|
150
|
+
} catch (e) {
|
|
151
|
+
console.log(e);
|
|
152
|
+
}
|
|
153
|
+
// Create a barcode reader instance.
|
|
154
|
+
this.reader = await DynamsoftBarcodeReader.createInstance();
|
|
155
|
+
|
|
156
|
+
// Add a result listener. The result listener will handle callback when barcode result is returned.
|
|
157
|
+
this.reader.addResultListener((results) => {
|
|
158
|
+
// Update the newly detected barcode results to the state.
|
|
159
|
+
this.setState({results});
|
|
160
|
+
});
|
|
161
|
+
|
|
162
|
+
// Enable video barcode scanning.
|
|
163
|
+
// If the camera is opened, the barcode reader will start the barcode decoding thread when you triggered the startScanning.
|
|
164
|
+
// The barcode reader will scan the barcodes continuously before you trigger stopScanning.
|
|
165
|
+
this.reader.startScanning();
|
|
166
|
+
})();
|
|
167
|
+
}
|
|
168
|
+
...
|
|
149
169
|
}
|
|
150
170
|
```
|
|
151
171
|
|
|
152
172
|
After implementing `componentDidMount`, `componentWillUnmount` will then include code to stop the barcode decoding and remove the result listener.
|
|
153
173
|
|
|
154
174
|
```js
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
175
|
+
class App extends React.Component {
|
|
176
|
+
...
|
|
177
|
+
async componentWillUnmount() {
|
|
178
|
+
// Stop the barcode decoding thread when your component is unmount.
|
|
179
|
+
await this.reader.stopScanning();
|
|
180
|
+
// Remove the result listener when your component is unmount.
|
|
181
|
+
this.reader.removeAllResultListeners();
|
|
182
|
+
}
|
|
183
|
+
...
|
|
160
184
|
}
|
|
161
185
|
```
|
|
162
186
|
|
|
@@ -164,35 +188,42 @@ async componentWillUnmount() {
|
|
|
164
188
|
|
|
165
189
|
Lastly, let's create the `DynamsoftCameraView` UI component in the `render` function.
|
|
166
190
|
|
|
167
|
-
```
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
191
|
+
```jsx
|
|
192
|
+
class App extends React.Component {
|
|
193
|
+
...
|
|
194
|
+
render() {
|
|
195
|
+
// Add code to fetch barcode text and format from the BarcodeResult
|
|
196
|
+
let results = this.state.results;
|
|
197
|
+
let resultBoxText = "";
|
|
198
|
+
if (results && results.length>0){
|
|
199
|
+
for (let i=0;i<results.length;i++){
|
|
200
|
+
resultBoxText+=results[i].barcodeFormatString+"\n"+results[i].barcodeText+"\n";
|
|
201
|
+
}
|
|
175
202
|
}
|
|
203
|
+
// Render DynamsoftCameraView componment.
|
|
204
|
+
return (
|
|
205
|
+
<DynamsoftCameraView
|
|
206
|
+
style={
|
|
207
|
+
{
|
|
208
|
+
flex: 1
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
ref = {(ref)=>{this.scanner = ref}}
|
|
212
|
+
overlayVisible={true}
|
|
213
|
+
>
|
|
214
|
+
{/*Add a text box to display the barcode result.*/}
|
|
215
|
+
<Text style={
|
|
216
|
+
{
|
|
217
|
+
flex: 0.9,
|
|
218
|
+
marginTop: 100,
|
|
219
|
+
textAlign: "center",
|
|
220
|
+
color: "white",
|
|
221
|
+
fontSize: 18,
|
|
222
|
+
}
|
|
223
|
+
}>{results && results.length > 0 ? resultBoxText : "No Barcode Detected"}</Text>
|
|
224
|
+
</DynamsoftCameraView>
|
|
225
|
+
);
|
|
176
226
|
}
|
|
177
|
-
// Render DynamsoftCameraView componment.
|
|
178
|
-
return (
|
|
179
|
-
<DynamsoftCameraView
|
|
180
|
-
style={{
|
|
181
|
-
flex: 1,
|
|
182
|
-
}}
|
|
183
|
-
ref = {(ref)=>{this.scanner = ref}}
|
|
184
|
-
isOverlayVisible={true}
|
|
185
|
-
>
|
|
186
|
-
// Add a text box to display the barcode result.
|
|
187
|
-
<Text style={{
|
|
188
|
-
flex: 0.9,
|
|
189
|
-
marginTop: 100,
|
|
190
|
-
textAlign: "center",
|
|
191
|
-
color: "white",
|
|
192
|
-
fontSize: 18,
|
|
193
|
-
}}>{results && results.length > 0 ? resultBoxText : "No Barcode Detected"}</Text>
|
|
194
|
-
</DynamsoftCameraView>
|
|
195
|
-
);
|
|
196
227
|
}
|
|
197
228
|
```
|
|
198
229
|
|
|
@@ -228,7 +259,7 @@ npx react-native run-ios
|
|
|
228
259
|
|
|
229
260
|
You can view all the DCV React Native samples via the following links:
|
|
230
261
|
|
|
231
|
-
- <a href = "https://github.com/Dynamsoft/capture-vision-react-native-samples/BarcodeReaderSimpleSample" target = "_blank" >Barcode reader simple sample</a>
|
|
262
|
+
- <a href = "https://github.com/Dynamsoft/capture-vision-react-native-samples/tree/main/BarcodeReaderSimpleSample" target = "_blank" >Barcode reader simple sample</a>
|
|
232
263
|
|
|
233
264
|
## API References
|
|
234
265
|
|
|
@@ -244,4 +275,4 @@ View the API reference of DCV React Native Edition to explore the full feature o
|
|
|
244
275
|
|
|
245
276
|
## Contact
|
|
246
277
|
|
|
247
|
-
https://www.dynamsoft.com/company/contact/
|
|
278
|
+
https://www.dynamsoft.com/company/contact/
|
package/android/build.gradle
CHANGED
|
@@ -46,8 +46,8 @@ rootProject.allprojects {
|
|
|
46
46
|
}
|
|
47
47
|
|
|
48
48
|
dependencies {
|
|
49
|
-
implementation 'com.dynamsoft:dynamsoftcameraenhancer:2.
|
|
50
|
-
implementation 'com.dynamsoft:dynamsoftbarcodereader:9.
|
|
49
|
+
implementation 'com.dynamsoft:dynamsoftcameraenhancer:2.3.0@aar'
|
|
50
|
+
implementation 'com.dynamsoft:dynamsoftbarcodereader:9.2.10@aar'
|
|
51
51
|
|
|
52
52
|
implementation 'com.facebook.react:react-native:+'
|
|
53
53
|
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (C) 2016 The Android Open Source Project
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this file except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
package com.dynamsoft.reactlibrary;
|
|
17
|
+
|
|
18
|
+
public interface Constants {
|
|
19
|
+
int TORCH_OFF = 0;
|
|
20
|
+
int TORCH_ON = 1;
|
|
21
|
+
// int FLASH_TORCH = 2;
|
|
22
|
+
// int FLASH_AUTO = 3;
|
|
23
|
+
}
|
|
@@ -1,42 +1,21 @@
|
|
|
1
1
|
package com.dynamsoft.reactlibrary;
|
|
2
2
|
|
|
3
|
+
import com.dynamsoft.dce.CameraEnhancer;
|
|
3
4
|
import com.dynamsoft.dce.CameraEnhancerException;
|
|
4
5
|
import com.dynamsoft.dce.DCECameraView;
|
|
5
|
-
import com.dynamsoft.dce.DCEFrame;
|
|
6
|
-
import com.dynamsoft.dce.DCEFrameListener;
|
|
7
|
-
import com.dynamsoft.dce.EnumResolution;
|
|
8
|
-
import com.facebook.react.bridge.Arguments;
|
|
9
6
|
import com.facebook.react.bridge.LifecycleEventListener;
|
|
10
7
|
import com.facebook.react.bridge.ReactApplicationContext;
|
|
11
|
-
import com.facebook.react.bridge.ReactContext;
|
|
12
|
-
import com.facebook.react.bridge.WritableMap;
|
|
13
|
-
import com.facebook.react.modules.core.DeviceEventManagerModule;
|
|
14
8
|
import com.facebook.react.uimanager.ThemedReactContext;
|
|
15
|
-
import static com.dynamsoft.reactlibrary.RNDCECameraViewManager.mCamera;
|
|
16
9
|
|
|
17
10
|
public class RNDCECameraView extends DCECameraView implements LifecycleEventListener {
|
|
18
11
|
|
|
19
|
-
|
|
12
|
+
CameraEnhancer mCamera;
|
|
13
|
+
|
|
14
|
+
public RNDCECameraView(ThemedReactContext context, ReactApplicationContext appContext, CameraEnhancer cameraEnhancer) {
|
|
20
15
|
super(context);
|
|
21
16
|
context.addLifecycleEventListener(this);
|
|
17
|
+
mCamera = cameraEnhancer;
|
|
22
18
|
mCamera.setCameraView(this);
|
|
23
|
-
// mCamera.addListener(new DCEFrameListener() {
|
|
24
|
-
// @Override
|
|
25
|
-
// public void frameOutputCallback(DCEFrame dceFrame, long l) {
|
|
26
|
-
// WritableMap frame = Arguments.createMap();
|
|
27
|
-
// frame.putInt("id",dceFrame.getFrameId());
|
|
28
|
-
// frame.putInt("width",dceFrame.getWidth());
|
|
29
|
-
// frame.putInt("height",dceFrame.getHeight());
|
|
30
|
-
// frame.putInt("stride",dceFrame.getStrides()[0]);
|
|
31
|
-
// frame.putInt("dataLength",dceFrame.getImageData().length);
|
|
32
|
-
// frame.putInt("format",dceFrame.getPixelFormat());
|
|
33
|
-
//
|
|
34
|
-
// ReactContext reactContext = (ReactContext)getContext();
|
|
35
|
-
// reactContext.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class).emit(
|
|
36
|
-
// "getFrameFromBuffer",
|
|
37
|
-
// frame);
|
|
38
|
-
// }
|
|
39
|
-
// });
|
|
40
19
|
}
|
|
41
20
|
|
|
42
21
|
@Override
|
|
@@ -1,11 +1,14 @@
|
|
|
1
1
|
package com.dynamsoft.reactlibrary;
|
|
2
2
|
|
|
3
|
-
import android.
|
|
4
|
-
import android.
|
|
3
|
+
import android.graphics.Bitmap;
|
|
4
|
+
import android.graphics.BitmapFactory;
|
|
5
|
+
import android.graphics.Point;
|
|
6
|
+
import android.graphics.drawable.BitmapDrawable;
|
|
7
|
+
import android.graphics.drawable.Drawable;
|
|
8
|
+
import android.util.Base64;
|
|
5
9
|
|
|
6
10
|
import com.dynamsoft.dce.CameraEnhancer;
|
|
7
11
|
import com.dynamsoft.dce.CameraEnhancerException;
|
|
8
|
-
import com.dynamsoft.dce.EnumResolution;
|
|
9
12
|
import com.dynamsoft.dce.RegionDefinition;
|
|
10
13
|
import com.facebook.react.bridge.ReactApplicationContext;
|
|
11
14
|
import com.facebook.react.bridge.ReadableArray;
|
|
@@ -15,11 +18,8 @@ import com.facebook.react.uimanager.ThemedReactContext;
|
|
|
15
18
|
import com.facebook.react.uimanager.ViewGroupManager;
|
|
16
19
|
import com.facebook.react.uimanager.annotations.ReactProp;
|
|
17
20
|
|
|
18
|
-
import java.lang.reflect.Field;
|
|
19
|
-
import java.lang.reflect.InvocationTargetException;
|
|
20
21
|
import java.util.HashMap;
|
|
21
22
|
import java.util.Map;
|
|
22
|
-
import java.util.Objects;
|
|
23
23
|
|
|
24
24
|
import javax.annotation.Nullable;
|
|
25
25
|
|
|
@@ -30,11 +30,16 @@ public class RNDCECameraViewManager extends ViewGroupManager<RNDCECameraView> {
|
|
|
30
30
|
private static final int CLOSE_COMMAND = 2;
|
|
31
31
|
|
|
32
32
|
ReactApplicationContext mReactApplicationContext;
|
|
33
|
-
|
|
33
|
+
CameraEnhancer mCamera;
|
|
34
|
+
RNDynamsoftBarcodeReaderModule mDbrModule;
|
|
34
35
|
|
|
35
|
-
public RNDCECameraViewManager(ReactApplicationContext reactContext) {
|
|
36
|
+
public RNDCECameraViewManager(ReactApplicationContext reactContext, RNDynamsoftBarcodeReaderModule dbrModule) {
|
|
36
37
|
mReactApplicationContext = reactContext;
|
|
37
|
-
|
|
38
|
+
mDbrModule = dbrModule;
|
|
39
|
+
if (dbrModule.getActivity() != null) {
|
|
40
|
+
mCamera = new CameraEnhancer(dbrModule.getActivity());
|
|
41
|
+
dbrModule.mCamera = mCamera;
|
|
42
|
+
}
|
|
38
43
|
}
|
|
39
44
|
|
|
40
45
|
private static final String REACT_CLASS = "DYSCameraView";
|
|
@@ -44,47 +49,94 @@ public class RNDCECameraViewManager extends ViewGroupManager<RNDCECameraView> {
|
|
|
44
49
|
return REACT_CLASS;
|
|
45
50
|
}
|
|
46
51
|
|
|
47
|
-
|
|
48
|
-
|
|
52
|
+
@Override
|
|
53
|
+
protected RNDCECameraView createViewInstance(ThemedReactContext reactContext) {
|
|
54
|
+
if (mCamera == null) {
|
|
55
|
+
mCamera = new CameraEnhancer(mDbrModule.getActivity());
|
|
56
|
+
mDbrModule.mCamera = mCamera;
|
|
57
|
+
}
|
|
58
|
+
return new RNDCECameraView(reactContext, mReactApplicationContext, mCamera);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
@ReactProp(name = "overlayVisible")
|
|
62
|
+
public void setOverlayVisible(RNDCECameraView view, boolean isVisible) {
|
|
63
|
+
view.setOverlayVisible(isVisible);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
@ReactProp(name = "torchState")
|
|
67
|
+
public void setTorchState(RNDCECameraView view, int torchState) {
|
|
49
68
|
try {
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
Map activities = (Map) activitiesField.get(activityThread);
|
|
55
|
-
for (Object activityRecord : activities.values()) {
|
|
56
|
-
Class activityRecordClass = activityRecord.getClass();
|
|
57
|
-
Field pausedField = activityRecordClass.getDeclaredField("paused");
|
|
58
|
-
pausedField.setAccessible(true);
|
|
59
|
-
if (!pausedField.getBoolean(activityRecord)) {
|
|
60
|
-
Field activityField = activityRecordClass.getDeclaredField("activity");
|
|
61
|
-
activityField.setAccessible(true);
|
|
62
|
-
Activity activity = (Activity) activityField.get(activityRecord);
|
|
63
|
-
return activity;
|
|
64
|
-
}
|
|
69
|
+
if (torchState == Constants.TORCH_ON) {
|
|
70
|
+
mCamera.turnOnTorch();
|
|
71
|
+
} else if (torchState == Constants.TORCH_OFF) {
|
|
72
|
+
mCamera.turnOffTorch();
|
|
65
73
|
}
|
|
66
|
-
} catch (
|
|
67
|
-
e.printStackTrace();
|
|
68
|
-
} catch (NoSuchMethodException e) {
|
|
69
|
-
e.printStackTrace();
|
|
70
|
-
} catch (IllegalAccessException e) {
|
|
71
|
-
e.printStackTrace();
|
|
72
|
-
} catch (InvocationTargetException e) {
|
|
73
|
-
e.printStackTrace();
|
|
74
|
-
} catch (NoSuchFieldException e) {
|
|
74
|
+
} catch (CameraEnhancerException e) {
|
|
75
75
|
e.printStackTrace();
|
|
76
76
|
}
|
|
77
|
-
return null;
|
|
78
77
|
}
|
|
79
78
|
|
|
80
|
-
@
|
|
81
|
-
|
|
82
|
-
|
|
79
|
+
@ReactProp(name = "torchButton")
|
|
80
|
+
public void setTorchButton(RNDCECameraView view, ReadableMap torchButton) {
|
|
81
|
+
if (torchButton != null) {
|
|
82
|
+
boolean isVisible = (torchButton.hasKey("visible") && !torchButton.isNull("visible")) ? torchButton.getBoolean("visible") : false;
|
|
83
|
+
if (isVisible) {
|
|
84
|
+
ReadableMap location = torchButton.getMap("location");
|
|
85
|
+
Point startPoint;
|
|
86
|
+
int width;
|
|
87
|
+
int height;
|
|
88
|
+
if (location != null) {
|
|
89
|
+
int x = (location.hasKey("x") && !location.isNull("x")) ? location.getInt("x") : 25;
|
|
90
|
+
int y = (location.hasKey("y") && !location.isNull("y")) ? location.getInt("y") : 100;
|
|
91
|
+
startPoint = new Point(x, y);
|
|
92
|
+
width = (location.hasKey("width") && !location.isNull("width")) ? location.getInt("width") : 45;
|
|
93
|
+
height = (location.hasKey("height") && !location.isNull("height")) ? location.getInt("height") : 45;
|
|
94
|
+
} else {
|
|
95
|
+
// Default location. Unit is dp.
|
|
96
|
+
startPoint = new Point(25, 100);
|
|
97
|
+
width = 45;
|
|
98
|
+
height = 45;
|
|
99
|
+
}
|
|
100
|
+
String torchOnImageBase64 = torchButton.getString("torchOnImageBase64");
|
|
101
|
+
String torchOffImageBase64 = torchButton.getString("torchOffImageBase64");
|
|
102
|
+
Drawable torchOnDrawable = bitmapToDrawable((base64ToBitmap(torchOnImageBase64)));
|
|
103
|
+
Drawable torchOffDrawable = bitmapToDrawable((base64ToBitmap(torchOffImageBase64)));
|
|
104
|
+
view.setTorchButton(startPoint, width, height, torchOnDrawable, torchOffDrawable);
|
|
105
|
+
view.setTorchButtonVisible(true);
|
|
106
|
+
} else {
|
|
107
|
+
view.setTorchButtonVisible(false);
|
|
108
|
+
}
|
|
109
|
+
}
|
|
83
110
|
}
|
|
84
111
|
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
112
|
+
private static Bitmap base64ToBitmap(String base64Data) {
|
|
113
|
+
if (base64Data == null) {
|
|
114
|
+
return null;
|
|
115
|
+
}
|
|
116
|
+
byte[] bytes = Base64.decode(base64Data, Base64.DEFAULT);
|
|
117
|
+
if (bytes != null) {
|
|
118
|
+
BitmapFactory.Options options = new BitmapFactory.Options();
|
|
119
|
+
options.inJustDecodeBounds = true;
|
|
120
|
+
BitmapFactory.decodeByteArray(bytes, 0, bytes.length, options);
|
|
121
|
+
if (options.outWidth * options.outHeight > 2000 * 2000) {
|
|
122
|
+
options.inTargetDensity = options.outWidth * options.outHeight;
|
|
123
|
+
options.inDensity = 2000 * 2000;
|
|
124
|
+
}
|
|
125
|
+
options.inJustDecodeBounds = false;
|
|
126
|
+
return BitmapFactory.decodeByteArray(bytes, 0, bytes.length, options);
|
|
127
|
+
} else {
|
|
128
|
+
return null;
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
private Drawable bitmapToDrawable(Bitmap bitmap) {
|
|
133
|
+
if (bitmap != null) {
|
|
134
|
+
BitmapDrawable bd = new BitmapDrawable(mReactApplicationContext.getResources(), bitmap);
|
|
135
|
+
Drawable img = bd;
|
|
136
|
+
return img;
|
|
137
|
+
} else {
|
|
138
|
+
return null;
|
|
139
|
+
}
|
|
88
140
|
}
|
|
89
141
|
|
|
90
142
|
@ReactProp(name = "scanRegionVisible")
|
package/android/src/main/java/com/dynamsoft/reactlibrary/RNDynamsoftBarcodeReaderModule.java
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
|
|
2
2
|
package com.dynamsoft.reactlibrary;
|
|
3
3
|
|
|
4
|
+
import android.app.Activity;
|
|
4
5
|
import android.util.Log;
|
|
5
6
|
|
|
6
7
|
import com.dynamsoft.dbr.BarcodeReader;
|
|
@@ -15,6 +16,7 @@ import com.dynamsoft.dbr.Point;
|
|
|
15
16
|
import com.dynamsoft.dbr.PublicRuntimeSettings;
|
|
16
17
|
import com.dynamsoft.dbr.TextResult;
|
|
17
18
|
import com.dynamsoft.dbr.TextResultListener;
|
|
19
|
+
import com.dynamsoft.dce.CameraEnhancer;
|
|
18
20
|
import com.facebook.react.bridge.Arguments;
|
|
19
21
|
import com.facebook.react.bridge.Promise;
|
|
20
22
|
import com.facebook.react.bridge.ReactApplicationContext;
|
|
@@ -24,8 +26,11 @@ import com.facebook.react.bridge.ReadableMap;
|
|
|
24
26
|
import com.facebook.react.bridge.WritableArray;
|
|
25
27
|
import com.facebook.react.bridge.WritableMap;
|
|
26
28
|
import com.facebook.react.modules.core.DeviceEventManagerModule;
|
|
29
|
+
import java.util.Collections;
|
|
30
|
+
import java.util.HashMap;
|
|
31
|
+
import java.util.Map;
|
|
32
|
+
import javax.annotation.Nullable;
|
|
27
33
|
|
|
28
|
-
import static com.dynamsoft.reactlibrary.RNDCECameraViewManager.mCamera;
|
|
29
34
|
|
|
30
35
|
public class RNDynamsoftBarcodeReaderModule extends ReactContextBaseJavaModule {
|
|
31
36
|
|
|
@@ -33,6 +38,7 @@ public class RNDynamsoftBarcodeReaderModule extends ReactContextBaseJavaModule {
|
|
|
33
38
|
private BarcodeReader mReader;
|
|
34
39
|
|
|
35
40
|
private boolean mIsCameraAttached;
|
|
41
|
+
CameraEnhancer mCamera;
|
|
36
42
|
|
|
37
43
|
public RNDynamsoftBarcodeReaderModule(ReactApplicationContext reactContext) {
|
|
38
44
|
super(reactContext);
|
|
@@ -40,11 +46,35 @@ public class RNDynamsoftBarcodeReaderModule extends ReactContextBaseJavaModule {
|
|
|
40
46
|
mIsCameraAttached = false;
|
|
41
47
|
}
|
|
42
48
|
|
|
49
|
+
|
|
50
|
+
protected Activity getActivity() {
|
|
51
|
+
return super.getCurrentActivity();
|
|
52
|
+
}
|
|
53
|
+
|
|
43
54
|
@Override
|
|
44
55
|
public String getName() {
|
|
45
56
|
return "RNDynamsoftBarcodeReader";
|
|
46
57
|
}
|
|
47
58
|
|
|
59
|
+
@Nullable
|
|
60
|
+
@Override
|
|
61
|
+
public Map<String, Object> getConstants() {
|
|
62
|
+
return Collections.unmodifiableMap(new HashMap<String, Object>() {
|
|
63
|
+
{
|
|
64
|
+
put("TorchState", getFlashModeConstants());
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
private Map<String, Object> getFlashModeConstants(){
|
|
68
|
+
return Collections.unmodifiableMap(new HashMap<String, Object>() {
|
|
69
|
+
{
|
|
70
|
+
put("off", Constants.TORCH_OFF);
|
|
71
|
+
put("on", Constants.TORCH_ON);
|
|
72
|
+
}
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
});
|
|
77
|
+
}
|
|
48
78
|
|
|
49
79
|
@ReactMethod
|
|
50
80
|
public void initLicense(String license, final Promise promise) {
|
|
@@ -99,7 +129,6 @@ public class RNDynamsoftBarcodeReaderModule extends ReactContextBaseJavaModule {
|
|
|
99
129
|
|
|
100
130
|
}
|
|
101
131
|
|
|
102
|
-
|
|
103
132
|
@ReactMethod
|
|
104
133
|
public void startBarcodeScanning() {
|
|
105
134
|
if (!mIsCameraAttached) {
|
|
@@ -190,7 +219,7 @@ public class RNDynamsoftBarcodeReaderModule extends ReactContextBaseJavaModule {
|
|
|
190
219
|
promise.reject(e.getErrorCode() + "", e.getCause());
|
|
191
220
|
}
|
|
192
221
|
promise.resolve(settingsMap);
|
|
193
|
-
//
|
|
222
|
+
// return settingsMap;
|
|
194
223
|
}
|
|
195
224
|
|
|
196
225
|
private WritableArray serializeResults(TextResult[] barcodes) {
|
package/android/src/main/java/com/dynamsoft/reactlibrary/RNDynamsoftCaptrueVisionPackage.java
CHANGED
|
@@ -1,19 +1,29 @@
|
|
|
1
1
|
|
|
2
2
|
package com.dynamsoft.reactlibrary;
|
|
3
3
|
|
|
4
|
+
|
|
4
5
|
import java.util.Arrays;
|
|
5
6
|
import java.util.Collections;
|
|
6
7
|
import java.util.List;
|
|
7
8
|
|
|
9
|
+
import com.dynamsoft.dce.CameraEnhancer;
|
|
8
10
|
import com.facebook.react.ReactPackage;
|
|
9
11
|
import com.facebook.react.bridge.NativeModule;
|
|
10
12
|
import com.facebook.react.bridge.ReactApplicationContext;
|
|
11
13
|
import com.facebook.react.uimanager.ViewManager;
|
|
12
14
|
import com.facebook.react.bridge.JavaScriptModule;
|
|
13
15
|
public class RNDynamsoftCaptrueVisionPackage implements ReactPackage {
|
|
16
|
+
CameraEnhancer mCamera;
|
|
17
|
+
RNDynamsoftBarcodeReaderModule mDbrModule;
|
|
18
|
+
RNDCECameraViewManager mDCEViewManager;
|
|
19
|
+
|
|
14
20
|
@Override
|
|
15
21
|
public List<NativeModule> createNativeModules(ReactApplicationContext reactContext) {
|
|
16
|
-
|
|
22
|
+
mDbrModule = new RNDynamsoftBarcodeReaderModule(reactContext);
|
|
23
|
+
if(mDCEViewManager !=null && mDCEViewManager.mCamera != null) {
|
|
24
|
+
mDbrModule.mCamera = mDCEViewManager.mCamera;
|
|
25
|
+
}
|
|
26
|
+
return Arrays.<NativeModule>asList(mDbrModule);
|
|
17
27
|
}
|
|
18
28
|
|
|
19
29
|
// Deprecated from RN 0.47
|
|
@@ -23,6 +33,7 @@ public class RNDynamsoftCaptrueVisionPackage implements ReactPackage {
|
|
|
23
33
|
|
|
24
34
|
@Override
|
|
25
35
|
public List<ViewManager> createViewManagers(ReactApplicationContext reactContext) {
|
|
26
|
-
|
|
36
|
+
mDCEViewManager = new RNDCECameraViewManager(reactContext, mDbrModule);
|
|
37
|
+
return Arrays.<ViewManager>asList(mDCEViewManager);
|
|
27
38
|
}
|
|
28
39
|
}
|
|
@@ -15,8 +15,8 @@ Pod::Spec.new do |s|
|
|
|
15
15
|
s.requires_arc = true
|
|
16
16
|
s.module_name = "RNDynamsoftCaptureVision"
|
|
17
17
|
s.header_dir = "RNDynamsoftCaptureVision"
|
|
18
|
-
s.dependency 'DynamsoftCameraEnhancer', '= 2.1
|
|
19
|
-
s.dependency 'DynamsoftBarcodeReader', '= 9.
|
|
18
|
+
s.dependency 'DynamsoftCameraEnhancer', '= 2.3.1'
|
|
19
|
+
s.dependency 'DynamsoftBarcodeReader', '= 9.2.11'
|
|
20
20
|
|
|
21
21
|
s.dependency "React"
|
|
22
22
|
end
|
|
@@ -1,26 +1,30 @@
|
|
|
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
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
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) int torchState;
|
|
20
|
+
|
|
21
|
+
@property (nonatomic, strong, nullable) NSDictionary *scanRegion;
|
|
22
|
+
|
|
23
|
+
@property (nonatomic, strong, nullable) NSDictionary *torchButton;
|
|
24
|
+
|
|
25
|
+
- (void)open;
|
|
26
|
+
- (void)close;
|
|
27
|
+
|
|
28
|
+
@end
|
|
29
|
+
|
|
30
|
+
NS_ASSUME_NONNULL_END
|