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.

ThemeManager.js 1.4KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. import {AsyncStorage} from 'react-native'
  2. import platform from '../native-base-theme/variables/platform';
  3. import platformDark from '../native-base-theme/variables/platformDark';
  4. import getTheme from '../native-base-theme/components';
  5. const nightModeKey = 'nightMode';
  6. export default class ThemeManager {
  7. static instance = null;
  8. constructor() {
  9. this.nightMode = false;
  10. this.updateThemeCallback = undefined;
  11. }
  12. static getInstance() {
  13. if (ThemeManager.instance == null) {
  14. ThemeManager.instance = new ThemeManager();
  15. }
  16. return this.instance;
  17. }
  18. setUpdateThemeCallback(callback) {
  19. this.updateThemeCallback = callback;
  20. }
  21. async getDataFromPreferences() {
  22. let result = await AsyncStorage.getItem(nightModeKey);
  23. if (result === '1')
  24. this.nightMode = true;
  25. console.log('nightmode: ' + this.nightMode);
  26. }
  27. setNightmode(isNightMode) {
  28. this.nightMode = isNightMode;
  29. AsyncStorage.setItem(nightModeKey, isNightMode ? '1' : '0');
  30. if (this.updateThemeCallback !== undefined)
  31. this.updateThemeCallback();
  32. }
  33. getNightMode() {
  34. return this.nightMode;
  35. }
  36. getCurrentTheme() {
  37. if (this.nightMode)
  38. return getTheme(platformDark);
  39. else
  40. return getTheme(platform);
  41. }
  42. getCurrentThemeVariables() {
  43. return this.getCurrentTheme().variables;
  44. }
  45. };