dynamsoft-capture-vision-react-native 1.1.2 → 1.1.3
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 +278 -278
- package/android/build.gradle +54 -54
- package/android/src/main/AndroidManifest.xml +5 -5
- package/android/src/main/java/com/dynamsoft/reactlibrary/Constants.java +23 -23
- package/android/src/main/java/com/dynamsoft/reactlibrary/RNDynamsoftBarcodeReaderModule.java +282 -282
- package/android/src/main/java/com/dynamsoft/reactlibrary/RNDynamsoftCaptrueVisionPackage.java +38 -38
- package/dynamsoft-capture-vision-react-native.podspec +22 -22
- package/ios/RNDynamsoftCaptureVision/DYSCameraView.m +8 -4
- package/js/BarcodeResult.d.ts +25 -25
- package/js/BarcodeResult.js +2 -2
- package/js/BasicStructures.d.ts +20 -20
- package/js/BasicStructures.js +2 -2
- package/js/CameraSettings.d.ts +11 -11
- package/js/CameraSettings.js +8 -8
- package/js/DynamsoftBarcodeReader.js +75 -75
- package/package.json +38 -38
package/README.md
CHANGED
|
@@ -1,278 +1,278 @@
|
|
|
1
|
-
# Dynamsoft Capture Vision React-Native Edition
|
|
2
|
-
|
|
3
|
-

|
|
4
|
-

|
|
5
|
-

|
|
6
|
-

