Skip to content

Instantly share code, notes, and snippets.

@yvsssantosh
Created September 16, 2019 16:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yvsssantosh/4f4639fce61155b8b5dfe48686297d7b to your computer and use it in GitHub Desktop.
Save yvsssantosh/4f4639fce61155b8b5dfe48686297d7b to your computer and use it in GitHub Desktop.
// 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