Skip to content
This repository was archived by the owner on Apr 4, 2023. It is now read-only.

Commit 067221d

Browse files
#699 Add ML Kit support (wrapping up)
1 parent cebfc22 commit 067221d

File tree

15 files changed

+79
-61
lines changed

15 files changed

+79
-61
lines changed

demo-ng/app/tabs/mlkit/mlkit.component.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ export class MLKitComponent {
177177
}).then((result: MLKitRecognizeTextOnDeviceResult) => {
178178
alert({
179179
title: `Result`,
180-
message: result.features.map(feature => feature.text).join(""),
180+
message: result.blocks.map(block => block.text).join(""),
181181
okButtonText: "OK"
182182
});
183183
}).catch(errorMessage => console.log("ML Kit error: " + errorMessage));

demo-ng/app/tabs/mlkit/textrecognition/textrecognition.component.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
(scanResult)="onTextRecognitionResult($event)">
1212
</MLKitTextRecognition>
1313

14-
<ListView row="1" [items]="features" class="m-t-20">
14+
<ListView row="1" [items]="blocks" class="m-t-20">
1515
<ng-template let-item="item">
1616
<Label class="mlkit-result" textWrap="true" [text]="item.text"></Label>
1717
</ng-template>
Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,19 @@
11
import { Component } from "@angular/core";
2-
import { MLKitRecognizeTextOnDeviceResult } from "nativescript-plugin-firebase/mlkit/textrecognition";
2+
import {
3+
MLKitRecognizeTextOnDeviceResult,
4+
MLKitRecognizeTextResultBlock
5+
} from "nativescript-plugin-firebase/mlkit/textrecognition";
36

47
@Component({
58
selector: "mlkit-textrecognition",
69
moduleId: module.id,
710
templateUrl: "./textrecognition.component.html",
811
})
912
export class TextRecognitionComponent {
10-
features: Array<{
11-
text: string;
12-
}>;
13+
blocks: Array<MLKitRecognizeTextResultBlock>;
1314

1415
onTextRecognitionResult(scanResult: any): void {
1516
const value: MLKitRecognizeTextOnDeviceResult = scanResult.value;
16-
this.features = value.features;
17+
this.blocks = value.blocks;
1718
}
1819
}

