Application Android et IOS pour l'amicale des élèves https://play.google.com/store/apps/details?id=fr.amicaleinsat.application
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

App.js 6.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  1. // @flow
  2. import * as React from 'react';
  3. import {Root, StyleProvider, Text} from 'native-base';
  4. import {Image, StyleSheet, View} from 'react-native'
  5. import AppNavigator from './navigation/AppNavigator';
  6. import ThemeManager from './utils/ThemeManager';
  7. import LocaleManager from './utils/LocaleManager';
  8. import * as Font from 'expo-font';
  9. import {LinearGradient} from 'expo-linear-gradient';
  10. import AppIntroSlider from 'react-native-app-intro-slider';
  11. // edited native-base-shoutem-theme according to
  12. // https://github.com/GeekyAnts/theme/pull/5/files/91f67c55ca6e65fe3af779586b506950c9f331be#diff-4cfc2dd4d5dae7954012899f2268a422
  13. // to allow for dynamic theme switching
  14. import {clearThemeCache} from 'native-base-shoutem-theme';
  15. import AsyncStorageManager from "./utils/AsyncStorageManager";
  16. import CustomMaterialIcon from "./components/CustomMaterialIcon";
  17. import SideBar from "./components/Sidebar";
  18. import SideMenu from "react-native-side-menu";
  19. const styles = StyleSheet.create({
  20. mainContent: {
  21. flex: 1,
  22. alignItems: 'center',
  23. justifyContent: 'center',
  24. paddingBottom: 100
  25. },
  26. image: {
  27. width: 200,
  28. height: 200,
  29. },
  30. text: {
  31. color: 'rgba(255, 255, 255, 0.8)',
  32. backgroundColor: 'transparent',
  33. textAlign: 'center',
  34. paddingHorizontal: 16,
  35. },
  36. title: {
  37. fontSize: 22,
  38. color: 'white',
  39. backgroundColor: 'transparent',
  40. textAlign: 'center',
  41. marginBottom: 16,
  42. },
  43. });
  44. // Content to be used int the intro slides
  45. const slides = [
  46. {
  47. key: '1',
  48. title: 'Bienvenue sur COFFEE',
  49. text: ' La nouvelle app à consulter pendant la pause café pour être au courant de la vie du campus !',
  50. image: require('./assets/drawer-cover.png'),
  51. colors: ['#e01928', '#be1522'],
  52. },
  53. {
  54. key: '2',
  55. title: 'Restez informés',
  56. 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 !',
  57. icon: 'calendar-range',
  58. colors: ['#d99e09', '#c28d08'],
  59. },
  60. {
  61. key: '3',
  62. title: 'N\'oubliez plus votre linge !',
  63. text: 'COFFEE vous informe de la disponibilité des machines et vous permet d\'être notifiés lorsque la vôtre se termine bientôt !',
  64. icon: 'washing-machine',
  65. colors: ['#1fa5ee', '#1c97da'],
  66. },
  67. {
  68. key: '4',
  69. title: 'Proximo',
  70. 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',
  71. icon: 'shopping',
  72. colors: ['#ec5904', '#da5204'],
  73. },
  74. {
  75. key: '5',
  76. title: 'Planex',
  77. text: 'Consultez votre emploi du temps sur COFFEE',
  78. icon: 'timetable',
  79. colors: ['#7c33ec', '#732fda'],
  80. },
  81. {
  82. key: '6',
  83. title: 'Toujours en développement',
  84. text: 'D\'autres fonctionnalités arrivent bientôt, n\'hésitez pas à nous donner votre avis pour améliorer l\'appli',
  85. icon: 'cogs',
  86. colors: ['#37c13e', '#26852b'],
  87. },
  88. ];
  89. type Props = {};
  90. type State = {
  91. isLoading: boolean,
  92. showIntro: boolean,
  93. currentTheme: ?Object,
  94. };
  95. export default class App extends React.Component<Props, State> {
  96. state = {
  97. isLoading: true,
  98. showIntro: true,
  99. currentTheme: null,
  100. };
  101. constructor(props: Object) {
  102. super(props);
  103. LocaleManager.initTranslations();
  104. }
  105. /**
  106. * Loads FetchedData before components are mounted, like fonts and themes
  107. * @returns {Promise}
  108. */
  109. async componentWillMount() {
  110. // Wait for custom fonts to be loaded before showing the app
  111. await Font.loadAsync({
  112. 'Roboto': require('native-base/Fonts/Roboto.ttf'),
  113. 'Roboto_medium': require('native-base/Fonts/Roboto_medium.ttf'),
  114. });
  115. await AsyncStorageManager.getInstance().loadPreferences();
  116. ThemeManager.getInstance().setUpdateThemeCallback(() => this.updateTheme());
  117. // Only show intro if this is the first time starting the app
  118. this.setState({
  119. isLoading: false,
  120. currentTheme: ThemeManager.getCurrentTheme(),
  121. // showIntro: AsyncStorageManager.getInstance().preferences.showIntro.current === '1'
  122. showIntro: true
  123. });
  124. }
  125. /**
  126. * Updates the theme and clears the cache to force reloading the app colors. Need to edit shoutem theme for ti to work
  127. */
  128. updateTheme() {
  129. this.setState({
  130. currentTheme: ThemeManager.getCurrentTheme()
  131. });
  132. clearThemeCache();
  133. }
  134. /**
  135. * Render item to be used for the intro slides
  136. * @param item
  137. * @param dimensions
  138. */
  139. getIntroRenderItem(item: Object, dimensions: Object) {
  140. return (
  141. <LinearGradient
  142. style={[
  143. styles.mainContent,
  144. dimensions,
  145. ]}
  146. colors={item.colors}
  147. start={{x: 0, y: 0.1}}
  148. end={{x: 0.1, y: 1}}
  149. >
  150. {item.image !== undefined ?
  151. <Image source={item.image} style={styles.image}/>
  152. : <CustomMaterialIcon icon={item.icon} color={'#fff'} fontSize={200} width={200}/>}
  153. <View style={{marginTop: 20}}>
  154. <Text style={styles.title}>{item.title}</Text>
  155. <Text style={styles.text}>{item.text}</Text>
  156. </View>
  157. </LinearGradient>
  158. );
  159. }
  160. /**
  161. * Callback when user ends the intro. Save in preferences to avaoid showing back the slides
  162. */
  163. onIntroDone() {
  164. this.setState({showIntro: false});
  165. AsyncStorageManager.getInstance().savePref(AsyncStorageManager.getInstance().preferences.showIntro.key, '0');
  166. }
  167. /**
  168. * Renders the app based on loading state
  169. */
  170. render() {
  171. if (this.state.isLoading) {
  172. return <View/>;
  173. }
  174. if (this.state.showIntro) {
  175. return <AppIntroSlider renderItem={({item, dimensions}) => this.getIntroRenderItem(item, dimensions)}
  176. slides={slides} onDone={() => this.onIntroDone()} bottomButton showSkipButton/>;
  177. } else {
  178. return (
  179. <Root>
  180. <StyleProvider style={this.state.currentTheme}>
  181. <AppNavigator/>
  182. </StyleProvider>
  183. </Root>
  184. );
  185. }
  186. }
  187. menu = <View/>;
  188. }