2019-06-29 13:37:21 +02:00
// @flow
2019-08-06 13:28:11 +02:00
import * as React from 'react' ;
2019-08-05 17:18:48 +02:00
import { Root , StyleProvider , Text } from 'native-base' ;
2019-08-06 13:28:11 +02:00
import { Image , StyleSheet , View } from 'react-native'
2019-06-25 22:20:24 +02:00
import AppNavigator from './navigation/AppNavigator' ;
import ThemeManager from './utils/ThemeManager' ;
import LocaleManager from './utils/LocaleManager' ;
import * as Font from 'expo-font' ;
2019-08-05 17:18:48 +02:00
import { LinearGradient } from 'expo-linear-gradient' ;
import AppIntroSlider from 'react-native-app-intro-slider' ;
2019-06-28 11:35:15 +02:00
// edited native-base-shoutem-theme according to
// https://github.com/GeekyAnts/theme/pull/5/files/91f67c55ca6e65fe3af779586b506950c9f331be#diff-4cfc2dd4d5dae7954012899f2268a422
// to allow for dynamic theme switching
2019-06-29 13:37:21 +02:00
import { clearThemeCache } from 'native-base-shoutem-theme' ;
2019-07-31 14:22:36 +02:00
import AsyncStorageManager from "./utils/AsyncStorageManager" ;
2019-08-05 17:18:48 +02:00
import CustomMaterialIcon from "./components/CustomMaterialIcon" ;
2019-08-07 10:24:35 +02:00
import SideBar from "./components/Sidebar" ;
import SideMenu from "react-native-side-menu" ;
2019-08-05 17:18:48 +02:00
const styles = StyleSheet . create ( {
mainContent : {
flex : 1 ,
alignItems : 'center' ,
justifyContent : 'center' ,
paddingBottom : 100
} ,
image : {
width : 200 ,
height : 200 ,
} ,
text : {
color : 'rgba(255, 255, 255, 0.8)' ,
backgroundColor : 'transparent' ,
textAlign : 'center' ,
paddingHorizontal : 16 ,
} ,
title : {
fontSize : 22 ,
color : 'white' ,
backgroundColor : 'transparent' ,
textAlign : 'center' ,
marginBottom : 16 ,
} ,
} ) ;
2019-08-06 13:28:11 +02:00
// Content to be used int the intro slides
2019-08-05 17:18:48 +02:00
const slides = [
{
key : '1' ,
2019-08-07 11:10:17 +02:00
title : 'Bienvenue sur COFFEE' ,
text : ' La nouvelle app à consulter pendant la pause café pour être au courant de la vie du campus !' ,
2019-08-05 17:18:48 +02:00
image : require ( './assets/amicale.png' ) ,
colors : [ '#ff8a6d' , '#aa1c0d' ] ,
} ,
{
key : '2' ,
2019-08-07 11:10:17 +02:00
title : 'Restez informés' ,
text : 'COFFEE vous permettra bientôt d\'être au courant de tous les événements qui ont lieu sur le campus, de la vente de crêpes jusqu\'aux concerts enfoiros !' ,
icon : 'calendar-range' ,
2019-08-05 17:18:48 +02:00
colors : [ '#9cd6d3' , '#3186be' ] ,
} ,
{
key : '3' ,
2019-08-07 11:10:17 +02:00
title : 'N\'oubliez plus votre linge !' ,
text : 'COFFEE vous informe de la disponibilité des machines et vous permet d\'être notifiés lorsque la vôtre se termine bientôt !' ,
icon : 'washing-machine' ,
2019-08-05 17:18:48 +02:00
colors : [ '#f9a967' , '#da5204' ] ,
} ,
{
key : '4' ,
2019-08-07 11:10:17 +02:00
title : 'Proximo' ,
text : 'Il vous manque des pâtes ? Ou un petit creux au gouter, regardez les stocks de votre supérette insaienne en temps réel' ,
icon : 'shopping' ,
colors : [ '#f9a967' , '#da5204' ] ,
} ,
{
key : '5' ,
title : 'Planex' ,
text : 'Consultez votre emploi du temps sur COFFEE' ,
icon : 'timetable' ,
colors : [ '#f9a967' , '#da5204' ] ,
} ,
{
key : '6' ,
2019-08-05 17:18:48 +02:00
title : 'Toujours en développement' ,
2019-08-07 11:10:17 +02:00
text : 'D\'autres fonctionnalités arrivent bientôt, n\'hésitez pas à nous donner votre avis pour améliorer l\'appli' ,
icon : 'cogs' ,
2019-08-05 17:18:48 +02:00
colors : [ '#9be238' , '#1e6a22' ] ,
} ,
] ;
2019-06-29 13:37:21 +02:00
type Props = { } ;
type State = {
isLoading : boolean ,
2019-08-05 17:18:48 +02:00
showIntro : boolean ,
2019-06-29 13:37:21 +02:00
currentTheme : ? Object ,
} ;
export default class App extends React . Component < Props , State > {
2019-06-25 22:16:14 +02:00
2019-06-29 13:37:21 +02:00
state = {
isLoading : true ,
2019-08-05 17:18:48 +02:00
showIntro : true ,
2019-06-29 13:37:21 +02:00
currentTheme : null ,
} ;
2019-06-25 22:20:24 +02:00
2019-06-29 13:37:21 +02:00
constructor ( props : Object ) {
2019-06-25 22:20:24 +02:00
super ( props ) ;
2019-06-29 13:37:21 +02:00
LocaleManager . initTranslations ( ) ;
2019-06-25 22:20:24 +02:00
}
2019-06-29 13:37:21 +02:00
/ * *
2019-07-26 14:14:01 +02:00
* Loads FetchedData before components are mounted , like fonts and themes
2019-06-29 13:37:21 +02:00
* @ returns { Promise }
* /
2019-06-25 22:20:24 +02:00
async componentWillMount ( ) {
2019-08-06 13:28:11 +02:00
// Wait for custom fonts to be loaded before showing the app
2019-06-25 22:20:24 +02:00
await Font . loadAsync ( {
'Roboto' : require ( 'native-base/Fonts/Roboto.ttf' ) ,
'Roboto_medium' : require ( 'native-base/Fonts/Roboto_medium.ttf' ) ,
} ) ;
2019-07-31 14:22:36 +02:00
await AsyncStorageManager . getInstance ( ) . loadPreferences ( ) ;
2019-06-29 13:37:21 +02:00
ThemeManager . getInstance ( ) . setUpdateThemeCallback ( ( ) => this . updateTheme ( ) ) ;
2019-08-06 13:28:11 +02:00
// Only show intro if this is the first time starting the app
2019-06-25 22:20:24 +02:00
this . setState ( {
isLoading : false ,
2019-08-05 17:18:48 +02:00
currentTheme : ThemeManager . getCurrentTheme ( ) ,
2019-08-07 11:10:17 +02:00
// showIntro: AsyncStorageManager.getInstance().preferences.showIntro.current === '1'
showIntro : true
2019-06-25 22:20:24 +02:00
} ) ;
}
2019-06-29 13:37:21 +02:00
/ * *
2019-08-06 13:28:11 +02:00
* Updates the theme and clears the cache to force reloading the app colors . Need to edit shoutem theme for ti to work
2019-06-29 13:37:21 +02:00
* /
2019-06-25 22:20:24 +02:00
updateTheme ( ) {
2019-06-28 11:35:15 +02:00
this . setState ( {
2019-07-31 14:22:36 +02:00
currentTheme : ThemeManager . getCurrentTheme ( )
2019-06-28 11:35:15 +02:00
} ) ;
2019-08-05 14:52:18 +02:00
clearThemeCache ( ) ;
2019-06-25 22:20:24 +02:00
}
2019-08-06 13:28:11 +02:00
/ * *
* Render item to be used for the intro slides
* @ param item
* @ param dimensions
* /
2019-08-05 17:18:48 +02:00
getIntroRenderItem ( item : Object , dimensions : Object ) {
return (
< LinearGradient
style = { [
styles . mainContent ,
dimensions ,
] }
colors = { item . colors }
start = { { x : 0 , y : 0.1 } }
end = { { x : 0.1 , y : 1 } }
>
{ item . image !== undefined ?
< Image source = { item . image } style = { styles . image } / >
: < CustomMaterialIcon icon = { item . icon } color = { '#fff' } fontSize = { 200 } width = { 200 } / > }
< View style = { { marginTop : 20 } } >
< Text style = { styles . title } > { item . title } < / T e x t >
< Text style = { styles . text } > { item . text } < / T e x t >
< / V i e w >
< / L i n e a r G r a d i e n t >
) ;
}
2019-08-06 13:28:11 +02:00
/ * *
* Callback when user ends the intro . Save in preferences to avaoid showing back the slides
* /
2019-08-05 17:18:48 +02:00
onIntroDone ( ) {
this . setState ( { showIntro : false } ) ;
AsyncStorageManager . getInstance ( ) . savePref ( AsyncStorageManager . getInstance ( ) . preferences . showIntro . key , '0' ) ;
}
2019-06-29 13:37:21 +02:00
/ * *
* Renders the app based on loading state
* /
2019-06-25 22:20:24 +02:00
render ( ) {
if ( this . state . isLoading ) {
return < View / > ;
}
2019-08-05 17:18:48 +02:00
if ( this . state . showIntro ) {
return < AppIntroSlider renderItem = { ( { item , dimensions } ) => this . getIntroRenderItem ( item , dimensions ) }
slides = { slides } onDone = { ( ) => this . onIntroDone ( ) } bottomButton showSkipButton / > ;
} else {
return (
< Root >
< StyleProvider style = { this . state . currentTheme } >
2019-08-07 10:24:35 +02:00
< AppNavigator / >
2019-08-05 17:18:48 +02:00
< / S t y l e P r o v i d e r >
< / R o o t >
) ;
}
2019-06-25 22:20:24 +02:00
}
2019-08-07 10:24:35 +02:00
menu = < View / > ;
2019-06-25 22:20:24 +02:00
}