Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

run with expo #31

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions .expo/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
> Why do I have a folder named ".expo" in my project?
The ".expo" folder is created when an Expo project is started using "expo start" command.

> What does the "packager-info.json" file contain?
The "packager-info.json" file contains port numbers and process PIDs that are used to serve the application to the mobile device/simulator.

> What does the "settings.json" file contain?
The "settings.json" file contains the server configuration that is used to serve the application manifest.

> Should I commit the ".expo" folder?
No, you should not share the ".expo" folder. It does not contain any information that is relevant for other developers working on the project, it is specific to your machine.

Upon project creation, the ".expo" folder is already added to your ".gitignore" file.
5 changes: 5 additions & 0 deletions .expo/packager-info.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"devToolsPort": 19002,
"expoServerPort": 19000,
"packagerPort": 19000
}
10 changes: 10 additions & 0 deletions .expo/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"hostType": "lan",
"lanType": "ip",
"dev": true,
"minify": false,
"urlRandomness": null,
"https": false,
"scheme": null,
"devClient": false
}
5 changes: 2 additions & 3 deletions app.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
{
"name": "oca",
"displayName": "oca"
}
"name": "oca"
}
3 changes: 1 addition & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,5 @@

import {AppRegistry} from 'react-native';
import App from './src/containers/App';
import {name as appName} from './app.json';

AppRegistry.registerComponent(appName, () => App);
AppRegistry.registerComponent('main', () => App);
7 changes: 6 additions & 1 deletion metro.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,13 @@
*
* @format
*/

