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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. // @flow
  2. import * as React from 'react';
  3. import {Root, StyleProvider} from 'native-base';
  4. import {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. // edited native-base-shoutem-theme according to
  10. // https://github.com/GeekyAnts/theme/pull/5/files/91f67c55ca6e65fe3af779586b506950c9f331be#diff-4cfc2dd4d5dae7954012899f2268a422
  11. // to allow for dynamic theme switching
  12. import {clearThemeCache} from 'native-base-shoutem-theme';
  13. import AsyncStorageManager from "./utils/AsyncStorageManager";
  14. import CustomIntroSlider from "./components/CustomIntroSlider";
  15. type Props = {};
  16. type State = {
  17. isLoading: boolean,
  18. showIntro: boolean,
  19. currentTheme: ?Object,
  20. };
  21. export default class App extends React.Component<Props, State> {
  22. state = {
  23. isLoading: true,
  24. showIntro: true,
  25. currentTheme: null,
  26. };
  27. constructor(props: Object) {
  28. super(props);
  29. LocaleManager.initTranslations();
  30. }
  31. /**
  32. * Loads FetchedData before components are mounted, like fonts and themes
  33. * @returns {Promise}
  34. */
  35. async componentWillMount() {
  36. // Wait for custom fonts to be loaded before showing the app
  37. await Font.loadAsync({
  38. 'Roboto': require('native-base/Fonts/Roboto.ttf'),
  39. 'Roboto_medium': require('native-base/Fonts/Roboto_medium.ttf'),
  40. });
  41. await AsyncStorageManager.getInstance().loadPreferences();
  42. ThemeManager.getInstance().setUpdateThemeCallback(() => this.updateTheme());
  43. // Only show intro if this is the first time starting the app
  44. this.setState({
  45. isLoading: false,
  46. currentTheme: ThemeManager.getCurrentTheme(),
  47. showIntro: AsyncStorageManager.getInstance().preferences.showIntro.current === '1'
  48. // showIntro: true
  49. });
  50. }
  51. /**
  52. * Updates the theme and clears the cache to force reloading the app colors. Need to edit shoutem theme for ti to work
  53. */
  54. updateTheme() {
  55. this.setState({
  56. currentTheme: ThemeManager.getCurrentTheme()
  57. });
  58. clearThemeCache();
  59. }
  60. /**
  61. * Callback when user ends the intro. Save in preferences to avaoid showing back the slides
  62. */
  63. onIntroDone() {
  64. this.setState({showIntro: false});
  65. AsyncStorageManager.getInstance().savePref(AsyncStorageManager.getInstance().preferences.showIntro.key, '0');
  66. }
  67. /**
  68. * Renders the app based on loading state
  69. */
  70. render() {
  71. if (this.state.isLoading) {
  72. return <View/>;
  73. }
  74. if (this.state.showIntro) {
  75. return <CustomIntroSlider onDone={() => this.onIntroDone()}/>;
  76. } else {
  77. return (
  78. <Root>
  79. <StyleProvider style={this.state.currentTheme}>
  80. <AppNavigator/>
  81. </StyleProvider>
  82. </Root>
  83. );
  84. }
  85. }
  86. }