This repository has been archived on 2023-03-26. You can view files and clone it, but cannot push or open issues or pull requests.
Sphere/app/components/app.js

94 lines
2.1 KiB
JavaScript
Raw Normal View History

2016-02-01 20:58:00 +00:00
import React from 'react-native';
import RouteMaster from './routes/RouteMaster';
2016-02-06 15:07:29 +00:00
import RouteMapper from './navigation/RouteMapper';
2016-02-06 15:49:57 +00:00
import GlobalStyles from '../settings/styles';
2016-02-21 12:05:14 +00:00
import BusyIndicator from 'react-native-busy-indicator';
2016-05-05 18:25:00 +01:00
import token from '../api/token';
import { checkToken } from '../api/CircleCI';
2016-02-01 20:58:00 +00:00
require('moment-duration-format');
2016-02-01 20:58:00 +00:00
const {
Navigator,
2016-02-06 15:07:29 +00:00
StyleSheet,
Platform,
View
2016-02-01 20:58:00 +00:00
} = React;
2016-02-06 15:07:29 +00:00
const styles = StyleSheet.create({
navbar: {
2016-02-06 15:49:57 +00:00
backgroundColor: GlobalStyles.get('CIRCLE_NAVBAR_BG'),
2016-02-06 15:07:29 +00:00
flexDirection:'row',
justifyContent: 'center',
},
container: {
flex: 1,
marginTop: (Platform.OS === 'ios' ? 64 : 56)
}
});
2016-02-01 20:58:00 +00:00
export default class extends React.Component {
2016-05-05 18:25:00 +01:00
constructor() {
super();
this.state = {
initialRoute: false
};
}
2016-02-01 20:58:00 +00:00
renderScene(route, nav) {
2016-02-06 15:07:29 +00:00
const Component = route.component;
2016-02-01 20:58:00 +00:00
const props = route.props || {};
2016-02-06 15:07:29 +00:00
return (
<View style={styles.container}>
<Component
nav={nav}
2016-02-23 23:12:32 +00:00
currentRoute={route}
2016-02-06 15:07:29 +00:00
{...props} />
</View>
);
2016-02-01 20:58:00 +00:00
}
2016-02-01 21:50:50 +00:00
componentWillMount() {
2016-05-05 18:25:00 +01:00
token.get().then(function (CIToken) {
if (!CIToken) {
this.setState({
initialRoute: RouteMaster.get('HOME')
});
return;
}
checkToken(CIToken).then(function (isValid) {
this.setState({
initialRoute: isValid ? RouteMaster.get('HOME') : RouteMaster.get('LOGIN')
});
}.bind(this));
}.bind(this));
2016-02-01 20:58:00 +00:00
}
render() {
2016-05-05 18:25:00 +01:00
if (!this.state.initialRoute) {
return null; // Replace with a splash screen?
}
2016-02-01 20:58:00 +00:00
return (
2016-03-11 20:53:33 +00:00
<View style={{ flex: 1 }}>
<Navigator
renderScene={this.renderScene}
2016-05-05 18:25:00 +01:00
initialRoute={this.state.initialRoute}
2016-03-11 20:53:33 +00:00
navigationBar={
<Navigator.NavigationBar
style={styles.navbar}
routeMapper={RouteMapper} />
2016-02-01 20:58:00 +00:00
}
2016-03-11 20:53:33 +00:00
configureScene={(route) => {
if (route.sceneConfig) {
return route.sceneConfig;
}
return Navigator.SceneConfigs.PushFromRight;
}}
/>
<BusyIndicator />
</View>
2016-02-01 20:58:00 +00:00
);
}
};