Embedding in NativeScript-Vue
See original GitHub issueI’ve got Barcode Scanner working with NativeScript-Vue by calling scan() function, but I can’t figure out how to use the embed feature, it keeps returning Frame errors. This is what I’m doing:
<template>
<Page class="page">
<ActionBar class="action-bar" title="Home"/>
<StackLayout>
<Button class="btn btn-primary" @tap="onScan">Scan</Button>
<BarcodeScanner
class="scanner-round"
formats="QR_CODE, EAN_13"
beepOnScan="true"
reportDuplicates="true"
preferFrontCamera="false"
@scanResult="onScan">
</BarcodeScanner>
</StackLayout>
</Page>
</template>
<script>
const BarcodeScanner = require("nativescript-barcodescanner").BarcodeScanner;
export default {
components: {
"BarcodeScanner": require("nativescript-barcodescanner").BarcodeScannerView
},
data () {
return {
scanner: null
};
},
async created() {
this.scanner = new BarcodeScanner();
},
methods: {
onScan() {
this.scanner.scan({
formats: "QR_CODE, EAN_13",
showFlipCameraButton: true,
preferFrontCamera: false,
showTorchButton: true,
beepOnScan: true,
torchOn: false,
resultDisplayDuration: 500,
openSettingsIfPermissionWasPreviouslyDenied: true //ios only
}).then((result) => {
console.log({
title: "You Scanned ",
message: "Format: " + result.format + ",\nContent: " + result.text,
okButtonText: "OK"
});
}, (errorMessage) => {
console.log("Error when scanning " + errorMessage);
});
},
scanResult(result) {
console.log(`Format: ${ result.format }, Value: ${ result.text }`);
}
}
};
</script>
Issue Analytics
- State:
- Created 5 years ago
- Comments:7 (2 by maintainers)
Top Results From Across the Web
RadListView Overview
RadListView for NativeScript is a virtualizing list component that provides the most popular features associated with scenarios where a list of items is ......
Read more >What is proper way of starting a new nativescript-vue project ...
I want to be able to use Typescript inside Vue instance methods, as documented in blog page of nativescript-vue.org.
Read more >Persisting data between app launches with NativeScript Vue
import Vue from 'nativescript-vue'; import Vuex from 'vuex'; Vue.use(Vuex); const state = { token: false } const mutations = { setUser(state, ...
Read more >Introduction - NativeScript-Vue
NativeScript -Vue is a NativeScript plugin which allows you to use Vue.js to craft your mobile application. If you have used Vue.js before...
Read more >Develop Mobile Apps with NativeScript and VueJs - Littlelines
There are a few options available to us to use Vue to build mobile apps. One option is a framework called Vue Native....
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
I Struggled with this for a while as well.
The problem I found was that people are trying to embed when this will not work at all with android. Instead you MUST use a method call if you want this to work with android(and iOS). Functionality remains the same.
I will say that the documentation confused me to where I gave up and had to come back at a later stage, then realizing how silly I was in all my frustration… I did however get it to work! (after reading through the documentation several times)
This is how(using NativeScript-Vue):
In your: _ app.js/main.js_
Vue.registerElement('BarcodeScanner', () => require('nativescript-barcodescanner').BarcodeScannerView)
In your page.vue
(may contain some unnecessary code within elements and camera is imported because I am using this elsewhere in my app as well and have used its permission request in my solution)
The above code is what allowed me to eventually get the barcode scanner working in my own NS-Vue app.
My mistake was including the embedding Code from the docs as seen below:
(Do NOT include this)
I hope this helps someone get the nativescript-barcodescanner working on their NS-Vue app!
Definitively it works. The only thing is that it won’t work on the playground app, you must run it in a real device, since nativescript preview app does not ships with all the required plugins.