Created
September 16, 2019 16:14
-
-
Save yvsssantosh/4f4639fce61155b8b5dfe48686297d7b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// import React from 'react' | |
// import { StyleSheet, Text, View } from 'react-native' | |
// export default function App () { | |
// return ( | |
// <View style={styles.container}> | |
// <Text>Shili</Text> | |
// </View> | |
// ) | |
// } | |
// const styles = StyleSheet.create({ | |
// container: { | |
// flex: 1, | |
// backgroundColor: '#fff', | |
// alignItems: 'center', | |
// justifyContent: 'center' | |
// } | |
// }) | |
/** | |
* Sample React Native App | |
* https://github.com/facebook/react-native | |
* | |
* @format | |
* @flow | |
*/ | |
import React, { PureComponent } from 'react' | |
import { connect } from 'react-redux' | |
import { Text, View, ActivityIndicator, AsyncStorage } from 'react-native' | |
// Custom imports | |
import actionCreator from './src/screens/login' | |
import AppNavigation from './src/shared/navigation' | |
class AppRoot extends PureComponent { | |
constructor (props) { | |
super(props) | |
} | |
componentDidMount () { | |
console.log('INSIDE CDM') | |
this.props.checkLogin() | |
} | |
render () { | |
const { appStarted, authenticated } = this.props.authState | |
console.log('APP STARTING STATUS : ', appStarted) | |
return appStarted ? this._renderAppRoot(authenticated) : this._renderSplash(appStarted) | |
} | |
_renderAppRoot (authenticated) { | |
const CreateRoot = AppNavigation(authenticated) | |
return <CreateRoot /> | |
} | |
_renderSplash (appStarted) { | |
return ( | |
<View style={{ flex: 1, justifyContent: 'center', alignItems: 'center' }}> | |
<ActivityIndicator size='large' animating={!appStarted} /> | |
<Text children='Loading...' /> | |
{console.log('INSIDE CONSTRUCTOR')} | |
</View> | |
) | |
} | |
} | |
const mapDispatchToProps = (dispatch, ownProps) => { | |
return { | |
async checkLogin () { | |
const isLoggedIn = await AsyncStorage.getItem('authenticated').catch(e => console.log(e)) | |
console.log('IS LOGGED IN : ', isLoggedIn) | |
if (isLoggedIn) { | |
await dispatch(actionCreator('LOGIN_SUCCESS')) | |
} | |
await dispatch(actionCreator('APP_LOADED')) | |
} | |
} | |
} | |
const mapStateToProps = (state, ownProps) => { | |
return { | |
authState: state.authState | |
} | |
} | |
export default connect(mapStateToProps, mapDispatchToProps)(AppRoot) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment