import React, { Component } from "react";
import {PermissionsAndroid,View,StyleSheet,Animated,Dimensions,AsyncStorage} from "react-native";
import { CommonActions } from '@react-navigation/native';
import { Constants } from '../common';
import utils from "../utils";
import DeviceInfo from 'react-native-device-info';
import { getUniqueId, getManufacturer } from 'react-native-device-info';
const { width } = Dimensions.get('window');
const resetLoginAction = CommonActions.reset({
index: 1,
routes: [
{ name: 'Home' },
],
})
const resetActionApp = CommonActions.reset({
index: 1,
routes: [
{ name: 'SignIn' },
],
})
let uniqueId = DeviceInfo.getUniqueId();
export default class Splash extends Component {
constructor(props) {
super(props);
this.state = {
ready: false,
SlideInLeft: new Animated.Value(0),
slideUpValue: new Animated.Value(0),
fadeValue: new Animated.Value(0),
}
}
async componentDidMount() {
this._start()
setTimeout(() => {
this._retrieveData()
}, 3000);
}
_start = async () => {
return Animated.parallel([
Animated.timing(this.state.SlideInLeft, {
toValue: 1,
duration: 500,
useNativeDriver: true
}),
Animated.timing(this.state.fadeValue, {
toValue: 1,
duration: 500,
useNativeDriver: true
}),
Animated.timing(this.state.slideUpValue, {
toValue: 1,
duration: 500,
useNativeDriver: true
})
]).start();
};
_retrieveData = async () => {
try {
const value = await AsyncStorage.getItem('LoginDetails');
// console.log(value+"data get")
if (value !== null) {
if(JSON.parse(value).is_guest) {
this.props.navigation.dispatch(resetLoginAction);
}
else {
utils.setUserData(value);
this.props.navigation.dispatch(resetLoginAction);
}
} else {
this.props.navigation.dispatch(resetActionApp);
}
} catch (error) {
console.log(error);
// Error retrieving data
}
};
render() {
let { slideUpValue, fadeValue, SlideInLeft } = this.state;
return (
<Animated.Image
source={Constants.Splash_bg}
style={{
transform: [
{
translateY: slideUpValue.interpolate({
inputRange: [0, 1],
outputRange: [-200, 0]
})
}
],
flex: 1,
width: width,
resizeMode: 'contain',
justifyContent: "center"
}}
/>
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: "#FFF",
alignItems: "center"
},
item: {},
btn: {
backgroundColor: "#480032",
width: 100,
height: 40,
padding: 3,
justifyContent: "center",
borderRadius: 6,
marginTop: 29
},
text: {
fontSize: 20,
color: "#fff",
fontWeight: "bold",
textAlign: "center"
},
item1: {
backgroundColor: "red",
padding: 20,
width: 100,
margin: 10
},
textBtn: {
color: "#f4f4f4",
fontWeight: "bold",
textAlign: "center"
}
});