const blacklist = require('metro-config/src/defaults/exclusionList');
module.exports = {
resolver: {
blacklistRE: blacklist([
/node_modules\/.*\/node_modules\/react-native\/.*/,
]),
},
transformer: {
getTransformOptions: async () => ({
transform: {
Expand Down
29 changes: 16 additions & 13 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,28 +8,31 @@
"lint": "eslint ."
},
"dependencies": {
"react": "16.8.6",
"react-native": "0.60.5",
"@react-native-async-storage/async-storage": "~1.15.0",
"expo": "^44.0.6",
"react": "17.0.1",
"react-dom": "17.0.1",
"react-native": "0.64.3",
"react-native-elements": "^1.2.0",
"react-native-gesture-handler": "^1.4.1",
"react-native-gesture-handler": "~2.1.0",
"react-native-odoo-promise-based": "^0.6.4",
"react-native-vector-icons": "^6.6.0",
"react-native-webview": "^7.0.4",
"react-native-vector-icons": "^8.1.0",
"react-native-webview": "11.15.0",
"react-navigation": "^4.0.0",
"react-navigation-stack": "^1.5.1",
"url": "^0.11.0"
},
"devDependencies": {
"@babel/core": "^7.6.0",
"@babel/runtime": "^7.6.0",
"@react-native-community/eslint-config": "^0.0.5",
"babel-jest": "^24.9.0",
"eslint": "^6.3.0",
"jest": "^24.9.0",
"@babel/core": "^7.12.9",
"@babel/runtime": "^7.12.5",
"@react-native-community/eslint-config": "^2.0.0",
"babel-jest": "^26.6.3",
"eslint": "7.14.0",
"jest": "^26.6.3",
"jetifier": "^1.6.4",
"metro-react-native-babel-preset": "^0.56.0",
"metro-react-native-babel-preset": "^0.64.0",
"react-native-dotenv": "^0.2.0",
"react-test-renderer": "16.8.6"
"react-test-renderer": "17.0.1"
},
"jest": {
"preset": "react-native"
Expand Down
5 changes: 3 additions & 2 deletions src/components/auth.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/* eslint-disable prettier/prettier */
import React from 'react';
import {ActivityIndicator, AsyncStorage, StatusBar, View} from 'react-native';

import {ActivityIndicator, StatusBar, View} from 'react-native';
import AsyncStorage from '@react-native-async-storage/async-storage';
import styles from './style';

export default class AuthLoadingScreen extends React.Component {
Expand Down
3 changes: 2 additions & 1 deletion src/components/router.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable prettier/prettier */
import {createSwitchNavigator} from 'react-navigation';
import {createStackNavigator} from 'react-navigation-stack';

Expand All @@ -7,7 +8,7 @@ import OdooBackend from '../pages/backend';
import AuthLoadingScreen from './auth';

const AuthStack = createStackNavigator({SignIn: SignInScreen});
const AppStack = createStackNavigator({Other: OdooBackend, Home: HomeScreen});
const AppStack = createStackNavigator({Home: HomeScreen, Other: OdooBackend});

export const AppNavigator = createSwitchNavigator(
{
Expand Down
2 changes: 2 additions & 0 deletions src/containers/App.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
/* eslint-disable prettier/prettier */
// In App.js in a new project

import React from 'react';
import {createAppContainer} from 'react-navigation';
import {AppNavigator} from '../components/router';
// eslint-disable-next-line prettier/prettier

const AppContainer = createAppContainer(AppNavigator);

Expand Down
16 changes: 9 additions & 7 deletions src/pages/backend/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
/* eslint-disable prettier/prettier */
import React from 'react';

import {ActivityIndicator, AsyncStorage, Vibration} from 'react-native';
import {ActivityIndicator, Vibration} from 'react-native';
import AsyncStorage from '@react-native-async-storage/async-storage';
import {WebView} from 'react-native-webview';

import styles from './style';
Expand All @@ -20,7 +22,7 @@ export default class OdooBackend extends React.Component {

StartVibrationFunction = () => {
// Device Will Vibrate for 10 seconds.
// Vibration.vibrate(DURATION);
Vibration.vibrate(DURATION);

// Android Device Will Vibrate in pattern : Wait 1sec -> vibrate 2sec -> wait 3sec.
// iOS Device Will Vibrate in pattern : Wait 1sec -> Vibrate -> wait 2sec -> Vibrate -> wait 3sec -> Vibrate
Expand All @@ -35,19 +37,19 @@ export default class OdooBackend extends React.Component {
};

async componentDidMount() {
AsyncStorage.getItem('last_url').then(last_url => {
AsyncStorage.getItem('last_url').then((last_url) => {
if (
last_url === 'about:blank' ||
typeof last_url === 'undefined' ||
last_url == null
) {
AsyncStorage.getItem('server_backend_url')
.then(url => {
.then((url) => {
if (url) {
this.setState({url: url});
}
})
.catch(e => {
.catch((e) => {
console.log(e);
});
} else {
Expand All @@ -63,7 +65,7 @@ export default class OdooBackend extends React.Component {
_backendMessage(message) {
switch (message) {
case 'REACT_EXIT':
// this.StartVibrationFunction();
this.StartVibrationFunction();
this.props.navigation.navigate('Home');
break;
case 'OTHER_MESSAGE':
Expand Down Expand Up @@ -104,7 +106,7 @@ export default class OdooBackend extends React.Component {
renderLoading={this.ActivityIndicatorLoadingView}
injectedJavaScript={runFirst}
// injectedJavaScript={this.state.cookie}
onMessage={event => {
onMessage={(event) => {
this._backendMessage(event.nativeEvent.data);
}}
/>
Expand Down
11 changes: 8 additions & 3 deletions src/pages/home/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
/* eslint-disable prettier/prettier */
import React from 'react';
import {AsyncStorage, Image, View} from 'react-native';
import {Image, View} from 'react-native';
import AsyncStorage from '@react-native-async-storage/async-storage';
import {Button, Card, Icon, Text} from 'react-native-elements';

import styles from './style';
Expand All @@ -18,8 +20,7 @@ export default class HomeScreen extends React.Component {
static navigationOptions = {
header: null,
};

async componentDidMount() {
async _loadingInfo() {
var server = await AsyncStorage.getItem('server_backend_url');
var user_name = await AsyncStorage.getItem('user_display_name');
var image_small = await AsyncStorage.getItem('image_small');
Expand All @@ -32,6 +33,10 @@ export default class HomeScreen extends React.Component {
});
}

async componentDidMount() {
this._loadingInfo();
}

render() {
return (
<View style={styles.container}>
Expand Down
36 changes: 21 additions & 15 deletions src/pages/login/index.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
/* eslint-disable prettier/prettier */
import React from 'react';
import { APP_SITE, APP_SITE_TITLE } from 'react-native-dotenv';
import {APP_SITE, APP_SITE_TITLE} from 'react-native-dotenv';
import {
AsyncStorage,
Keyboard,
Image,
View,
TouchableWithoutFeedback,
KeyboardAvoidingView,
Linking,
} from 'react-native';
import { Button, Input } from 'react-native-elements';
import AsyncStorage from '@react-native-async-storage/async-storage';
import {Button, Input} from 'react-native-elements';
import Icon from 'react-native-vector-icons/FontAwesome';
import styles from './style';
import OdooApi from '../../services/odoo';
Expand All @@ -25,21 +26,24 @@ export default class SignInScreen extends React.Component {
protocol: 'https',
};

handleServerChange = server => {
this.setState({ server });
handleServerChange = (server) => {
this.setState({server});
};

handleUserChange = user => {
this.setState({ user });
handleUserChange = (user) => {
this.setState({user});
};

handlePasswordChange = password => {
this.setState({ password });
handlePasswordChange = (password) => {
this.setState({password});
};

render() {
return (
<KeyboardAvoidingView style={styles.containerView} behavior="padding" keyboardVerticalOffset={-400}>
<KeyboardAvoidingView
style={styles.containerView}
behavior="padding"
keyboardVerticalOffset={-400}>
<TouchableWithoutFeedback onPress={Keyboard.dismiss}>
<View style={styles.loginScreenContainer}>
<View style={styles.loginFormView}>
Expand Down Expand Up @@ -105,26 +109,28 @@ export default class SignInScreen extends React.Component {
this.state.password,
);
const database_list = await odoo_api.database_list;

console.log(odoo_api, 'api');
if (database_list && database_list.length) {
if (database_list.length === 1) {
this.state.database = database_list[0];
} else {
console.error('Not implemented');
}
var connection = await odoo_api.connect(this.state.database);
console.log(connection);

if (typeof connection.uid === 'number') {
await AsyncStorage.setItem('userToken', connection.session_id);
// await AsyncStorage.setItem('userToken', connection.session_id);
await AsyncStorage.setItem('user_display_name', connection.name);
await AsyncStorage.setItem('user_uid', connection.uid.toString());
await AsyncStorage.setItem('database', connection.db);
const imagem = await odoo_api.get_user_image(connection.uid);
await AsyncStorage.setItem('image_small', imagem);
// const imagem = await odoo_api.get_user_image(connection.uid);
// await AsyncStorage.setItem('image_small', imagem);
await AsyncStorage.setItem(
'server_backend_url',
odoo_api.server_backend_url,
);
this.props.navigation.navigate('App', {
this.props.navigation.navigate('Home', {
url: odoo_api.server_backend_url,
});
} else {
Expand Down
15 changes: 8 additions & 7 deletions src/services/odoo.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable prettier/prettier */
import Odoo from 'react-native-odoo-promise-based';
const url_api = require('url');

Expand Down Expand Up @@ -43,7 +44,7 @@ class OdooApi {

_parseURL() {
if (!this.complete_url.includes('http')) {
this.complete_url = "https://" + this.complete_url;
this.complete_url = 'https://' + this.complete_url;
}
var url = url_api.parse(this.complete_url);
this.hostname = url.hostname;
Expand All @@ -70,12 +71,12 @@ class OdooApi {
_getDatabases() {
return this.odoo
.rpc_call('/web/database/list', {})
.then(response => {
.then((response) => {
if (response.success === true) {
return response.data;
}
})
.catch(e => {
.catch((e) => {
console.log(e);
});
}
Expand All @@ -84,12 +85,12 @@ class OdooApi {
this.odoo.database = database;
return this.odoo
.connect()
.then(response => {
.then((response) => {
if (response.success === true) {
return response.data;
}
})
.catch(e => {
.catch((e) => {
return false;
});
}
Expand All @@ -100,12 +101,12 @@ class OdooApi {
ids: [user_id],
fields: ['image_small'],
})
.then(response => {
.then((response) => {
if (response.success === true) {
return response.data[0].image_small;
}
})
.catch(e => {
.catch((e) => {
return false;
});
}
Expand Down
Loading