|
|
7
|
-
|
|
8
|
-
<a href="https://www.dynamsoft.com/capture-vision/docs/introduction/">Dynamsoft Capture Vision (DCV) </a> is an aggregating SDK of a series of specific functional products including:
|
|
9
|
-
|
|
10
|
-
- Dynamsoft Camera Enhancer (DCE) which provides camera enhancements and UI configuration APIs.
|
|
11
|
-
- Dynamsoft Barcode Reader (DBR) which provides barcode decoding algorithm and APIs.
|
|
12
|
-
- Dynamsoft Label Recognizer (DLR) which provides label content recognizing algorithm and APIs.
|
|
13
|
-
- Dynamsoft Document Normalizer (DDN) which provides document scanning algorithms and APIs.
|
|
14
|
-
|
|
15
|
-
>Note: DCV React-Native edition currently only includes DCE and DBR modules. DLR and DDN modules are still under development and will be included in the future.
|
|
16
|
-
|
|
17
|
-
<span style="font-size:20px">Table of Contents</span>
|
|
18
|
-
|
|
19
|
-
- [System Requirements](#system-requirements)
|
|
20
|
-
- [Installation](#installation)
|
|
21
|
-
- [Build Your Barcode Scanner App](#build-your-barcode-scanner-app)
|
|
22
|
-
- [Set up Development Environment](#set-up-development-environment)
|
|
23
|
-
- [Initialize the Project](#initialize-the-project)
|
|
24
|
-
- [Include the Library](#include-the-library)
|
|
25
|
-
- [Configure the Barcode Reader](#configure-the-barcode-reader)
|
|
26
|
-
- [Rendering the UI](#rendering-the-ui)
|
|
27
|
-
- [Configure Camera Permissions](#configure-camera-permissions)
|
|
28
|
-
- [Run the Project](#run-the-project)
|
|
29
|
-
- [Samples](#samples)
|
|
30
|
-
- [API References](#api-references)
|
|
31
|
-
- [License](#license)
|
|
32
|
-
- [Contact](#contact)
|
|
33
|
-
|
|
34
|
-
## System Requirements
|
|
35
|
-
|
|
36
|
-
### React Native
|
|
37
|
-
|
|
38
|
-
- Supported Version: 0.60 or higher
|
|
39
|
-
|
|
40
|
-
### Android
|
|
41
|
-
|
|
42
|
-
- Supported OS: Android 5.0 (API Level 21) or higher.
|
|
43
|
-
- Supported ABI: **armeabi-v7a**, **arm64-v8a**, **x86** and **x86_64**.
|
|
44
|
-
- Development Environment: Android Studio 3.4+ (Android Studio 4.2+ recommended).
|
|
45
|
-
- JDK: 1.8+
|
|
46
|
-
|
|
47
|
-
### iOS
|
|
48
|
-
|
|
49
|
-
- Supported OS: **iOS 10.0** or higher.
|
|
50
|
-
- Supported ABI: **arm64** and **x86_64**.
|
|
51
|
-
- Development Environment: Xcode 7.1 and above (Xcode 13.0+ recommended), CocoaPods 1.11.0+.
|
|
52
|
-
|
|
53
|
-
### Others
|
|
54
|
-
|
|
55
|
-
- Node: 16.15.1 recommended
|
|
56
|
-
|
|
57
|
-
## Installation
|
|
58
|
-
|
|
59
|
-
- **yarn**
|
|
60
|
-
|
|
61
|
-
```bash
|
|
62
|
-
yarn add dynamsoft-capture-vision-react-native
|
|
63
|
-
```
|
|
64
|
-
|
|
65
|
-
- **npm**
|
|
66
|
-
|
|
67
|
-
```bash
|
|
68
|
-
npm install dynamsoft-capture-vision-react-native
|
|
69
|
-
```
|
|
70
|
-
|
|
71
|
-
## Build Your Barcode Scanner App
|
|
72
|
-
|
|
73
|
-
Now you will learn how to create a simple barcode scanner using Dynamsoft Capture Vision SDK.
|
|
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
|
-
|
|
79
|
-
### Initialize the Project
|
|
80
|
-
|
|
81
|
-
Create a new React Native project.
|
|
82
|
-
|
|
83
|
-
```bash
|
|
84
|
-
npx react-native init SimpleBarcodeScanner
|
|
85
|
-
```
|
|
86
|
-
|
|
87
|
-
>Note: This sample uses react 17.0.2 and react-native 0.65.0.
|
|
88
|
-
|
|
89
|
-
### Include the Library
|
|
90
|
-
|
|
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
|
-
```
|
|
104
|
-
|
|
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:
|
|
106
|
-
|
|
107
|
-
```bash
|
|
108
|
-
cd ios
|
|
109
|
-
```
|
|
110
|
-
|
|
111
|
-
```bash
|
|
112
|
-
pod install
|
|
113
|
-
```
|
|
114
|
-
|
|
115
|
-
### Configure the Barcode Reader
|
|
116
|
-
|
|
117
|
-
In `App.js`, import the following components:
|
|
118
|
-
|
|
119
|
-
```js
|
|
120
|
-
import React from 'react';
|
|
121
|
-
import {Text} from 'react-native';
|
|
122
|
-
import {
|
|
123
|
-
DynamsoftBarcodeReader,
|
|
124
|
-
DynamsoftCameraView,
|
|
125
|
-
EnumBarcodeFormat
|
|
126
|
-
} from 'dynamsoft-capture-vision-react-native';
|
|
127
|
-
```
|
|
128
|
-
|
|
129
|
-
Next in `App.js`, let's define the `state` to your component. In the `state`, add a `results` variable, initialized to null. In the following steps, we will store the newly decoded barcodes to `results`.
|
|
130
|
-
|
|
131
|
-
```js
|
|
132
|
-
class App extends React.Component {
|
|
133
|
-
state = {
|
|
134
|
-
results: null
|
|
135
|
-
};
|
|
136
|
-
}
|
|
137
|
-
export default App;
|
|
138
|
-
```
|
|
139
|
-
|
|
140
|
-
Next is the `componentDidMount` implementation. First up is adding the code to start barcode decoding:
|
|
141
|
-
|
|
142
|
-
```js
|
|
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
|
-
...
|
|
169
|
-
}
|
|
170
|
-
```
|
|
171
|
-
|
|
172
|
-
After implementing `componentDidMount`, `componentWillUnmount` will then include code to stop the barcode decoding and remove the result listener.
|
|
173
|
-
|
|
174
|
-
```js
|
|
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
|
-
...
|
|
184
|
-
}
|
|
185
|
-
```
|
|
186
|
-
|
|
187
|
-
### Rendering the UI
|
|
188
|
-
|
|
189
|
-
Lastly, let's create the `DynamsoftCameraView` UI component in the `render` function.
|
|
190
|
-
|
|
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
|
-
}
|
|
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
|
-
);
|
|
226
|
-
}
|
|
227
|
-
}
|
|
228
|
-
```
|
|
229
|
-
|
|
230
|
-
### Configure Camera Permissions
|
|
231
|
-
|
|
232
|
-
You need to set the "Privacy - Camera Usage Description" field in the `Info.plist` file for iOS. If this property is not set, the iOS application will fail at runtime. In order to set this property, you might need to use Xcode and open the corresponding `.xcworkspace` located in the `ios` folder. Once open, you can edit the `Info.plist` to include this property.
|
|
233
|
-
|
|
234
|
-
### Run the Project
|
|
235
|
-
|
|
236
|
-
#### Run Android on Windows
|
|
237
|
-
|
|
238
|
-
In the command line interface (we recommend using Powershell), go to your project folder and run the following command:
|
|
239
|
-
|
|
240
|
-
```bash
|
|
241
|
-
npx react-native run-android
|
|
242
|
-
```
|
|
243
|
-
|
|
244
|
-
#### Run iOS on macOS
|
|
245
|
-
|
|
246
|
-
In the terminal, go to the project folder in your project:
|
|
247
|
-
|
|
248
|
-
```bash
|
|
249
|
-
npx react-native run-ios
|
|
250
|
-
```
|
|
251
|
-
|
|
252
|
-
> Note:
|
|
253
|
-
>
|
|
254
|
-
>- The application needs to run on a physical device rather than a simulator as it requires the use of the camera. If you try running it on a simulator, you will most likely run into a number of errors/failures.
|
|
255
|
-
>- On iOS, in order to run the React Native app on a physical device you will need to install the [`ios-deploy`](https://www.npmjs.com/package/ios-deploy) library. Afterwards, you can run the react native app from the terminal as such `npx react-native run-ios --device` assuming it's the only device connected to the Mac.
|
|
256
|
-
>- Alternatively on iOS, you can simply open the `xcworkspace` of the project found in the `ios` folder using Xcode and run the sample on your connected iOS device from there. The advantage that this offers is that it is easier to deal with the developer signatures for deployment in there.
|
|
257
|
-
|
|
258
|
-
## Samples
|
|
259
|
-
|
|
260
|
-
You can view all the DCV React Native samples via the following links:
|
|
261
|
-
|
|
262
|
-
- <a href = "https://github.com/Dynamsoft/capture-vision-react-native-samples/tree/main/BarcodeReaderSimpleSample" target = "_blank" >Barcode reader simple sample</a>
|
|
263
|
-
|
|
264
|
-
## API References
|
|
265
|
-
|
|
266
|
-
View the API reference of DCV React Native Edition to explore the full feature of DCV:
|
|
267
|
-
|
|
268
|
-
- <a href = "https://www.dynamsoft.com/capture-vision/docs/programming/react-native/api-reference/?ver=latest" target = "_blank" >DCV API Reference - React Native Edition</a>
|
|
269
|
-
- <a href = "https://www.dynamsoft.com/capture-vision/docs/programming/react-native/api-reference/barcode-reader.html?ver=latest" target = "_blank" >DynamsoftBarcodeReader Class</a>
|
|
270
|
-
- <a href = "https://www.dynamsoft.com/capture-vision/docs/programming/react-native/api-reference/camera-view.html?ver=latest" target = "_blank" >DynamsoftCameraEnhancer Class</a>
|
|
271
|
-
|
|
272
|
-
## License
|
|
273
|
-
|
|
274
|
-
- You can also request an extension for your trial license in the [customer portal](https://www.dynamsoft.com/customer/license/trialLicense?product=dbr&utm_source=github)
|
|
275
|
-
|
|
276
|
-
## Contact
|
|
277
|
-
|
|
278
|
-
https://www.dynamsoft.com/company/contact/
|
|
1
|
+
# Dynamsoft Capture Vision React-Native Edition
|
|
2
|
+
|
|
3
|
+

|
|
4
|
+

|
|
5
|
+

|
|
6
|
+

|
|
7
|
+
|
|
8
|
+
<a href="https://www.dynamsoft.com/capture-vision/docs/introduction/">Dynamsoft Capture Vision (DCV) </a> is an aggregating SDK of a series of specific functional products including:
|
|
9
|
+
|
|
10
|
+
- Dynamsoft Camera Enhancer (DCE) which provides camera enhancements and UI configuration APIs.
|
|
11
|
+
- Dynamsoft Barcode Reader (DBR) which provides barcode decoding algorithm and APIs.
|
|
12
|
+
- Dynamsoft Label Recognizer (DLR) which provides label content recognizing algorithm and APIs.
|
|
13
|
+
- Dynamsoft Document Normalizer (DDN) which provides document scanning algorithms and APIs.
|
|
14
|
+
|
|
15
|
+
>Note: DCV React-Native edition currently only includes DCE and DBR modules. DLR and DDN modules are still under development and will be included in the future.
|
|
16
|
+
|
|
17
|
+
<span style="font-size:20px">Table of Contents</span>
|
|
18
|
+
|
|
19
|
+
- [System Requirements](#system-requirements)
|
|
20
|
+
- [Installation](#installation)
|
|
21
|
+
- [Build Your Barcode Scanner App](#build-your-barcode-scanner-app)
|
|
22
|
+
- [Set up Development Environment](#set-up-development-environment)
|
|
23
|
+
- [Initialize the Project](#initialize-the-project)
|
|
24
|
+
- [Include the Library](#include-the-library)
|
|
25
|
+
- [Configure the Barcode Reader](#configure-the-barcode-reader)
|
|
26
|
+
- [Rendering the UI](#rendering-the-ui)
|
|
27
|
+
- [Configure Camera Permissions](#configure-camera-permissions)
|
|
28
|
+
- [Run the Project](#run-the-project)
|
|
29
|
+
- [Samples](#samples)
|
|
30
|
+
- [API References](#api-references)
|
|
31
|
+
- [License](#license)
|
|
32
|
+
- [Contact](#contact)
|
|
33
|
+
|
|
34
|
+
## System Requirements
|
|
35
|
+
|
|
36
|
+
### React Native
|
|
37
|
+
|
|
38
|
+
- Supported Version: 0.60 or higher
|
|
39
|
+
|
|
40
|
+
### Android
|
|
41
|
+
|
|
42
|
+
- Supported OS: Android 5.0 (API Level 21) or higher.
|
|
43
|
+
- Supported ABI: **armeabi-v7a**, **arm64-v8a**, **x86** and **x86_64**.
|
|
44
|
+
- Development Environment: Android Studio 3.4+ (Android Studio 4.2+ recommended).
|
|
45
|
+
- JDK: 1.8+
|
|
46
|
+
|
|
47
|
+
### iOS
|
|
48
|
+
|
|
49
|
+
- Supported OS: **iOS 10.0** or higher.
|
|
50
|
+
- Supported ABI: **arm64** and **x86_64**.
|
|
51
|
+
- Development Environment: Xcode 7.1 and above (Xcode 13.0+ recommended), CocoaPods 1.11.0+.
|
|
52
|
+
|
|
53
|
+
### Others
|
|
54
|
+
|
|
55
|
+
- Node: 16.15.1 recommended
|
|
56
|
+
|
|
57
|
+
## Installation
|
|
58
|
+
|
|
59
|
+
- **yarn**
|
|
60
|
+
|
|
61
|
+
```bash
|
|
62
|
+
yarn add dynamsoft-capture-vision-react-native
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
- **npm**
|
|
66
|
+
|
|
67
|
+
```bash
|
|
68
|
+
npm install dynamsoft-capture-vision-react-native
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
## Build Your Barcode Scanner App
|
|
72
|
+
|
|
73
|
+
Now you will learn how to create a simple barcode scanner using Dynamsoft Capture Vision SDK.
|
|
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
|
+
|
|
79
|
+
### Initialize the Project
|
|
80
|
+
|
|
81
|
+
Create a new React Native project.
|
|
82
|
+
|
|
83
|
+
```bash
|
|
84
|
+
npx react-native init SimpleBarcodeScanner
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
>Note: This sample uses react 17.0.2 and react-native 0.65.0.
|
|
88
|
+
|
|
89
|
+
### Include the Library
|
|
90
|
+
|
|
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
|
+
```
|
|
104
|
+
|
|
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:
|
|
106
|
+
|
|
107
|
+
```bash
|
|
108
|
+
cd ios
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
```bash
|
|
112
|
+
pod install
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
### Configure the Barcode Reader
|
|
116
|
+
|
|
117
|
+
In `App.js`, import the following components:
|
|
118
|
+
|
|
119
|
+
```js
|
|
120
|
+
import React from 'react';
|
|
121
|
+
import {Text} from 'react-native';
|
|
122
|
+
import {
|
|
123
|
+
DynamsoftBarcodeReader,
|
|
124
|
+
DynamsoftCameraView,
|
|
125
|
+
EnumBarcodeFormat
|
|
126
|
+
} from 'dynamsoft-capture-vision-react-native';
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
Next in `App.js`, let's define the `state` to your component. In the `state`, add a `results` variable, initialized to null. In the following steps, we will store the newly decoded barcodes to `results`.
|
|
130
|
+
|
|
131
|
+
```js
|
|
132
|
+
class App extends React.Component {
|
|
133
|
+
state = {
|
|
134
|
+
results: null
|
|
135
|
+
};
|
|
136
|
+
}
|
|
137
|
+
export default App;
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
Next is the `componentDidMount` implementation. First up is adding the code to start barcode decoding:
|
|
141
|
+
|
|
142
|
+
```js
|
|
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
|
+
...
|
|
169
|
+
}
|
|
170
|
+
```
|
|
171
|
+
|
|
172
|
+
After implementing `componentDidMount`, `componentWillUnmount` will then include code to stop the barcode decoding and remove the result listener.
|
|
173
|
+
|
|
174
|
+
```js
|
|
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
|
+
...
|
|
184
|
+
}
|
|
185
|
+
```
|
|
186
|
+
|
|
187
|
+
### Rendering the UI
|
|
188
|
+
|
|
189
|
+
Lastly, let's create the `DynamsoftCameraView` UI component in the `render` function.
|
|
190
|
+
|
|
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
|
+
}
|
|
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
|
+
);
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
```
|
|
229
|
+
|
|
230
|
+
### Configure Camera Permissions
|
|
231
|
+
|
|
232
|
+
You need to set the "Privacy - Camera Usage Description" field in the `Info.plist` file for iOS. If this property is not set, the iOS application will fail at runtime. In order to set this property, you might need to use Xcode and open the corresponding `.xcworkspace` located in the `ios` folder. Once open, you can edit the `Info.plist` to include this property.
|
|
233
|
+
|
|
234
|
+
### Run the Project
|
|
235
|
+
|
|
236
|
+
#### Run Android on Windows
|
|
237
|
+
|
|
238
|
+
In the command line interface (we recommend using Powershell), go to your project folder and run the following command:
|
|
239
|
+
|
|
240
|
+
```bash
|
|
241
|
+
npx react-native run-android
|
|
242
|
+
```
|
|
243
|
+
|
|
244
|
+
#### Run iOS on macOS
|
|
245
|
+
|
|
246
|
+
In the terminal, go to the project folder in your project:
|
|
247
|
+
|
|
248
|
+
```bash
|
|
249
|
+
npx react-native run-ios
|
|
250
|
+
```
|
|
251
|
+
|
|
252
|
+
> Note:
|
|
253
|
+
>
|
|
254
|
+
>- The application needs to run on a physical device rather than a simulator as it requires the use of the camera. If you try running it on a simulator, you will most likely run into a number of errors/failures.
|
|
255
|
+
>- On iOS, in order to run the React Native app on a physical device you will need to install the [`ios-deploy`](https://www.npmjs.com/package/ios-deploy) library. Afterwards, you can run the react native app from the terminal as such `npx react-native run-ios --device` assuming it's the only device connected to the Mac.
|
|
256
|
+
>- Alternatively on iOS, you can simply open the `xcworkspace` of the project found in the `ios` folder using Xcode and run the sample on your connected iOS device from there. The advantage that this offers is that it is easier to deal with the developer signatures for deployment in there.
|
|
257
|
+
|
|
258
|
+
## Samples
|
|
259
|
+
|
|
260
|
+
You can view all the DCV React Native samples via the following links:
|
|
261
|
+
|
|
262
|
+
- <a href = "https://github.com/Dynamsoft/capture-vision-react-native-samples/tree/main/BarcodeReaderSimpleSample" target = "_blank" >Barcode reader simple sample</a>
|
|
263
|
+
|
|
264
|
+
## API References
|
|
265
|
+
|
|
266
|
+
View the API reference of DCV React Native Edition to explore the full feature of DCV:
|
|
267
|
+
|
|
268
|
+
- <a href = "https://www.dynamsoft.com/capture-vision/docs/programming/react-native/api-reference/?ver=latest" target = "_blank" >DCV API Reference - React Native Edition</a>
|
|
269
|
+
- <a href = "https://www.dynamsoft.com/capture-vision/docs/programming/react-native/api-reference/barcode-reader.html?ver=latest" target = "_blank" >DynamsoftBarcodeReader Class</a>
|
|
270
|
+
- <a href = "https://www.dynamsoft.com/capture-vision/docs/programming/react-native/api-reference/camera-view.html?ver=latest" target = "_blank" >DynamsoftCameraEnhancer Class</a>
|
|
271
|
+
|
|
272
|
+
## License
|
|
273
|
+
|
|
274
|
+
- You can also request an extension for your trial license in the [customer portal](https://www.dynamsoft.com/customer/license/trialLicense?product=dbr&utm_source=github)
|
|
275
|
+
|
|
276
|
+
## Contact
|
|
277
|
+
|
|
278
|
+
https://www.dynamsoft.com/company/contact/
|
package/android/build.gradle
CHANGED
|
@@ -1,54 +1,54 @@
|
|
|
1
|
-
|
|
2
|
-
buildscript {
|
|
3
|
-
repositories {
|
|
4
|
-
google()
|
|
5
|
-
jcenter()
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
dependencies {
|
|
9
|
-
classpath 'com.android.tools.build:gradle:4.1.3'
|
|
10
|
-
}
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
apply plugin: 'com.android.library'
|
|
14
|
-
|
|
15
|
-
android {
|
|
16
|
-
compileSdkVersion 30
|
|
17
|
-
buildToolsVersion "30.0.3"
|
|
18
|
-
|
|
19
|
-
defaultConfig {
|
|
20
|
-
minSdkVersion 21
|
|
21
|
-
targetSdkVersion 27
|
|
22
|
-
versionCode 1
|
|
23
|
-
versionName "1.0"
|
|
24
|
-
}
|
|
25
|
-
lintOptions {
|
|
26
|
-
abortOnError false
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
repositories {
|
|
31
|
-
google()
|
|
32
|
-
jcenter()
|
|
33
|
-
mavenCentral()
|
|
34
|
-
maven {
|
|
35
|
-
// All of React Native (JS, Obj-C sources, Android binaries) is installed from npm
|
|
36
|
-
url "$rootDir/../node_modules/react-native/android"
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
rootProject.allprojects {
|
|
41
|
-
repositories {
|
|
42
|
-
maven {
|
|
43
|
-
url "https://download2.dynamsoft.com/maven/aar"
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
dependencies {
|
|
49
|
-
implementation 'com.dynamsoft:dynamsoftcameraenhancer:2.3.
|
|
50
|
-
implementation 'com.dynamsoft:dynamsoftbarcodereader:9.2.10@aar'
|
|
51
|
-
|
|
52
|
-
implementation 'com.facebook.react:react-native:+'
|
|
53
|
-
}
|
|
54
|
-
|
|
1
|
+
|
|
2
|
+
buildscript {
|
|
3
|
+
repositories {
|
|
4
|
+
google()
|
|
5
|
+
jcenter()
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
dependencies {
|
|
9
|
+
classpath 'com.android.tools.build:gradle:4.1.3'
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
apply plugin: 'com.android.library'
|
|
14
|
+
|
|
15
|
+
android {
|
|
16
|
+
compileSdkVersion 30
|
|
17
|
+
buildToolsVersion "30.0.3"
|
|
18
|
+
|
|
19
|
+
defaultConfig {
|
|
20
|
+
minSdkVersion 21
|
|
21
|
+
targetSdkVersion 27
|
|
22
|
+
versionCode 1
|
|
23
|
+
versionName "1.0"
|
|
24
|
+
}
|
|
25
|
+
lintOptions {
|
|
26
|
+
abortOnError false
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
repositories {
|
|
31
|
+
google()
|
|
32
|
+
jcenter()
|
|
33
|
+
mavenCentral()
|
|
34
|
+
maven {
|
|
35
|
+
// All of React Native (JS, Obj-C sources, Android binaries) is installed from npm
|
|
36
|
+
url "$rootDir/../node_modules/react-native/android"
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
rootProject.allprojects {
|
|
41
|
+
repositories {
|
|
42
|
+
maven {
|
|
43
|
+
url "https://download2.dynamsoft.com/maven/aar"
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
dependencies {
|
|
49
|
+
implementation 'com.dynamsoft:dynamsoftcameraenhancer:2.3.2@aar'
|
|
50
|
+
implementation 'com.dynamsoft:dynamsoftbarcodereader:9.2.10@aar'
|
|
51
|
+
|
|
52
|
+
implementation 'com.facebook.react:react-native:+'
|
|
53
|
+
}
|
|
54
|
+
|