{"size": 2600, "ext": "js", "max_stars_repo_path": "App.js", "max_stars_repo_name": "chathurangiamarathunga/SmartWalletGuide", "max_stars_repo_stars_event_min_datetime": "2019-12-07T11:23:56.000Z", "max_stars_repo_stars_event_max_datetime": "2019-12-10T16:02:10.000Z", "max_issues_repo_path": "App.js", "max_issues_repo_name": "chathurangiamarathunga/SmartWalletGuide", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "App.js", "max_forks_repo_name": "chathurangiamarathunga/SmartWalletGuide", "max_forks_repo_forks_event_min_datetime": "2019-12-03T06:21:51.000Z", "max_forks_repo_forks_event_max_datetime": "2019-12-03T06:21:51.000Z"}
{"max_stars_count": 3, "max_issues_count": null, "max_forks_count": 1, "avg_line_length": 30.2325581395, "max_line_length": 113, "alphanum_fraction": 0.5765384615}
import React from 'react';
import {ActivityIndicator, Text, View,ImageBackground} from 'react-native';
import DrawerNavigator from './lib/navigation/drawerNavigator';
import {createAppContainer, createSwitchNavigator} from 'react-navigation';
import {createStackNavigator} from 'react-navigation-stack';
import LoginScreen from './screens/authentication/loginScreen';
import RegisterScreen from './screens/authentication/registerScreen';
import WelcomeScreen from './screens/authentication/welcomeScreen';
import AsyncStorage from '@react-native-community/async-storage';
import GlobalService from './lib/service/globalService';
import Webservice from './lib/api/webService';

class App extends React.Component {
    constructor(props) {
        super(props);
        GlobalService.set('main_navigation', props.navigation);
        AsyncStorage.getItem('userData').then(response => {
            if (response !== null) {
                let userData= JSON.parse(response)
                Webservice.login(userData.email,userData.password).then(response=>{
                    if(response.ok){
                        this.props.navigation.navigate('Auth');
                    }else{
                        this.props.navigation.navigate('Login');
                    }
                })
            } else {
                this.props.navigation.navigate('Welcome');
            }
        });
    }

    render() {
        return (
            <View style={{flex: 1}}>
                <ImageBackground source={require('./assets/Splash.jpg')} style={{width: "100%", height: "100%"}}>
                    <View style={{
                        flex:1,justifyContent: 'center', alignItems: 'center', alignContent: 'center'
                    }}>
                    <ActivityIndicator size="large" color="#000"/>
                    </View>
                </ImageBackground>
            </View>
        );
    }
}

const SignInStack = createStackNavigator({
    Login: LoginScreen,
    Register: RegisterScreen,
}, {
    headerMode: 'none',
    navigationOptions: {
        headerVisible: false,
    },
});

const Navigation = createAppContainer(createSwitchNavigator(
    {
        App: App,
        SignIn: SignInStack,
        Welcome: WelcomeScreen,
        Auth: DrawerNavigator,
    },
    {
        initialRouteName: 'App',
    },
));

export default class AppContainer extends React.Component {
    constructor(props) {
        super(props);

    }

    render() {
        return (
            <View style={{flex: 1}}>
                <Navigation/>
            </View>

        );
    }
}

