1- import { BarcodeFormats , barcodeFormatsProperty , CameraPosition , cameraPositionProperty , DetectionType , detectionTypeProperty , faceDetectionMinFaceSizeProperty , faceDetectionPerformanceModeProperty , faceDetectionTrackingEnabledProperty , imageLabelerConfidenceThresholdProperty , MLKitViewBase , objectDetectionClassifyProperty , objectDetectionMultipleProperty , onDetectionProperty } from "./common" ;
1+ import { BarcodeFormats , barcodeFormatsProperty , CameraPosition , cameraPositionProperty , DetectionType , detectionTypeProperty , faceDetectionMinFaceSizeProperty , faceDetectionPerformanceModeProperty , faceDetectionTrackingEnabledProperty , imageLabelerConfidenceThresholdProperty , MLKitViewBase , objectDetectionClassifyProperty , objectDetectionMultipleProperty } from "./common" ;
22import { Application , Device , Utils , AndroidActivityRequestPermissionsEventData } from '@nativescript/core' ;
33import lazy from '@nativescript/core/utils/lazy' ;
44
@@ -117,17 +117,31 @@ export class MLKitView extends MLKitViewBase {
117117 type = DetectorType_None ( ) ;
118118 break ;
119119 }
120-
121120 this . #camera. setDetectorType ( type ) ;
121+ this . #setListeners( ) ;
122+ }
123+
124+ initNativeView ( ) {
125+ super . initNativeView ( ) ;
126+ this . #setListeners( ) ;
122127 }
123128
124- [ onDetectionProperty . setNative ] ( value ) {
129+ #setListeners ( ) {
125130 const ref = new WeakRef ( this ) ;
126131 if ( ! this . #onTextListener && ( this . detectionType === DetectionType . Text || this . detectionType === DetectionType . All ) ) {
127132 this . #onTextListener = new io . github . triniwiz . fancycamera . ImageAnalysisCallback ( {
128133 onSuccess ( param0 : string ) {
134+ const hasListener = ref ?. get ?.( ) . hasListeners ?.( MLKitView . detectionEvent ) ;
135+ if ( ! hasListener ) {
136+ return ;
137+ }
129138 try {
130- ref ?. get ?.( ) . onDetection ?.( JSON . parse ( param0 ) , DetectionType . Text ) ;
139+ ref ?. get ?.( ) . notify ?.( {
140+ eventName : MLKitView . detectionEvent ,
141+ object : ref ?. get ?.( ) ,
142+ data : JSON . parse ( param0 ) ,
143+ type : DetectionType . Text
144+ } ) ;
131145 } catch ( e ) { }
132146 } ,
133147 onError ( param0 : string , param1 : java . lang . Exception ) {
@@ -140,8 +154,17 @@ export class MLKitView extends MLKitViewBase {
140154 if ( ! this . #onBarcodeListener && ( this . detectionType . includes ( DetectionType . Barcode ) || this . detectionType . includes ( DetectionType . All ) ) ) {
141155 this . #onBarcodeListener = new io . github . triniwiz . fancycamera . ImageAnalysisCallback ( {
142156 onSuccess ( param0 : string ) {
157+ const hasListener = ref ?. get ?.( ) . hasListeners ?.( MLKitView . detectionEvent ) ;
158+ if ( ! hasListener ) {
159+ return ;
160+ }
143161 try {
144- ref ?. get ?.( ) . onDetection ?.( JSON . parse ( param0 ) , DetectionType . Barcode ) ;
162+ ref ?. get ?.( ) . notify ?.( {
163+ eventName : MLKitView . detectionEvent ,
164+ object : ref ?. get ?.( ) ,
165+ data : JSON . parse ( param0 ) ,
166+ type : DetectionType . Barcode
167+ } ) ;
145168 } catch ( e ) { }
146169 } ,
147170 onError ( param0 : string , param1 : java . lang . Exception ) {
@@ -155,8 +178,17 @@ export class MLKitView extends MLKitViewBase {
155178 if ( ! this . #onDigitalInkListener && ( this . detectionType === DetectionType . DigitalInk || this . detectionType === DetectionType . All ) ) {
156179 /* this.#onDigitalInkListener = new io.github.triniwiz.fancycamera.ImageAnalysisCallback({
157180 onSuccess(param0: string) {
181+ const hasListener = ref?.get?.().hasListeners?.(MLKitView.detectionEvent);
182+ if(!hasListener){
183+ return;
184+ }
158185 try {
159- ref?.get?.().onDetection?.(JSON.parse(param0));
186+ ref?.get?.().notify?.({
187+ eventName: MLKitView.detectionEvent,
188+ object: ref?.get?.(),
189+ data: JSON.parse(param0),
190+ type: DetectionType.DigitalInk
191+ });
160192 } catch (e) { }
161193 },
162194 onError(param0: string, param1: java.lang.Exception) {
@@ -169,8 +201,17 @@ export class MLKitView extends MLKitViewBase {
169201 this . #faceDetectionOptions = new io . github . triniwiz . fancycamera . facedetection . FaceDetection . Options ( ) ;
170202 this . #onFaceListener = new io . github . triniwiz . fancycamera . ImageAnalysisCallback ( {
171203 onSuccess ( param0 : string ) {
204+ const hasListener = ref ?. get ?.( ) . hasListeners ?.( MLKitView . detectionEvent ) ;
205+ if ( ! hasListener ) {
206+ return ;
207+ }
172208 try {
173- ref ?. get ?.( ) . onDetection ?.( JSON . parse ( param0 ) , DetectionType . Face ) ;
209+ ref ?. get ?.( ) . notify ?.( {
210+ eventName : MLKitView . detectionEvent ,
211+ object : ref ?. get ?.( ) ,
212+ data : JSON . parse ( param0 ) ,
213+ type : DetectionType . Face
214+ } ) ;
174215 } catch ( e ) { }
175216 } ,
176217 onError ( param0 : string , param1 : java . lang . Exception ) {
@@ -183,8 +224,17 @@ export class MLKitView extends MLKitViewBase {
183224 if ( ! this . #onImageListener && ( this . detectionType === DetectionType . Image || this . detectionType === DetectionType . All ) ) {
184225 this . #onImageListener = new io . github . triniwiz . fancycamera . ImageAnalysisCallback ( {
185226 onSuccess ( param0 : string ) {
227+ const hasListener = ref ?. get ?.( ) . hasListeners ?.( MLKitView . detectionEvent ) ;
228+ if ( ! hasListener ) {
229+ return ;
230+ }
186231 try {
187- ref ?. get ?.( ) . onDetection ?.( JSON . parse ( param0 ) , DetectionType . Image ) ;
232+ ref ?. get ?.( ) . notify ?.( {
233+ eventName : MLKitView . detectionEvent ,
234+ object : ref ?. get ?.( ) ,
235+ data : JSON . parse ( param0 ) ,
236+ type : DetectionType . Image
237+ } ) ;
188238 } catch ( e ) { }
189239 } ,
190240 onError ( param0 : string , param1 : java . lang . Exception ) {
@@ -197,8 +247,17 @@ export class MLKitView extends MLKitViewBase {
197247 if ( ! this . #onObjectListener && ( this . detectionType === DetectionType . Object || this . detectionType === DetectionType . All ) ) {
198248 this . #onObjectListener = new io . github . triniwiz . fancycamera . ImageAnalysisCallback ( {
199249 onSuccess ( param0 : string ) {
250+ const hasListener = ref ?. get ?.( ) . hasListeners ?.( MLKitView . detectionEvent ) ;
251+ if ( ! hasListener ) {
252+ return ;
253+ }
200254 try {
201- ref ?. get ?.( ) . onDetection ?.( JSON . parse ( param0 ) , DetectionType . Object ) ;
255+ ref ?. get ?.( ) . notify ?.( {
256+ eventName : MLKitView . detectionEvent ,
257+ object : ref ?. get ?.( ) ,
258+ data : JSON . parse ( param0 ) ,
259+ type : DetectionType . Object
260+ } ) ;
202261 } catch ( e ) { }
203262 } ,
204263 onError ( param0 : string , param1 : java . lang . Exception ) {
@@ -211,8 +270,17 @@ export class MLKitView extends MLKitViewBase {
211270 if ( ! this . #onPoseListener && ( this . detectionType === DetectionType . Pose || this . detectionType === DetectionType . All ) ) {
212271 this . #onPoseListener = new io . github . triniwiz . fancycamera . ImageAnalysisCallback ( {
213272 onSuccess ( param0 : string ) {
273+ const hasListener = ref ?. get ?.( ) . hasListeners ?.( MLKitView . detectionEvent ) ;
274+ if ( ! hasListener ) {
275+ return ;
276+ }
214277 try {
215- ref ?. get ?.( ) . onDetection ?.( JSON . parse ( param0 ) , DetectionType . Pose ) ;
278+ ref ?. get ?.( ) . notify ?.( {
279+ eventName : MLKitView . detectionEvent ,
280+ object : ref ?. get ?.( ) ,
281+ data : JSON . parse ( param0 ) ,
282+ type : DetectionType . Pose
283+ } ) ;
216284 } catch ( e ) { }
217285 } ,
218286 onError ( param0 : string , param1 : java . lang . Exception ) {
@@ -233,7 +301,7 @@ export class MLKitView extends MLKitViewBase {
233301 let formats ;
234302 if ( Array . isArray ( value ) ) {
235303 if ( value . indexOf ( BarcodeFormats . ALL ) ) {
236- formats = Array . create ( 'io.github.triniwiz.fancycamera.barcodescanning.BarcodeScanner. BarcodeFormat' , 1 ) ;
304+ formats = Array . create ( 'io.github.triniwiz.fancycamera.barcodescanning.BarcodeScanner$ BarcodeFormat' , 1 ) ;
237305 formats [ 0 ] = io . github . triniwiz . fancycamera . barcodescanning . BarcodeScanner . BarcodeFormat . ALL ;
238306 } else {
239307 formats = value . map ( format => {
0 commit comments