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.4KB

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