@@ -18,54 +18,66 @@ class App extends React.Component {
1818
1919 componentDidMount ( ) {
2020 ( async ( ) => {
21+ // Initialize the license so that you can use full feature of the Barcode Reader module.
2122 try {
22- await DynamsoftBarcodeReader . initLicense ( "DLS2eyJvcmdhbml6YXRpb25JRCI6IjIwMDAwMSJ9" )
23+ await DynamsoftBarcodeReader . initLicense ( "DLS2eyJvcmdhbml6YXRpb25JRCI6IjIwMDAwMSJ9" ) ;
2324 } catch ( e ) {
24- console . log ( e )
25+ console . log ( e ) ;
2526 }
2627
27-
28+ // Create a barcode reader instance.
2829 this . reader = await DynamsoftBarcodeReader . createInstance ( ) ;
2930 await this . reader . updateRuntimeSettings ( EnumDBRPresetTemplate . DEFAULT ) ;
30- let settings : DBRRuntimeSettings = await this . reader . getRuntimeSettings ( ) ;
31+
32+ // Get the current runtime settings of the barcode reader.
33+ let settings = await this . reader . getRuntimeSettings ( ) ;
34+
3135 // Set the expected barcode count to 0 when you are not sure how many barcodes you are scanning.
3236 // Set the expected barcode count to 1 can maximize the barcode decoding speed.
3337 settings . expectedBarcodesCount = 0 ;
34- settings . barcodeFormatIds = EnumBarcodeFormat . BF_ONED | EnumBarcodeFormat . BF_QR_CODE ;
35- await this . reader . updateRuntimeSettings ( settings )
38+ // Set the barcode format to read.
39+ settings . barcodeFormatIds = EnumBarcodeFormat . BF_ONED | EnumBarcodeFormat . BF_QR_CODE | EnumBarcodeFormat . BF_PDF417 | EnumBarcodeFormat . BF_DATAMATRIX ;
40+
41+ // Apply the new runtime settings to the barcode reader.
42+ await this . reader . updateRuntimeSettings ( settings ) ;
3643
44+ // Enable video barcode scanning.
45+ // If the camera is opened, the barcode reader will start the barcode decoding thread when you triggered the startScanning.
46+ // The barcode reader will scan the barcodes continuously before you trigger stopScanning.
3747 await this . reader . startScanning ( ) ;
38- this . reader . addResultListener ( ( results : BarcodeResult [ ] ) => {
48+
49+ // Add a result listener. The result listener will handle callback when barcode result is returned.
50+ this . reader . addResultListener ( ( results ) => {
51+ // Update the newly detected barcode results to the state.
3952 this . setState ( { results : results } )
40- console . log ( results . length )
4153 } )
4254 } ) ( ) ;
4355
4456
4557 }
4658
4759 async componentWillUnmount ( ) {
60+ // Stop the barcode decoding thread when your component is unmount.
4861 await this . reader . stopScanning ( )
62+ // Remove the result listener when your component is unmount.
4963 this . reader . removeAllResultListeners ( )
5064 }
5165
52-
5366 render ( ) {
54- let region : Region ;
5567 let barcode_text = "" ;
56- region = {
68+ // Define the scan region.
69+ let region = {
5770 regionTop : 30 ,
5871 regionLeft : 15 ,
5972 regionBottom : 70 ,
6073 regionRight : 85 ,
6174 regionMeasuredByPercentage : true
6275 }
63- let results : BarcodeResult [ ] = this . state . results ;
76+ let results = this . state . results ;
6477 if ( results && results . length > 0 ) {
6578 for ( var i = 0 ; i < results . length ; i ++ ) {
6679 barcode_text += results [ i ] . barcodeFormatString + ":" + results [ i ] . barcodeText + "\n"
6780 }
68- console . log ( barcode_text ) ;
6981 }
7082
7183 return (
@@ -86,8 +98,6 @@ class App extends React.Component {
8698 fontSize : 18 ,
8799 } } > { results && results . length > 0 ? barcode_text : "null" } </ Text >
88100 </ DynamsoftCameraView >
89-
90-
91101 ) ;
92102 }
93103}
0 commit comments