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

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. // @flow
  2. import React from 'react';
  3. import {StyleProvider, Root, View} 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. type Props = {};
  13. type State = {
  14. isLoading: boolean,
  15. currentTheme: ?Object,
  16. };
  17. export default class App extends React.Component<Props, State> {
  18. state = {
  19. isLoading: true,
  20. currentTheme: null,
  21. };
  22. constructor(props: Object) {
  23. super(props);
  24. LocaleManager.initTranslations();
  25. }
  26. /**
  27. * Loads FetchedData before components are mounted, like fonts and themes
  28. * @returns {Promise}
  29. */
  30. async componentWillMount() {
  31. await Font.loadAsync({
  32. 'Roboto': require('native-base/Fonts/Roboto.ttf'),
  33. 'Roboto_medium': require('native-base/Fonts/Roboto_medium.ttf'),
  34. });
  35. ThemeManager.getInstance().setUpdateThemeCallback(() => this.updateTheme());
  36. await ThemeManager.getInstance().getDataFromPreferences();
  37. this.setState({
  38. isLoading: false,
  39. currentTheme: ThemeManager.getInstance().getCurrentTheme()
  40. });
  41. }
  42. /**
  43. * Updates the theme and clears the cache to force reloading the app colors
  44. */
  45. updateTheme() {
  46. // console.log('update theme called');
  47. this.setState({
  48. currentTheme: ThemeManager.getInstance().getCurrentTheme()
  49. });
  50. clearThemeCache();
  51. }
  52. /**
  53. * Renders the app based on loading state
  54. *
  55. * @returns {*}
  56. */
  57. render() {
  58. if (this.state.isLoading) {
  59. return <View/>;
  60. }
  61. // console.log('rendering');
  62. // console.log(this.state.currentTheme.variables.containerBgColor);
  63. return (
  64. <Root>
  65. <StyleProvider style={this.state.currentTheme}>
  66. <AppNavigator/>
  67. </StyleProvider>
  68. </Root>
  69. );
  70. }
  71. }