Skip to content

Commit 9a7d9bc

Browse files
committed
fix: ios
1 parent 0529325 commit 9a7d9bc

18 files changed

+1393
-747
lines changed

Diff for: apps/demo/package.json

+4-4
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,14 @@
55
"repository": "<fill-your-repository-here>",
66
"dependencies": {
77
"@nativescript/core": "file:../../node_modules/@nativescript/core",
8-
"@nativescript/mlkit-text-recognition": "file:../../packages/mlkit-text-recognition",
9-
"@nativescript/mlkit-core": "file:../../packages/mlkit-core",
108
"@nativescript/mlkit-barcode-scanning": "file:../../packages/mlkit-barcode-scanning",
9+
"@nativescript/mlkit-core": "file:../../packages/mlkit-core",
10+
"@nativescript/mlkit-digital-ink-recognition": "file:../../packages/mlkit-digital-ink-recognition",
1111
"@nativescript/mlkit-face-detection": "file:../../packages/mlkit-face-detection",
1212
"@nativescript/mlkit-image-labeling": "file:../../packages/mlkit-image-labeling",
1313
"@nativescript/mlkit-object-detection": "file:../../packages/mlkit-object-detection",
14-
"@nativescript/mlkit-digital-ink-recognition": "file:../../packages/mlkit-digital-ink-recognition",
15-
"@nativescript/mlkit-pose-detection": "file:../../packages/mlkit-pose-detection"
14+
"@nativescript/mlkit-pose-detection": "file:../../packages/mlkit-pose-detection",
15+
"@nativescript/mlkit-text-recognition": "file:../../packages/mlkit-text-recognition"
1616
},
1717
"devDependencies": {
1818
"@nativescript/android": "~8.1.1",

Diff for: apps/demo/src/plugin-demos/mlkit-core.ts

+11
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,24 @@
11
import { Observable, EventData, Page } from '@nativescript/core';
22
import { DemoSharedMlkitCore } from '@demo/shared';
3+
import { MLKitView } from '@nativescript/mlkit-core';
34

45
export function navigatingTo(args: EventData) {
56
const page = <Page>args.object;
67
page.bindingContext = new DemoModel();
78
}
89

910
export class DemoModel extends DemoSharedMlkitCore {
11+
camera: MLKitView;
12+
13+
onLoaded(args){
14+
this.camera = args.object;
15+
}
16+
1017
onDetection(data) {
1118
console.log('onDetection', data);
1219
}
20+
21+
toggleCamera(){
22+
this.camera.toggleCamera();
23+
}
1324
}

Diff for: apps/demo/src/plugin-demos/mlkit-core.xml

+4-3
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
<ActionBar title="mlkit-core" icon="" class="action-bar">
44
</ActionBar>
55
</Page.actionBar>
6-
<StackLayout class="p-20">
7-
<ui:MLKitView detectionType="all" onDetection="{{ onDetection }}"/>
8-
</StackLayout>
6+
<GridLayout class="p-20">
7+
<ui:MLKitView loaded="{{ onLoaded }}" cameraPosition="back" detectionType="all" onDetection="{{ onDetection }}"/>
8+
<Button text="Toggle Camera" tap="{{ toggleCamera }}" />
9+
</GridLayout>
910
</Page>

Diff for: packages/mlkit-core/common.ts

+14-9
Original file line numberDiff line numberDiff line change
@@ -46,17 +46,22 @@ export enum FaceDetectionPerformanceMode {
4646
@CSSType('MLKitView')
4747
export class MLKitViewBase extends ContainerView {
4848
cameraPosition: CameraPosition;
49-
dectectionType: DetectionType;
50-
barcodeFormats: BarcodeFormats;
49+
detectionType: DetectionType;
50+
barcodeFormats: BarcodeFormats[];
5151
faceDetectionPerformanceMode: FaceDetectionPerformanceMode;
5252
faceDetectionTrackingEnabled: boolean;
5353
faceDetectionMinFaceSize: number;
54-
imageLablerConfidenceThreshold: number;
54+
imageLabelerConfidenceThreshold: number;
5555
objectDetectionMultiple: boolean;
5656
objectDetectionClassify: boolean;
5757
onDetection: (data) => void;
5858
}
5959

60+
export const onDetectionProperty = new Property<MLKitViewBase, (data: { [key: string]: any }) => void>({
61+
name: 'onDetection'
62+
});
63+
onDetectionProperty.register(MLKitViewBase);
64+
6065
export const cameraPositionProperty = new Property<MLKitViewBase, CameraPosition>({
6166
name: 'cameraPosition',
6267
defaultValue: CameraPosition.BACK
@@ -65,15 +70,15 @@ export const cameraPositionProperty = new Property<MLKitViewBase, CameraPosition
6570
cameraPositionProperty.register(MLKitViewBase);
6671

6772
export const detectionTypeProperty = new Property<MLKitViewBase, DetectionType>({
68-
name: 'dectectionType',
73+
name: 'detectionType',
6974
defaultValue: DetectionType.None
7075
});
7176

7277
detectionTypeProperty.register(MLKitViewBase);
7378

74-
export const barcodeFormatsProperty = new Property<MLKitViewBase, BarcodeFormats>({
79+
export const barcodeFormatsProperty = new Property<MLKitViewBase, BarcodeFormats[]>({
7580
name: 'barcodeFormats',
76-
defaultValue: BarcodeFormats.ALL
81+
defaultValue: [BarcodeFormats.ALL]
7782
})
7883

7984
barcodeFormatsProperty.register(MLKitViewBase);
@@ -104,12 +109,12 @@ export const faceDetectionMinFaceSizeProperty = new Property<MLKitViewBase, numb
104109
faceDetectionMinFaceSizeProperty.register(MLKitViewBase);
105110

106111

107-
export const imageLablerConfidenceThresholdProperty = new Property<MLKitViewBase, number>({
108-
name: 'imageLablerConfidenceThreshold',
112+
export const imageLabelerConfidenceThresholdProperty = new Property<MLKitViewBase, number>({
113+
name: 'imageLabelerConfidenceThreshold',
109114
defaultValue: 0.5
110115
});
111116

112-
imageLablerConfidenceThresholdProperty.register(MLKitViewBase);
117+
imageLabelerConfidenceThresholdProperty.register(MLKitViewBase);
113118

114119
export const objectDetectionMultipleProperty = new Property<MLKitViewBase, boolean>({
115120
name: 'objectDetectionMultiple',

Diff for: packages/mlkit-core/index.android.ts

+11-20
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { BarcodeFormats, barcodeFormatsProperty, CameraPosition, cameraPositionProperty, DetectionType, faceDetectionMinFaceSizeProperty, faceDetectionPerformanceModeProperty, faceDetectionTrackingEnabledProperty, imageLablerConfidenceThresholdProperty, MLKitViewBase, objectDetectionClassifyProperty, objectDetectionMultipleProperty } from "./common";
1+
import { BarcodeFormats, barcodeFormatsProperty, CameraPosition, cameraPositionProperty, DetectionType, faceDetectionMinFaceSizeProperty, faceDetectionPerformanceModeProperty, faceDetectionTrackingEnabledProperty, imageLablerConfidenceThresholdProperty, MLKitViewBase, objectDetectionClassifyProperty, objectDetectionMultipleProperty, onDetectionProperty } from "./common";
22
import { Application, Device, Utils, AndroidActivityRequestPermissionsEventData } from '@nativescript/core';
33
import lazy from '@nativescript/core/utils/lazy';
44

@@ -19,12 +19,11 @@ const IMAGE_LABELING_SUPPORTED = lazy(() => typeof io.github.triniwiz.fancycamer
1919
const OBJECT_DETECTION_SUPPORTED = lazy(() => typeof io.github.triniwiz.fancycamera?.objectdetection?.ObjectDetection);
2020
const POSE_DETECTION_SUPPORTED = lazy(() => typeof io.github.triniwiz.fancycamera?.posedetection?.PoseDetection);
2121

22-
export { BarcodeFormats, barcodeFormatsProperty, CameraPosition, cameraPositionProperty, DetectionType, faceDetectionMinFaceSizeProperty, faceDetectionPerformanceModeProperty, faceDetectionTrackingEnabledProperty, imageLablerConfidenceThresholdProperty, objectDetectionClassifyProperty, objectDetectionMultipleProperty } from './common';
22+
export { BarcodeFormats, barcodeFormatsProperty, CameraPosition, cameraPositionProperty, DetectionType, faceDetectionMinFaceSizeProperty, faceDetectionPerformanceModeProperty, faceDetectionTrackingEnabledProperty, imageLabelerConfidenceThresholdProperty, objectDetectionClassifyProperty, objectDetectionMultipleProperty } from './common';
2323

2424
export class MLKitView extends MLKitViewBase {
2525
#camera: io.github.triniwiz.fancycamera.FancyCamera;
2626
static #hasCamera: boolean;
27-
#onDetection: (data: { [key: string]: any }) => void;
2827
#onTextListener: io.github.triniwiz.fancycamera.ImageAnalysisCallback;
2928
#onBarcodeListener: io.github.triniwiz.fancycamera.ImageAnalysisCallback;
3029
#onDigitalInkListener: io.github.triniwiz.fancycamera.ImageAnalysisCallback;
@@ -87,11 +86,9 @@ export class MLKitView extends MLKitViewBase {
8786
return this.#hasCamera;
8887
}
8988

90-
//@ts-ignore
91-
set onDetection(value) {
92-
this.#onDetection = value;
89+
[onDetectionProperty.setNative](value) {
9390
const ref = new WeakRef(this);
94-
if (!this.#onTextListener && (this.dectectionType === DetectionType.Text || this.dectectionType === DetectionType.All)) {
91+
if (!this.#onTextListener && (this.detectionType === DetectionType.Text || this.detectionType === DetectionType.All)) {
9592
this.#onTextListener = new io.github.triniwiz.fancycamera.ImageAnalysisCallback({
9693
onSuccess(param0: string) {
9794
try {
@@ -105,7 +102,7 @@ export class MLKitView extends MLKitViewBase {
105102
this.#camera.setOnTextRecognitionListener(this.#onTextListener);
106103
}
107104

108-
if (!this.#onBarcodeListener && (this.dectectionType === DetectionType.Barcode || this.dectectionType === DetectionType.All)) {
105+
if (!this.#onBarcodeListener && (this.detectionType.includes(DetectionType.Barcode) || this.detectionType.includes(DetectionType.All))) {
109106
this.#onBarcodeListener = new io.github.triniwiz.fancycamera.ImageAnalysisCallback({
110107
onSuccess(param0: string) {
111108
try {
@@ -120,7 +117,7 @@ export class MLKitView extends MLKitViewBase {
120117
}
121118

122119
// todo
123-
if (!this.#onDigitalInkListener && (this.dectectionType === DetectionType.DigitalInk || this.dectectionType === DetectionType.All)) {
120+
if (!this.#onDigitalInkListener && (this.detectionType === DetectionType.DigitalInk || this.detectionType === DetectionType.All)) {
124121
/* this.#onDigitalInkListener = new io.github.triniwiz.fancycamera.ImageAnalysisCallback({
125122
onSuccess(param0: string) {
126123
try {
@@ -133,7 +130,7 @@ export class MLKitView extends MLKitViewBase {
133130
}); */
134131
}
135132

136-
if (!this.#onFaceListener && (this.dectectionType === DetectionType.Face || this.dectectionType === DetectionType.All)) {
133+
if (!this.#onFaceListener && (this.detectionType === DetectionType.Face || this.detectionType === DetectionType.All)) {
137134
this.#faceDetectionOptions = new io.github.triniwiz.fancycamera.facedetection.FaceDetection.Options();
138135
this.#onFaceListener = new io.github.triniwiz.fancycamera.ImageAnalysisCallback({
139136
onSuccess(param0: string) {
@@ -148,7 +145,7 @@ export class MLKitView extends MLKitViewBase {
148145
this.#camera.setOnFacesDetectedListener(this.#onFaceListener);
149146
}
150147

151-
if (!this.#onImageListener && (this.dectectionType === DetectionType.Image || this.dectectionType === DetectionType.All)) {
148+
if (!this.#onImageListener && (this.detectionType === DetectionType.Image || this.detectionType === DetectionType.All)) {
152149
this.#onImageListener = new io.github.triniwiz.fancycamera.ImageAnalysisCallback({
153150
onSuccess(param0: string) {
154151
try {
@@ -162,7 +159,7 @@ export class MLKitView extends MLKitViewBase {
162159
this.#camera.setOnImageLabelingListener(this.#onImageListener);
163160
}
164161

165-
if (!this.#onObjectListener && (this.dectectionType === DetectionType.Object || this.dectectionType === DetectionType.All)) {
162+
if (!this.#onObjectListener && (this.detectionType === DetectionType.Object || this.detectionType === DetectionType.All)) {
166163
this.#onObjectListener = new io.github.triniwiz.fancycamera.ImageAnalysisCallback({
167164
onSuccess(param0: string) {
168165
try {
@@ -176,7 +173,7 @@ export class MLKitView extends MLKitViewBase {
176173
this.#camera.setOnObjectDetectedListener(this.#onObjectListener);
177174
}
178175

179-
if (!this.#onPoseListener && (this.dectectionType === DetectionType.Pose || this.dectectionType === DetectionType.All)) {
176+
if (!this.#onPoseListener && (this.detectionType === DetectionType.Pose || this.detectionType === DetectionType.All)) {
180177
this.#onPoseListener = new io.github.triniwiz.fancycamera.ImageAnalysisCallback({
181178
onSuccess(param0: string) {
182179
try {
@@ -191,7 +188,7 @@ export class MLKitView extends MLKitViewBase {
191188
}
192189

193190
let type = DetectorType_None();
194-
switch (this.dectectionType) {
191+
switch (this.detectionType) {
195192
case DetectionType.All:
196193
type = DetectorType_All();
197194
break;
@@ -219,14 +216,8 @@ export class MLKitView extends MLKitViewBase {
219216
}
220217

221218
this.#camera.setDetectorType(type);
222-
223-
}
224-
225-
get onDetection() {
226-
return this.#onDetection;
227219
}
228220

229-
230221
[barcodeFormatsProperty.setNative](value: BarcodeFormats[]) {
231222
if (!BARCODE_SCANNER_SUPPORTED()) {
232223
return;

Diff for: packages/mlkit-core/index.d.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { MLKitViewBase } from "./common";
2-
export { BarcodeFormats, barcodeFormatsProperty, CameraPosition, cameraPositionProperty, DetectionType, faceDetectionMinFaceSizeProperty, faceDetectionPerformanceModeProperty, faceDetectionTrackingEnabledProperty, imageLablerConfidenceThresholdProperty, objectDetectionClassifyProperty, objectDetectionMultipleProperty } from './common';
2+
export { BarcodeFormats, barcodeFormatsProperty, CameraPosition, cameraPositionProperty, DetectionType, faceDetectionMinFaceSizeProperty, faceDetectionPerformanceModeProperty, faceDetectionTrackingEnabledProperty, imageLabelerConfidenceThresholdProperty as imageLablerConfidenceThresholdProperty, objectDetectionClassifyProperty, objectDetectionMultipleProperty } from './common';
33
export declare class MLKitView extends MLKitViewBase {
44
static isAvailable(): boolean;
55
onDetection: (data: {

0 commit comments

Comments
 (0)