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" ;
2
2
import { Application , Device , Utils , AndroidActivityRequestPermissionsEventData } from '@nativescript/core' ;
3
3
import lazy from '@nativescript/core/utils/lazy' ;
4
4
@@ -117,17 +117,31 @@ export class MLKitView extends MLKitViewBase {
117
117
type = DetectorType_None ( ) ;
118
118
break ;
119
119
}
120
-
121
120
this . #camera. setDetectorType ( type ) ;
121
+ this . #setListeners( ) ;
122
+ }
123
+
124
+ initNativeView ( ) {
125
+ super . initNativeView ( ) ;
126
+ this . #setListeners( ) ;
122
127
}
123
128
124
- [ onDetectionProperty . setNative ] ( value ) {
129
+ #setListeners ( ) {
125
130
const ref = new WeakRef ( this ) ;
126
131
if ( ! this . #onTextListener && ( this . detectionType === DetectionType . Text || this . detectionType === DetectionType . All ) ) {
127
132
this . #onTextListener = new io . github . triniwiz . fancycamera . ImageAnalysisCallback ( {
128
133
onSuccess ( param0 : string ) {
134
+ const hasListener = ref ?. get ?.( ) . hasListeners ?.( MLKitView . detectionEvent ) ;
135
+ if ( ! hasListener ) {
136
+ return ;
137
+ }
129
138
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
+ } ) ;
131
145
} catch ( e ) { }
132
146
} ,
133
147
onError ( param0 : string , param1 : java . lang . Exception ) {
@@ -140,8 +154,17 @@ export class MLKitView extends MLKitViewBase {
140
154
if ( ! this . #onBarcodeListener && ( this . detectionType . includes ( DetectionType . Barcode ) || this . detectionType . includes ( DetectionType . All ) ) ) {
141
155
this . #onBarcodeListener = new io . github . triniwiz . fancycamera . ImageAnalysisCallback ( {
142
156
onSuccess ( param0 : string ) {
157
+ const hasListener = ref ?. get ?.( ) . hasListeners ?.( MLKitView . detectionEvent ) ;
158
+ if ( ! hasListener ) {
159
+ return ;
160
+ }
143
161
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
+ } ) ;
145
168
} catch ( e ) { }
146
169
} ,
147
170
onError ( param0 : string , param1 : java . lang . Exception ) {
@@ -155,8 +178,17 @@ export class MLKitView extends MLKitViewBase {
155
178
if ( ! this . #onDigitalInkListener && ( this . detectionType === DetectionType . DigitalInk || this . detectionType === DetectionType . All ) ) {
156
179
/* this.#onDigitalInkListener = new io.github.triniwiz.fancycamera.ImageAnalysisCallback({
157
180
onSuccess(param0: string) {
181
+ const hasListener = ref?.get?.().hasListeners?.(MLKitView.detectionEvent);
182
+ if(!hasListener){
183
+ return;
184
+ }
158
185
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
+ });
160
192
} catch (e) { }
161
193
},
162
194
onError(param0: string, param1: java.lang.Exception) {
@@ -169,8 +201,17 @@ export class MLKitView extends MLKitViewBase {
169
201
this . #faceDetectionOptions = new io . github . triniwiz . fancycamera . facedetection . FaceDetection . Options ( ) ;
170
202
this . #onFaceListener = new io . github . triniwiz . fancycamera . ImageAnalysisCallback ( {
171
203
onSuccess ( param0 : string ) {
204
+ const hasListener = ref ?. get ?.( ) . hasListeners ?.( MLKitView . detectionEvent ) ;
205
+ if ( ! hasListener ) {
206
+ return ;
207
+ }
172
208
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
+ } ) ;
174
215
} catch ( e ) { }
175
216
} ,
176
217
onError ( param0 : string , param1 : java . lang . Exception ) {
@@ -183,8 +224,17 @@ export class MLKitView extends MLKitViewBase {
183
224
if ( ! this . #onImageListener && ( this . detectionType === DetectionType . Image || this . detectionType === DetectionType . All ) ) {
184
225
this . #onImageListener = new io . github . triniwiz . fancycamera . ImageAnalysisCallback ( {
185
226
onSuccess ( param0 : string ) {
227
+ const hasListener = ref ?. get ?.( ) . hasListeners ?.( MLKitView . detectionEvent ) ;
228
+ if ( ! hasListener ) {
229
+ return ;
230
+ }
186
231
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
+ } ) ;
188
238
} catch ( e ) { }
189
239
} ,
190
240
onError ( param0 : string , param1 : java . lang . Exception ) {
@@ -197,8 +247,17 @@ export class MLKitView extends MLKitViewBase {
197
247
if ( ! this . #onObjectListener && ( this . detectionType === DetectionType . Object || this . detectionType === DetectionType . All ) ) {
198
248
this . #onObjectListener = new io . github . triniwiz . fancycamera . ImageAnalysisCallback ( {
199
249
onSuccess ( param0 : string ) {
250
+ const hasListener = ref ?. get ?.( ) . hasListeners ?.( MLKitView . detectionEvent ) ;
251
+ if ( ! hasListener ) {
252
+ return ;
253
+ }
200
254
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
+ } ) ;
202
261
} catch ( e ) { }
203
262
} ,
204
263
onError ( param0 : string , param1 : java . lang . Exception ) {
@@ -211,8 +270,17 @@ export class MLKitView extends MLKitViewBase {
211
270
if ( ! this . #onPoseListener && ( this . detectionType === DetectionType . Pose || this . detectionType === DetectionType . All ) ) {
212
271
this . #onPoseListener = new io . github . triniwiz . fancycamera . ImageAnalysisCallback ( {
213
272
onSuccess ( param0 : string ) {
273
+ const hasListener = ref ?. get ?.( ) . hasListeners ?.( MLKitView . detectionEvent ) ;
274
+ if ( ! hasListener ) {
275
+ return ;
276
+ }
214
277
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
+ } ) ;
216
284
} catch ( e ) { }
217
285
} ,
218
286
onError ( param0 : string , param1 : java . lang . Exception ) {
@@ -233,7 +301,7 @@ export class MLKitView extends MLKitViewBase {
233
301
let formats ;
234
302
if ( Array . isArray ( value ) ) {
235
303
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 ) ;
237
305
formats [ 0 ] = io . github . triniwiz . fancycamera . barcodescanning . BarcodeScanner . BarcodeFormat . ALL ;
238
306
} else {
239
307
formats = value . map ( format => {
0 commit comments