Skip to content

Instantly share code, notes, and snippets.

@linux08
Created September 7, 2018 23:31
Show Gist options
  • Save linux08/afbf2cb2eb6ce46022bbf924084e5544 to your computer and use it in GitHub Desktop.
Save linux08/afbf2cb2eb6ce46022bbf924084e5544 to your computer and use it in GitHub Desktop.
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