Application Android et IOS pour l'amicale des élèves
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 5.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  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: 'L\'application de l\'Amicale',
  49. text: 'Toutes les informations du campus de Toulouse',
  50. image: require('./assets/amicale.png'),
  51. colors: ['#ff8a6d', '#aa1c0d'],
  52. },
  53. {
  54. key: '2',
  55. title: 'N\'oubliez plus votre linge',
  56. text: 'Visualisez les disponibilités des machines et rajoutez des alarmes',
  57. icon: 'washing-machine',
  58. colors: ['#9cd6d3', '#3186be'],
  59. },
  60. {
  61. key: '3',
  62. title: 'Le proximo',
  63. text: 'Regardez le stock de la supérette de l\'INSA depuis n\'importe où',
  64. icon: 'shopping',
  65. colors: ['#f9a967', '#da5204'],
  66. },
  67. {
  68. key: '4',
  69. title: 'Toujours en développement',
  70. text: 'D\'autres fonctionnalités seront disponibles prochainement',
  71. icon: 'settings-outline',
  72. colors: ['#9be238', '#1e6a22'],
  73. },
  74. ];
  75. type Props = {};
  76. type State = {
  77. isLoading: boolean,
  78. showIntro: boolean,
  79. currentTheme: ?Object,
  80. };
  81. export default class App extends React.Component<Props, State> {
  82. state = {
  83. isLoading: true,
  84. showIntro: true,
  85. currentTheme: null,
  86. };
  87. constructor(props: Object) {
  88. super(props);
  89. LocaleManager.initTranslations();
  90. }
  91. /**
  92. * Loads FetchedData before components are mounted, like fonts and themes
  93. * @returns {Promise}
  94. */
  95. async componentWillMount() {
  96. // Wait for custom fonts to be loaded before showing the app
  97. await Font.loadAsync({
  98. 'Roboto': require('native-base/Fonts/Roboto.ttf'),
  99. 'Roboto_medium': require('native-base/Fonts/Roboto_medium.ttf'),
  100. });
  101. await AsyncStorageManager.getInstance().loadPreferences();
  102. ThemeManager.getInstance().setUpdateThemeCallback(() => this.updateTheme());
  103. // Only show intro if this is the first time starting the app
  104. this.setState({
  105. isLoading: false,
  106. currentTheme: ThemeManager.getCurrentTheme(),
  107. showIntro: AsyncStorageManager.getInstance().preferences.showIntro.current === '1'
  108. });
  109. }
  110. /**
  111. * Updates the theme and clears the cache to force reloading the app colors. Need to edit shoutem theme for ti to work
  112. */
  113. updateTheme() {
  114. this.setState({
  115. currentTheme: ThemeManager.getCurrentTheme()
  116. });
  117. clearThemeCache();
  118. }
  119. /**
  120. * Render item to be used for the intro slides
  121. * @param item
  122. * @param dimensions
  123. */
  124. getIntroRenderItem(item: Object, dimensions: Object) {
  125. return (
  126. <LinearGradient
  127. style={[
  128. styles.mainContent,
  129. dimensions,
  130. ]}
  131. colors={item.colors}
  132. start={{x: 0, y: 0.1}}
  133. end={{x: 0.1, y: 1}}
  134. >
  135. {item.image !== undefined ?
  136. <Image source={item.image} style={styles.image}/>
  137. : <CustomMaterialIcon icon={item.icon} color={'#fff'} fontSize={200} width={200}/>}
  138. <View style={{marginTop: 20}}>
  139. <Text style={styles.title}>{item.title}</Text>
  140. <Text style={styles.text}>{item.text}</Text>
  141. </View>
  142. </LinearGradient>
  143. );
  144. }
  145. /**
  146. * Callback when user ends the intro. Save in preferences to avaoid showing back the slides
  147. */
  148. onIntroDone() {
  149. this.setState({showIntro: false});
  150. AsyncStorageManager.getInstance().savePref(AsyncStorageManager.getInstance().preferences.showIntro.key, '0');
  151. }
  152. /**
  153. * Renders the app based on loading state
  154. */
  155. render() {
  156. if (this.state.isLoading) {
  157. return <View/>;
  158. }
  159. if (this.state.showIntro) {
  160. return <AppIntroSlider renderItem={({item, dimensions}) => this.getIntroRenderItem(item, dimensions)}
  161. slides={slides} onDone={() => this.onIntroDone()} bottomButton showSkipButton/>;
  162. } else {
  163. return (
  164. <Root>
  165. <StyleProvider style={this.state.currentTheme}>
  166. <AppNavigator/>
  167. </StyleProvider>
  168. </Root>
  169. );
  170. }
  171. }
  172. menu = <View/>;
  173. }