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

Commit 40da077

Browse files
How to get live camera feed with nativescript-vue? #887
1 parent 12dc2e9 commit 40da077

6 files changed

Lines changed: 64 additions & 23 deletions

File tree

demo-ng/app/App_Resources/Android/AndroidManifest.xml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,9 @@
3030
android:label="@string/app_name"
3131
android:theme="@style/AppTheme">
3232

33-
<meta-data
34-
android:name="com.facebook.sdk.ApplicationId"
35-
android:value="@string/facebook_app_id"/>
33+
<meta-data
34+
android:name="com.facebook.sdk.ApplicationId"
35+
android:value="@string/facebook_app_id"/>
3636

3737
<meta-data
3838
android:name="com.google.firebase.ml.vision.DEPENDENCIES"

demo-vue/app/App_Resources/Android/src/main/AndroidManifest.xml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,19 @@
88
<uses-permission android:name="android.permission.INTERNET"/>
99
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
1010
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
11+
12+
<!-- for ML Kit -->
13+
<uses-permission android:name="android.permission.CAMERA"/>
14+
<uses-feature android:name="android.hardware.camera" android:required="false" />
15+
<uses-feature android:name="android.hardware.camera.autofocus" android:required="false" />
16+
1117
<application android:name="com.tns.NativeScriptApplication" android:allowBackup="true" android:icon="@drawable/icon"
1218
android:label="@string/app_name" android:theme="@style/AppTheme">
19+
20+
<meta-data
21+
android:name="com.google.firebase.ml.vision.DEPENDENCIES"
22+
android:value="ocr" />
23+
1324
<activity android:name="com.tns.NativeScriptActivity" android:label="@string/title_activity_kimera"
1425
android:configChanges="keyboardHidden|orientation|screenSize"
1526
android:theme="@style/LaunchScreenTheme">

demo-vue/app/components/App.vue

Lines changed: 27 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -7,31 +7,37 @@
77
<!--<Button @tap="onTapScheduleNotification" class="btn" text="Schedule Notification"></Button>-->
88
<!--<Button @tap="onTapCancelAll" class="btn" text="Cancel notifications"></Button>-->
99
<Label class="message" :text="message" textWrap="true"></Label>
10+
<MLKitTextRecognition width="260"
11+
height="340"
12+
processEveryNthFrame="5"
13+
@scanResult="onTextRecognitionResult">
14+
</MLKitTextRecognition>
15+
1016
</StackLayout>
1117
</Page>
1218
</template>
1319

1420
<script>
15-
const firebase = require("nativescript-plugin-firebase");
21+
const firebase = require("nativescript-plugin-firebase");
1622
17-
firebase.init({
18-
onDynamicLinkCallback: function (result) {
19-
console.log("Dynamic Link received: " + result);
20-
console.log("Dynamic Link received, url: " + result.url);
21-
if (result.url.indexOf("/campaigns/shit") > -1) {
22-
// note that you could deeplink/route the user now, but let's just show an alert
23-
alert({
24-
title: "Campaign button tapped!",
25-
message: "You tapped the button in the 'Firebase is the 💩' campaign - well don!",
26-
okButtonText: "Yep!"
27-
})
28-
}
23+
firebase.init({
24+
onDynamicLinkCallback: function (result) {
25+
console.log("Dynamic Link received: " + result);
26+
console.log("Dynamic Link received, url: " + result.url);
27+
if (result.url.indexOf("/campaigns/shit") > -1) {
28+
// note that you could deeplink/route the user now, but let's just show an alert
29+
alert({
30+
title: "Campaign button tapped!",
31+
message: "You tapped the button in the 'Firebase is the 💩' campaign - well don!",
32+
okButtonText: "Yep!"
33+
})
2934
}
30-
}).then(function () {
31-
console.log("Firebase initialized");
32-
}).catch(function (error) {
33-
console.log("Error initializing Firebase: " + error);
34-
});
35+
}
36+
}).then(function () {
37+
console.log("Firebase initialized");
38+
}).catch(function (error) {
39+
console.log("Error initializing Firebase: " + error);
40+
});
3541
3642
export default {
3743
data() {
@@ -41,6 +47,9 @@
4147
},
4248
4349
methods: {
50+
onTextRecognitionResult() {
51+
console.log("onTextRecognitionResult");
52+
}
4453
/*
4554
onTapHasPermission() {
4655
LocalNotifications.hasPermission()

demo-vue/app/main.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import Vue from "nativescript-vue";
22
import App from "./components/App";
33

44
require("nativescript-plugin-firebase");
5+
Vue.registerElement("MLKitTextRecognition", () => require("nativescript-plugin-firebase/mlkit/textrecognition").MLKitTextRecognition);
56

67
// Prints Vue logs when --env.production is *NOT* set while building
78
Vue.config.silent = (TNS_ENV === "production");

demo-vue/firebase.nativescript.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,5 +18,6 @@
1818
"admob": false,
1919
"invites": false,
2020
"dynamic_links": true,
21-
"ml_kit": false
21+
"ml_kit": true,
22+
"ml_kit_text_recognition": true
2223
}

docs/ML_KIT.md

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ you can pause the scanner with the `pause` property.
161161
162162
> 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, and how to wire `torchOn` to a `Switch`.
163163
164-
##### Angular / Vue
164+
##### Angular
165165
Register a custom element like so in the component/module:
166166
167167
```typescript
@@ -184,6 +184,25 @@ Now you're able to use the registered element in the view:
184184
</MLKitTextRecognition>
185185
```
186186
187+
##### Vue
188+
Register a custom element like so in `main.js`:
189+
190+
```typescript
191+
Vue.registerElement("MLKitTextRecognition", () => require("nativescript-plugin-firebase/mlkit/textrecognition").MLKitTextRecognition);
192+
```
193+
194+
Now you're able to use the registered element in your `.Vue` file:
195+
196+
```vue
197+
<MLKitTextRecognition
198+
width="260"
199+
height="340"
200+
processEveryNthFrame="5"
201+
:torchOn="torchOn"
202+
@scanResult="onTextRecognitionResult">
203+
</MLKitTextRecognition>
204+
```
205+
187206
##### XML
188207
Declare a namespace at the top of the embedding page, and use it anywhere on the page:
189208

0 commit comments

Comments
 (0)