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 5.7KB

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