I'm new in app dev and I wanted to start with vue native and as I saw in the documentation,vue native is not able to acces some device API's like local file,but react native can and vue is just wrapper around the React Native,
So how can I use import react native compoment and API's inside vue project?
and use expo to development
For example ionicons:
In script part:
import { Ionicons } from "#expo/vector-icons";
export default {
components: {Ionicons},
}
After that you can use it in template:
<template>
<view class="container">
<ionicons name="md-checkmark-circle" size=92 color="green" />
</view>
</template>
You can see examples here:
https://vue-native.io/docs/community-libraries-doc.html
Another example with Expo-Speech:
Installing package:
expo install expo-speech
Add it in script:
import * as Speech from 'expo-speech';
export default {
methods: {
sayHi: function(){
Speech.speak('Hi');
}
}
}
In template:
<template>
<view class="container">
<button title="Say Hi" :on-press="sayHi" />
</view>
</template>
Good luck!
Related
I'm a React Native newbie and I'm trying to assess the viability of porting to Android a React Native app that was originally written (not by me...) with iOS in mind.
At the moment I'm not trying to have code that will easily generate both Android and iOS bundles, just having the Android app working properly, with whatever alteration needed. We are using React Native 0.65.3
After setting up the Android environment, I'm compiling it on a MacBook Pro M1 with this command:
npx react-native bundle --entry-file ./index.js --platform android --dev false --bundle-output android/app/src/main/assets/index.android.bundle --assets-dest android/app/src/main/res
I got the app to start, up to the point that a Webview has to load a static HTML file that is shipped with the assets (and which executes javascript code on its own)
In the original code, the HTML files to be loaded are located in the component folder (so NOT the usual assets folder). The original code that works for iOS is as follows:
const HTML: { [x: string]: any } = {
app_avatar_1: () => require('../../html/webview/app_avatar_1.html'),
...
};
return (
<View style={styles.container}>
<WebView
ref={webViewRef}
originWhitelist={['*']}
javaScriptEnabled={true}
domStorageEnabled={true}
source={HTML[avatarId]()}
onMessage={onMessage}
/>
</View>
);
Because Webview under Android does not "like" require() for static files, I ended up using 'file:///path/to/static/HTML/file' and adding allowFileAccess={true} as Android by default doesn't allow access to static HTML, JS, etc files.
Frustrated with the various ERR_FILE_NOT_FOUND or alternatively ERR_ACCESS_DENIED, I moved the HTML files in the assets folder of the React project...nothing changes...
At this point, I have no clue where the static HTML files should be located or I could invoke them inside the Webview...
I also noticed that the static files are being copied to the res folder only if there is a require() statement explicitly including those, otherwise they seem to be simply ignored.
With the following code:
const HTML: { [x: string]: any } = {
app_avatar_1: () => require('assets/webview/app_avatar_1.html'),
...
}
<WebView
ref={webViewRef}
originWhitelist={['*']}
javaScriptEnabled={true}
domStorageEnabled={true}
source={{uri: 'file:///assets/webview/app_avatar_1.html'}}
allowFileAccess={true}
onMessage={onMessage}
/>
I get a "ERR_ACCESS_DENIED" error.
For whatever reason, static images are displayed correctly with no change required for Android...for instance:
const avatarImages: { [x: string]: ImageSourcePropType } = {
app_avatar_1: require('assets/avatars/thumb-0.jpg'),
....
}
<Image
style={styles.image}
source={avatarImages[el.id]}
resizeMode={'cover'}`
/>
will work on Android right away...
Thank you all the people who will help!
This is how I eventually made it work:
const updateSourceOnLoad = () => {
setRenderedOnce(true);
};
if(Platform.OS === "android") {
return (
<View style={styles.container}>
<WebView
ref={webViewRef}
originWhitelist={['*']}
javaScriptEnabled={true}
domStorageEnabled={true}
source={{uri: 'file:///android_asset/file.html'}}
allowFileAccess={true}
allowUniversalAccessFromFileURLs={true}
onMessage={onMessage}
onLoad={updateSourceOnLoad}
/>
</View>
)
}
The issue seems to be the way the Webview sets flags once being loaded (only on Android)
I'm using Ionic native image picker: https://ionicframework.com/docs/native/image-picker/
I'm importing on my module
import { ImagePicker } from '#ionic-native/image-picker';
And adding on the module's providers
ImagePicker,
On my page I'm importing it
import { ImagePicker, ImagePickerOptions } from '#ionic-native/image-picker';
Adding to my constructor
private imagePicker: ImagePicker,
Then calling a method on a button
async pickImageFromGallery() {
try {
const [imageSource] = await this.imagePicker.getPictures(this.pickerOptions);
this.imgSrc = imageSource;
It does work and I can get the file URI, however when I try to display on an <img> tag the image doesn't show up
<img src="{{ imgSrc }}" alt="" />
Do I need to configure some permission or something? Why doesn't the image show up?
Instead of this.imgSrc = imageSource; I did
this.imgSrc = imageSource.replace('file://', '');
Works on both iOS and Android.
If you run into problems like Android crashing try this:
First I cleaned my project
# rm -rf
rimraf .sourcemaps node_modules platforms plugins www
Then installed packages
npm i
Then deploy the app again
ionic cordova run android --device
You have to add "" in your src
<img src="{{ imgSrc }}" alt="" />
I have tried out this tutorial to develop an android application via Cordova and Framework7. It works in the browser and also Android Emulator (ADK). I converted the project to the apk with Cordova build command and transferred the apk file to my device.
The application works, however, the list which is the application based Framework7 (indeed on Vue) does not show anything. It looks like Vue not initialized.
Here is the HTML code:
<template id="page-alt-sayfa">
<f7-page>
<f7-navbar title="Alt Sayfa" back-link="Geri" sliding></f7-navbar>
<f7-block-title>
<!-- sayfa id'sini data obj içinde ara-->
{{this.$root.$data['icerik'][$route.params['sayfaId']].baslik}}</p>
</f7-block-title>
<f7-block-title>Dondurucuya Konur mu?</f7-block-title>
<f7-block inner>
<img style="width:95%;overflow:hidden" :src="'./img/sembolik/'+$route.params['sayfaId']+'.png'"/>
<br>
<div v-if="this.$root.$data['icerik'][$route.params['sayfaId']].dondurucu">
<div class="chip">
<div class="chip-media bg-green"><i class="material-icons">dns</i></div>
<div class="chip-label">Dondurucuya Konulur</div>
</div>
</div>
Here is initializing Framework7 and Vue:
...
<script src="cordova.js"></script>
<script src="js/framework7.min.js"></script>
<script src="js/vue.min.js"></script>
<script src="js/framework7-vue.min.js"></script>
<script type="text/javascript" src="js/data.json"></script>
<script src="js/app.js"></script>
</body>
</html>
Here a screenshoot from my phone.
(source: ultraimg.com)
How can the problem be solved?
Edit:
Here is my router code:
// Init F7 Vue Plugin
Vue.use(Framework7Vue)
// Init Page Components
Vue.component('page-about', {
template: '#page-about'
})
Vue.component('page-form', {
template: '#page-form'
})
Vue.component('page-dynamic-routing', {
template: '#page-dynamic-routing'
})
Vue.component('page-alt-sayfa', {
template: '#page-alt-sayfa'
})
// Handle device ready event
// Note: You may want to check out the vue-cordova package on npm for cordova specific handling with vue - https://www.npmjs.com/package/vue-cordova
document.addEventListener('deviceready', () => {
console.log("DEVICE IS READY!");
}, false)
// Init App
new Vue({
el: '#app',
// Init Framework7 by passing parameters here
framework7: {
root: '#app',
/* Uncomment to enable Material theme: */
// material: true,
routes: [
{
path: '/about/',
component: 'page-about'
},
{
path: '/alt-sayfa/:sayfaId/',
component: 'page-alt-sayfa'
}
]
},
data: {
mesaj: 'Merhaba',
icerik: icerik
}
});
I recently faced a similar problem. The routing was working well when tested my computer browser and emulator. But when I built the apk, it just did not work. It turned out I had a case sensitivity issue with the names of the views in my code. My computer and emulator ignored it and did the routing, but my phone didn't.
Have you crossed-checked the spelling of the names of your views to make sure it is not a case-sensitivity issue?
I do not find the where is the problem stems from. However, I find a npm template and reorganized my code according to this template and it worked
Template is:
https://framework7.io/vue/templates.html
I installed it with this command:
cordova create <project_create_dir> [com.example.projectname] [ProjectClassName] --template cordova-template-framework7-vue-webpack
I followed the instruction to install native-base from nativebase.io and to setup the project. I was successful at that, after running the command react-native run-android I get a successful message in the CMD telling
BUILD SUCCESSFUL
Total time: 15.051 secs
'adb' is not recognized as an internal or external command,
operable program or batch file.
Starting the app (C:\Users\DELL\AppData\Local\Android\sdk/platform-tools/adb
shell am start -n
com.awesomenativebase/com.awesomenativebase.MainActivity...
Starting: Intent { cmp=com.awesomenativebase/.MainActivity }
but, I get the following error in my App that is running in my physical device(Samsung kitkat 4.4.4):
My code in App.js:
import React, { Component } from 'react';
import { Container, Header, Title, Content, Footer, FooterTab, Button, Left,
Right, Body, Icon, Text } from 'native-base';
export default class AnatomyExample extends Component {
render() {
return (
<Container>
<Header>
<Left>
<Button transparent>
<Icon name='menu' />
</Button>
</Left>
<Body>
<Title>Header</Title>
</Body>
<Right />
</Header>
<Content>
<Text>
This is Content Section
</Text>
</Content>
<Footer>
<FooterTab>
<Button full>
<Text>Footer</Text>
</Button>
</FooterTab>
</Footer>
</Container>
);
}
Can anyone help on this? Thank you.
First make sure that the both devices (physical device & the device on which the code is running) on the same network.
Shake the physical device, it opens the debugger options.
Go to Dev Settings -> Debug server host & port for device.
It should be empty if you're device is connected by usb otherwise enter the ip address of your laptop followed by the port on which the packager is running.
For e.g 12:34:56:78:8081
Hello i am beginner in react native, and i followed all the guides to use react native with native base, but whenever i test the application using the sample codes below, i still get
" welcome to React Native, to get started, edit index.android.js"
as you can see code and output do not match, any idea on how to solve this?
import {Container, Content, Button, Icon} from 'native-base';
import React, {Component} from 'react-native';
export default class IconButtonExample extends Component {
render() {
return (
Home
<Button success iconRight>
Next
<Icon name="ios-arrow-forward" />
</Button>
<Button info>
Previous
<Icon name="ios-arrow-back" />
</Button>
<Button warning>
<Icon name="ios-star" />
</Button>
<Button danger>
<Icon name="ios-close-circle" />
</Button>
<Button style={{backgroundColor: '#384850'}} >
<Icon name="ios-search" style={{color: '#00c497'}}/>
</Button>
</Content>
</Container>
);
}
}
you need to put the code you posted above inside the main file named index.android.js
you need to restart your emulator and re-bundle the application
You can see here the default folder structure for react native projects.
or read about it