ilink-world/screens/splashscreen/SplashScreen.js

265 lines
8.8 KiB
JavaScript
Raw Normal View History

2019-06-16 13:09:54 +00:00
import React, { Component } from 'react';
import {
2020-03-20 18:28:22 +00:00
StyleSheet, View, Text, Image, ProgressBarAndroid,
TouchableNativeFeedback, TouchableOpacity,
PermissionsAndroid, NativeModules, StatusBar, Platform, Animated
2019-06-16 13:09:54 +00:00
} from 'react-native';
2020-03-20 18:28:22 +00:00
import { responsiveHeight, responsiveWidth, responsiveFontSize } from 'react-native-responsive-dimensions';
2019-06-16 13:09:54 +00:00
import I18n from 'react-native-i18n'
2020-03-20 18:28:22 +00:00
const theme = require('./../../utils/theme.json');
const route = require('./../../route.json');
import { readUser, getPasObject, getPubActiveObject } from '../../webservice/AuthApi';
2019-06-16 13:09:54 +00:00
import { Bubbles, DoubleBounce, Bars, Pulse } from 'react-native-loader';
import Configuration from "../../webservice/persistences/Configuration";
import '../ads/InterticielAds'
import * as Animatable from 'react-native-animatable';
import LottieView from 'lottie-react-native'; // if you have "esModuleInterop": true
import InterticielAds from '../ads/InterticielAds';
import Overlay from 'react-native-elements'
import DeviceInfo from 'react-native-device-info';
2020-03-20 18:28:22 +00:00
export default class SplashScreen extends Component {
static navigatorStyle = {
drawUnderNavBar: true,
navBarHidden: true,
drawUnderStatusBar: false,
statusBarHidden: false,
statusBarTextColorScheme: 'light',
};
static options(passProps) {
return {
statusBar: {
visible: false,
style: 'light' | 'dark',
drawBehind: true
},
topBar: {
title: {
text: 'My Screen'
},
drawBehind: true,
visible: false,
animate: false
}
};
}
2019-06-16 13:09:54 +00:00
2020-03-20 18:28:22 +00:00
//
constructor(props) {
super(props);
this.state = {
2019-06-16 13:09:54 +00:00
2020-03-20 18:28:22 +00:00
}
};
workUserResult(result) {
2020-09-30 06:03:08 +00:00
console.log("SPLASHSCREEN PROPS", this.props);
if (this.props.navigation.state.params.hasOwnProperty('routeName')) {
this.props.navigation.navigate(this.props.navigation.state.params.routeName, {
id: this.props.navigation.state.params.params.id
});
2020-03-20 18:28:22 +00:00
} else {
2020-09-30 06:03:08 +00:00
var way = "";
var way2 = "";
if (result === null || result === undefined) {
way = "Auth"
way2 = route.first
} else {
if (!result.category)
way = "App"
else {
switch (result.category) {
case 'geolocated': way = "AgentApp"
break;
case 'super': way = "adminApp"
break
default:
way = "supAdminApp"
}
2020-03-20 18:28:22 +00:00
}
2020-09-30 06:03:08 +00:00
way2 = route.login
2020-03-20 18:28:22 +00:00
}
2020-09-30 06:03:08 +00:00
this.props.navigation.navigate(way)
2020-03-20 18:28:22 +00:00
}
2019-06-16 13:09:54 +00:00
2020-03-20 18:28:22 +00:00
/* Navigation.setStackRoot(route.stackRoot,
{ component: {
name: way,
}
}
);
Navigation.showOverlay({
component: {
name: route.intersticielAds,
id:"interticiel",
options: {
overlay: {
interceptTouchOutside: false
}
}
}
});*/
2019-06-16 13:09:54 +00:00
2020-03-20 18:28:22 +00:00
}
componentDidMount() {
try {
this.requestCameraPermission()
} catch (e) {
console.log(e)
}
this.config = new Configuration();
this.retrieveAndroidInformation()
setTimeout(() => this.bounce(), 500)
this.bounce()
2019-06-16 13:09:54 +00:00
}
2020-03-20 18:28:22 +00:00
async requestCameraPermission() {
try {
const granted = await PermissionsAndroid.request(
PermissionsAndroid.PERMISSIONS.ACCESS_FINE_LOCATION,
{
'title': 'Cool Photo App Camera Permission',
'message': 'Cool Photo App needs access to your camera ' +
'so you can take awesome pictures.'
}
)
if (granted === PermissionsAndroid.RESULTS.GRANTED) {
2019-06-16 13:09:54 +00:00
2020-03-20 18:28:22 +00:00
} else {
console.log("try get information else")
}
} catch (err) {
console.log("try get information error")
console.log(err)
}
2019-06-16 13:09:54 +00:00
}
2020-03-20 18:28:22 +00:00
handleViewRef = ref => this.view = ref;
2019-06-16 13:09:54 +00:00
2020-03-20 18:28:22 +00:00
bounce = () => this.view.transition({ translateX: 0 }, { translateX: 700 }, 5000);
2019-06-16 13:09:54 +00:00
2020-03-20 18:28:22 +00:00
render() {
2019-06-16 13:09:54 +00:00
2020-03-20 18:28:22 +00:00
return (
<View style={styles.container}>
<StatusBar
translucent={true}
/>
<Image style={styles.logo} source={require('./../../datas/img/icon3up.png')} />
<View style={{ flexDirection: 'row' }}>
<Image style={styles.logo} source={require('./../../datas/img/iconsub3.png')} />
2019-06-16 13:09:54 +00:00
<Animatable.View
2020-03-20 18:28:22 +00:00
style={{ width: responsiveWidth(90), height: 92, backgroundColor: theme.primary, position: 'absolute', zIndex: 100 }}
ref={this.handleViewRef}>
</Animatable.View>
2019-06-16 13:09:54 +00:00
2020-03-20 18:28:22 +00:00
</View>
2019-06-16 13:09:54 +00:00
2020-03-20 18:28:22 +00:00
</View>
)
}
retreiveIosInformation() {
readUser().then((result) => {
setTimeout(() => {
this.workUserResult(result)
}, 3000)
}).catch((e) => {
this.props.navigation.navigate("Auth")
});
return "";
}
retrieveAndroidInformation() {
getPasObject().then((data) => {
console.warn(data);
this.config.setCurrentPas(data)
})
2019-06-16 13:09:54 +00:00
2020-03-20 18:28:22 +00:00
this.config._getData().then((lang) => {
if (lang) {
I18n.locale = lang
2019-06-16 13:09:54 +00:00
readUser().then((result) => {
2020-03-20 18:28:22 +00:00
console.warn(result)
if (result) {
getPubActiveObject(result['country_id']).then((data) => {
console.warn(data)
this.config.setPubActive(data);
})
}
setTimeout(() => {
this.workUserResult(result)
}, 3000)
})
} else {
2019-06-16 13:09:54 +00:00
const code = DeviceInfo.getDeviceLocale();
console.warn(code)
2020-03-20 18:28:22 +00:00
I18n.locale = code.toLowerCase()
readUser().then((result) => {
console.warn(result)
if (result) {
getPubActiveObject(result['country_id']).then((data) => {
console.warn(data)
this.config.setPubActive(data);
})
}
setTimeout(() => {
this.workUserResult(result)
}, 3000)
}).catch((e) => {
this.setPubActive(data)
});
2019-06-16 13:09:54 +00:00
2020-03-20 18:28:22 +00:00
}
}).catch((e) => {
console.warn(e.message)
DeviceInfo.getDeviceLocale().then((code) => {
console.warn(code)
I18n.locale = code.toLowerCase()
readUser().then((result) => {
setTimeout(() => {
this.workUserResult(result)
}, 3000)
}).catch((e) => {
this.props.navigation.navigate("Auth")
});
})
})
return ""
}
2019-06-16 13:09:54 +00:00
}
2020-03-20 18:28:22 +00:00
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: theme.primary,
justifyContent: 'center',
alignItems: 'center',
},
logoContaner: {
flexDirection: 'row',
marginTop: responsiveHeight(20),
justifyContent: 'center',
alignItems: 'center',
},
logo: {
width: responsiveWidth(90),
resizeMode: 'contain'
},
lottie: {
width: 48
,
height: 64
},
title: {
fontSize: responsiveFontSize(4),
alignSelf: 'center',
fontWeight: 'bold',
color: 'white',
},
2019-06-16 13:09:54 +00:00
})