demo/app/main-view-model.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -348,7 +348,7 @@ export class HelloWorldModel extends Observable {
348348
setTimeout(() => {
349349
alert({
350350
title: "Dynamic Link!",
351-
message: result,
351+
message: JSON.stringify(result),
352352
okButtonText: "Awesome!"
353353
});
354354
}, 500);
@@ -1301,7 +1301,7 @@ export class HelloWorldModel extends Observable {
13011301
public doUploadFile(): void {
13021302
// let's first create a File object using the tns file module
13031303
const appPath = fs.knownFolders.currentApp().path;
1304-
const logoPath = appPath + "/res/telerik-logo.png";
1304+
const logoPath = appPath + "/images/telerik-logo.png";
13051305

13061306
firebase.uploadFile({
13071307
remoteFullPath: 'uploads/images/telerik-logo-uploaded.png',

demo/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
}
1010
},
1111
"dependencies": {
12-
"nativescript-plugin-firebase": "^5.0.0",
12+
"nativescript-plugin-firebase": "^6.0.0",
1313
"nativescript-theme-core": "^1.0.4",
1414
"nativescript-unit-test-runner": "^0.3.4",
1515
"tns-core-modules": "~4.0.0"

docs/ML_KIT.md

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
<img src="https://raw.githubusercontent.com/EddyVerbruggen/nativescript-plugin-firebase/issue699-mlkit-support/docs/images/features/mlkit.png" height="84px" alt="ML Kit"/>
1+
<img src="https://raw.githubusercontent.com/EddyVerbruggen/nativescript-plugin-firebase/master/docs/images/features/mlkit.png" height="84px" alt="ML Kit"/>
22

3-
Make sure to check out [this demo app](https://github.com/EddyVerbruggen/nativescript-plugin-firebase/tree/issue699-mlkit-support/demo-ng) because it has almost all ML Kit features this plugin currently supports! Steps:
3+
Make sure to check out [this demo app](https://github.com/EddyVerbruggen/nativescript-plugin-firebase/tree/master/demo-ng) because it has almost all ML Kit features this plugin currently supports! Steps:
44

55
```bash
66
git clone https://github.com/EddyVerbruggen/nativescript-plugin-firebase
77
cd nativescript-plugin-firebase/src
8-
npm i
8+
npm run setupandinstall
99
npm run demo-ng.ios (or .android)
1010
```
1111

@@ -52,7 +52,7 @@ To nbe able to use Cloud features you need to do two things:
5252
- Select your project.
5353
- In the bottom left, make sure you're on the _Blaze_ plan, or hit the 'Upgrade' button.
5454

55-
### Feature table
55+
### Features
5656

5757
|Feature|On-device|Cloud
5858
|---|---|---
@@ -66,7 +66,7 @@ To nbe able to use Cloud features you need to do two things:
6666
*) _Currently detecting faces from still images doesn't work on iOS (from the camera stream works fine tho)._
6767

6868
### Text recognition
69-
<img src="https://raw.githubusercontent.com/EddyVerbruggen/nativescript-plugin-firebase/issue699-mlkit-support/docs/images/features/mlkit_text_recognition.png" height="153px" alt="ML Kit - Text recognition"/>
69+
<img src="https://raw.githubusercontent.com/EddyVerbruggen/nativescript-plugin-firebase/master/docs/images/features/mlkit_text_recognition.png" height="153px" alt="ML Kit - Text recognition"/>
7070

7171
[Firebase documentation 🌎](https://firebase.google.com/docs/ml-kit/recognize-text)
7272

@@ -79,7 +79,7 @@ const firebase = require("nativescript-plugin-firebase");
7979
firebase.mlkit.textrecognition.recognizeTextOnDevice({
8080
image: imageSource // a NativeScript Image or ImageSource, see the demo for examples
8181
}).then((result: MLKitRecognizeTextOnDeviceResult) => { // just look at this type to see what else is returned
82-
console.log(result.features.map(feature => feature.text).join(""));
82+
console.log(result.blocks.map(block => block.text).join(""));
8383
}).catch(errorMessage => console.log("ML Kit error: " + errorMessage));
8484
```
8585

@@ -108,7 +108,7 @@ Plugin-specific are the optional property `processEveryNthFrame` and optional ev
108108
You can `processEveryNthFrame` set to a lower value than the default (5) to put less strain on the device.
109109
Especially 'Face detection' seems a bit more CPU intensive, but for 'Text recognition' the default is fine.
110110

111-
> Look at [the demo app](https://github.com/EddyVerbruggen/nativescript-plugin-firebase/tree/issue699-mlkit-support/demo-ng) to see how to wire up that `onTextRecognitionResult` function.
111+
> Look at [the demo app](https://github.com/EddyVerbruggen/nativescript-plugin-firebase/tree/master/demo-ng) to see how to wire up that `onTextRecognitionResult` function.
112112
113113
##### Angular / Vue
114114
Register a custom element like so in the component/module:
@@ -151,7 +151,7 @@ Declare a namespace at the top of the embedding page, and use it anywhere on the
151151
> Note that with NativeScript 4 the `Page` tag may actually be a `TabView`, but adding the namespace declaration to the TabView works just as well.
152152
153153
### Face detection
154-
<img src="https://raw.githubusercontent.com/EddyVerbruggen/nativescript-plugin-firebase/issue699-mlkit-support/docs/images/features/mlkit_face_detection.png" height="153px" alt="ML Kit - Face detection"/>
154+
<img src="https://raw.githubusercontent.com/EddyVerbruggen/nativescript-plugin-firebase/master/docs/images/features/mlkit_face_detection.png" height="153px" alt="ML Kit - Face detection"/>
155155

156156
[Firebase documentation 🌎](https://firebase.google.com/docs/ml-kit/detect-faces)
157157

@@ -185,7 +185,7 @@ registerElement("MLKitFaceDetection", () => require("nativescript-plugin-firebas
185185
```
186186

187187
### Barcode scanning
188-
<img src="https://raw.githubusercontent.com/EddyVerbruggen/nativescript-plugin-firebase/issue699-mlkit-support/docs/images/features/mlkit_text_barcode_scanning.png" height="153px" alt="ML Kit - Barcode scanning"/>
188+
<img src="https://raw.githubusercontent.com/EddyVerbruggen/nativescript-plugin-firebase/master/docs/images/features/mlkit_text_barcode_scanning.png" height="153px" alt="ML Kit - Barcode scanning"/>
189189

190190
[Firebase documentation 🌎](https://firebase.google.com/docs/ml-kit/read-barcodes)
191191

@@ -221,7 +221,7 @@ registerElement("MLKitBarcodeScanner", () => require("nativescript-plugin-fireba
221221
```
222222

223223
### Image labeling
224-
<img src="https://raw.githubusercontent.com/EddyVerbruggen/nativescript-plugin-firebase/issue699-mlkit-support/docs/images/features/mlkit_text_image_labeling.png" height="153px" alt="ML Kit - Image labeling"/>
224+
<img src="https://raw.githubusercontent.com/EddyVerbruggen/nativescript-plugin-firebase/master/docs/images/features/mlkit_text_image_labeling.png" height="153px" alt="ML Kit - Image labeling"/>
225225

226226
[Firebase documentation 🌎](https://firebase.google.com/docs/ml-kit/label-images)
227227

@@ -272,7 +272,7 @@ registerElement("MLKitImageLabeling", () => require("nativescript-plugin-firebas
272272
```
273273

274274
### Landmark recognition
275-
<img src="https://raw.githubusercontent.com/EddyVerbruggen/nativescript-plugin-firebase/issue699-mlkit-support/docs/images/features/mlkit_text_landmark_recognition.png" height="153px" alt="ML Kit - Landmark recognition"/>
275+
<img src="https://raw.githubusercontent.com/EddyVerbruggen/nativescript-plugin-firebase/master/docs/images/features/mlkit_text_landmark_recognition.png" height="153px" alt="ML Kit - Landmark recognition"/>
276276

277277
[Firebase documentation 🌎](https://firebase.google.com/docs/ml-kit/recognize-landmarks)
278278

@@ -294,4 +294,4 @@ firebase.mlkit.landmarkrecognition.recognizeLandmarksCloud({
294294
### Custom model inference
295295
[Firebase documentation 🌎](https://firebase.google.com/docs/ml-kit/use-custom-models)
296296

297-
Coming soon (probably with plugin version 6.1.0).
297+
Coming soon. See issue #702.

src/firebase.ios.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -641,6 +641,9 @@ firebase.toJsObject = objCObj => {
641641
case 'Date':
642642
node[key] = new Date(val);
643643
break;
644+
case 'FIRTimestamp':
645+
node[key] = val.dateValue();
646+
break;
644647
case 'FIRDocumentReference':
645648
const path = (<FIRDocumentReference>val).path;
646649
const lastSlashIndex = path.lastIndexOf("/");
@@ -712,6 +715,7 @@ firebase.init = arg => {
712715
if (arg.persist === false) {
713716
const fIRFirestoreSettings = FIRFirestoreSettings.new();
714717
fIRFirestoreSettings.persistenceEnabled = false;
718+
fIRFirestoreSettings.timestampsInSnapshotsEnabled = true;
715719
FIRFirestore.firestore().settings = fIRFirestoreSettings;
716720
}
717721
}
@@ -844,7 +848,7 @@ firebase.admob.showBanner = arg => {
844848

845849
view.addSubview(firebase.admob.adView);
846850

847-
// support rotation events (TODO we don't want to add multiple handlers)
851+
// support rotation events (TODO we don't want to add multiple handlers, also: remove with .off!).. could also just have the app handle this
848852
application.on(application.orientationChangedEvent, data => {
849853
if (firebase.admob.adView !== null) {
850854
firebase.admob.hideBanner().then(res => {
@@ -1267,13 +1271,12 @@ firebase.login = arg => {
12671271
return;
12681272
}
12691273

1270-
1271-
// TODO does this still work (there's a delegate now which we're not implementing)?
12721274
FIRPhoneAuthProvider.provider().verifyPhoneNumberUIDelegateCompletion(arg.phoneOptions.phoneNumber, null, (verificationID: string, error: NSError) => {
12731275
if (error) {
12741276
reject(error.localizedDescription);
12751277
return;
12761278
}
1279+
12771280
firebase.requestPhoneAuthVerificationCode(userResponse => {
12781281
const fIRAuthCredential = FIRPhoneAuthProvider.provider().credentialWithVerificationIDVerificationCode(verificationID, userResponse);
12791282
if (fAuth.currentUser) {
@@ -2687,8 +2690,6 @@ class FIRMessagingDelegateImpl extends NSObject implements FIRMessagingDelegate
26872690
return this;
26882691
}
26892692

2690-
2691-
// TODO test that receiving push notifications in the foreground still works
26922693
public messagingDidReceiveMessage(messaging: FIRMessaging, remoteMessage: FIRMessagingRemoteMessage): void {
26932694
console.log(">> fcm message received");
26942695
this.callback(remoteMessage.appData);

src/mlkit/imagelabeling/index.d.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ export interface MLKitImageLabelingCloudResult extends MLKitResult {
55
labels: Array<{
66
text: string;
77
confidence: number;
8-
// corners: any;
98
}>;
109
}
1110

src/mlkit/imagelabeling/index.ios.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ export class MLKitImageLabeling extends MLKitImageLabelingBase {
2828
});
2929
}
3030

31-
console.log(">>> notify " + MLKitImageLabeling.scanResultEvent + " with " + JSON.stringify(result));
3231
this.notify({
3332
eventName: MLKitImageLabeling.scanResultEvent,
3433
object: this,
@@ -68,10 +67,8 @@ export function labelImageOnDevice(options: MLKitImageLabelingOnDeviceOptions):
6867
result.labels.push({
6968
text: label.label,
7069
confidence: label.confidence
71-
// corners: <any>feature.cornerPoints
7270
});
7371
}
74-
console.log(">>> image labeling result: " + JSON.stringify(result.labels));
7572
resolve(result);
7673
}
7774
});

src/mlkit/landmarkrecognition/index.d.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
import { MLKitCloudOptions, MLKitResult } from "../index";
22

3+
export interface MLKitLandmarkRecognitionResultLandmark {
4+
// TODO add location (see #704)
5+
name: string;
6+
confidence: number;
7+
}
8+
39
export interface MLKitLandmarkRecognitionCloudResult extends MLKitResult {
4-
// TODO add locations (see #704)
5-
landmarks: Array<{
6-
name: string;
7-
confidence: number;
8-
}>;
10+
landmarks: Array<MLKitLandmarkRecognitionResultLandmark>;
911
}
1012

1113
export interface MLKitLandmarkRecognitionCloudOptions extends MLKitCloudOptions {

0 commit comments

Comments
 (0)