Created
September 7, 2018 23:31
-
-
Save linux08/afbf2cb2eb6ce46022bbf924084e5544 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 { | |
ActivityIndicator, | |
AsyncStorage, | |
StatusBar, | |
StyleSheet, | |
View, | |
} from 'react-native'; | |
import { connect } from 'react-redux'; | |
import { getUserToken } from '../actions'; | |
class AuthLoadingScreen extends React.Component { | |
static navigationOptions = { | |
header: null, | |
}; | |
constructor() { | |
super(); | |
} | |
componentDidMount() { | |
this._bootstrapAsync(); | |
} | |
// Fetch the token from storage then navigate to our appropriate place | |
_bootstrapAsync = () => { | |
this.props.getUserToken().then(() => { | |
this.props.navigation.navigate(this.props.token.token !== null ? 'App' : 'Auth'); | |
}) | |
.catch(error => { | |
this.setState({ error }) | |
}) | |
}; | |
// Render any loading content that you like here | |
render() { | |
return ( | |
<View style={styles.container}> | |
<ActivityIndicator /> | |
<StatusBar barStyle="default" /> | |
</View> | |
); | |
} | |
} | |
const styles = StyleSheet.create({ | |
container: { | |
flex: 1, | |
alignItems: 'center', | |
justifyContent: 'center', | |
}, | |
}); | |
const mapStateToProps = state => ({ | |
token: state.token, | |
}); | |
const mapDispatchToProps = dispatch => ({ | |
getUserToken: () => dispatch(getUserToken()), | |
}); | |
export default connect(mapStateToProps, mapDispatchToProps)(AuthLoadingScreen); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment