@@ -8,6 +8,10 @@ import {
88 StyleSheet ,
99 Text ,
1010 View ,
11+ NativeModules ,
12+ Platform ,
13+ NativeEventEmitter ,
14+ DeviceEventEmitter ,
1115} from 'react-native' ;
1216
1317import AnylineOCR from 'anyline-ocr-react-native-module' ;
@@ -34,16 +38,14 @@ import TireMakeConfig from '../config/TireMakeConfig';
3438import TireSizeConfig from '../config/TireSizeConfig' ;
3539import CommercialTireIdConfig from '../config/CommercialTireIdConfig' ;
3640import OdometerConfig from '../config/OdometerConfig' ;
37- import OtaConfig from '../config/OtaConfig' ;
38- import { DeviceEventEmitter } from 'react-native' ;
39- import { Platform } from 'react-native' ;
4041import VRCConfig from '../config/VRCConfig' ;
4142import DialMeterConfig from '../config/DialMeterConfig' ;
4243import LicensePlateConfigEU from '../config/LicensePlateConfigEU' ;
4344import LicensePlateConfigUS from '../config/LicensePlateConfigUS' ;
4445import LicensePlateConfigAF from '../config/LicensePlateConfigAF' ;
4546import TINUniversalConfig from '../config/TINUniversalConfig' ;
4647import TINDOTConfig from '../config/TINDOTConfig' ;
48+ import BarcodeContinuousConfig from "../config/BarcodeContinuousConfig" ;
4749const { license } = require ( './license.js' ) ;
4850
4951// Disable Warnings
@@ -53,8 +55,14 @@ const scrollRef = React.createRef();
5355
5456const demoAppLicenseKey = license ;
5557
58+ function getPlatformEventEmitter ( ) {
59+ return Platform . select ( {
60+ ios : new NativeEventEmitter ( NativeModules ) ,
61+ android : DeviceEventEmitter ,
62+ } ) ;
63+ }
64+
5665class Anyline extends Component {
57- overTheAirUpdateIsEnabled = false ;
5866
5967 state = {
6068 hasScanned : false ,
@@ -66,6 +74,7 @@ class Anyline extends Component {
6674 SDKVersion : '' ,
6775 pluginVersion : '' ,
6876 hasMultipleResults : false ,
77+ hasContinuousResults : false ,
6978 licenseMessage : '' ,
7079 titles : [ ] ,
7180 } ;
@@ -99,27 +108,7 @@ class Anyline extends Component {
99108 }
100109
101110 updateAnyline = async type => {
102- if ( Platform . OS === 'android' && this . overTheAirUpdateIsEnabled == true ) {
103- let otaConfig = OtaConfig ;
104-
105- AnylineOCR . initSdk ( otaConfig . license ) ;
106- const onSessionConnect = ( event ) => {
107- console . log ( event . progress ) ;
108- } ;
109- DeviceEventEmitter . addListener ( 'ota_progress_update_event' , onSessionConnect ) ;
110- AnylineOCR . update (
111- JSON . stringify ( otaConfig ) ,
112- ( message ) => {
113- console . log ( `Error: ${ message } ` ) ;
114- } ,
115- ( ) => {
116- console . log ( `DONE` ) ;
117- this . openAnyline ( type )
118- }
119- )
120- } else {
121- this . openAnyline ( type ) ;
122- }
111+ this . openAnyline ( type ) ;
123112 } ;
124113
125114 _openAnyline = async ( type ) => {
@@ -131,6 +120,7 @@ class Anyline extends Component {
131120 this . setState ( {
132121 currentScanMode : type ,
133122 hasMultipleResults : false ,
123+ hasContinuousResults : false ,
134124 } ) ;
135125
136126 switch ( type ) {
@@ -146,6 +136,10 @@ class Anyline extends Component {
146136 case 'BARCODE' :
147137 config = BarcodeConfig ;
148138 break ;
139+ case 'BARCODE_CONTINUOUS' :
140+ this . setState ( { hasContinuousResults : true } ) ;
141+ config = BarcodeContinuousConfig ;
142+ break ;
149143 case 'BARCODE_PDF417' :
150144 config = BarcodePDF417Config ;
151145 break ;
@@ -241,17 +235,48 @@ class Anyline extends Component {
241235 }
242236 this . setState ( { titles } ) ;
243237 try {
238+ const anylineOCRResultEventName = 'onResultCallback' ;
239+ const maxContinuousResultCount = 10 ;
240+ const continuousResultListener = ( response ) => {
241+ console . log ( `AnylineOCR.onResult: ` + response ) ;
242+ if ( continuousResults !== "" ) {
243+ continuousResults = continuousResults + ", " ;
244+ }
245+ continuousResults = continuousResults + response ;
246+ continuousCount ++ ;
247+ if ( continuousCount > maxContinuousResultCount ) {
248+ AnylineOCR . tryStopScan ( null ) ;
249+ }
250+ }
251+
252+ let continuousResults = "" ;
253+ let continuousCount = 0 ;
254+
244255 const isInitialized = await AnylineOCR . isInitialized ( ) ;
245256 console . log ( `AnylineOCR.initialized: ` + isInitialized ) ;
246257 if ( ! isInitialized ) {
247258 await AnylineOCR . setupAnylineSDK ( demoAppLicenseKey ) ;
248259 }
249260
250261 console . log ( `AnylineOCR.setupPromise` ) ;
251- const result = await AnylineOCR . setupPromise (
252- JSON . stringify ( config ) ,
253- 'scan'
254- ) ;
262+ let result = "" ;
263+ if ( ! this . state . hasContinuousResults ) {
264+ result = await AnylineOCR . setupPromise (
265+ JSON . stringify ( config ) ,
266+ 'scan'
267+ ) ;
268+ } else {
269+ continuousResults = "" ;
270+ continuousCount = 0 ;
271+ getPlatformEventEmitter ( ) . addListener ( anylineOCRResultEventName , continuousResultListener ) ;
272+ result = await AnylineOCR . setupPromiseWithScanCallbackConfig (
273+ JSON . stringify ( config ) ,
274+ 'scan' ,
275+ '{ "onResultEventName": "' + anylineOCRResultEventName + '" }'
276+ ) ;
277+ result = "[" + continuousResults + "]" ;
278+ getPlatformEventEmitter ( ) . removeAllListeners ( anylineOCRResultEventName )
279+ }
255280
256281 console . log ( 'scan result: ' + result ) ;
257282
@@ -320,6 +345,7 @@ class Anyline extends Component {
320345 pluginVersion,
321346 licenseMessage,
322347 hasMultipleResults,
348+ hasContinuousResults,
323349 titles,
324350 } = this . state ;
325351
@@ -338,7 +364,7 @@ class Anyline extends Component {
338364 contentContainerStyle = { styles . ContainerContent } >
339365 < Text style = { styles . headline } > Anyline React-Native Example</ Text >
340366 { hasScanned ? (
341- hasMultipleResults ? (
367+ hasMultipleResults || hasContinuousResults ? (
342368 Object . keys ( result ) . map ( ( key , index ) => {
343369 return (
344370 < Result
0 commit comments