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.

ThemeManager.js 4.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. // @flow
  2. import AsyncStorageManager from "./AsyncStorageManager";
  3. // import {DarkTheme as NavDarkTheme, DefaultTheme as NavDefaultTheme} from '@react-navigation/native';
  4. import {DarkTheme, DefaultTheme} from 'react-native-paper';
  5. /**
  6. * Singleton class used to manage themes
  7. */
  8. export default class ThemeManager {
  9. static instance: ThemeManager | null = null;
  10. updateThemeCallback: Function;
  11. constructor() {
  12. this.updateThemeCallback = null;
  13. }
  14. static getWhiteTheme() {
  15. return {
  16. ...DefaultTheme,
  17. colors: {
  18. ...DefaultTheme.colors,
  19. primary: '#be1522',
  20. accent: '#be1522',
  21. card: "rgb(255, 255, 255)",
  22. dividerBackground: '#e2e2e2',
  23. textDisabled: '#c1c1c1',
  24. icon: '#5d5d5d',
  25. success: "#5cb85c",
  26. warning: "#f0ad4e",
  27. danger: "#d9534f",
  28. // Calendar/Agenda
  29. agendaBackgroundColor: '#f3f3f4',
  30. agendaDayTextColor: '#636363',
  31. // PROXIWASH
  32. proxiwashFinishedColor: "rgba(54,165,22,0.31)",
  33. proxiwashReadyColor: "transparent",
  34. proxiwashRunningColor: "rgba(94,104,241,0.3)",
  35. proxiwashRunningBgColor: "rgba(99,109,255,0.14)",
  36. proxiwashBrokenColor: "rgba(162,162,162,0.31)",
  37. proxiwashErrorColor: "rgba(204,7,0,0.31)",
  38. // Screens
  39. planningColor: '#d9b10a',
  40. proximoColor: '#ec5904',
  41. proxiwashColor: '#1fa5ee',
  42. menuColor: '#e91314',
  43. tutorinsaColor: '#f93943',
  44. },
  45. };
  46. }
  47. static getDarkTheme() {
  48. return {
  49. ...DarkTheme,
  50. colors: {
  51. ...DarkTheme.colors,
  52. primary: '#be1522',
  53. accent: '#be1522',
  54. card: "rgb(18, 18, 18)",
  55. dividerBackground: '#222222',
  56. textDisabled: '#5b5b5b',
  57. icon: '#b3b3b3',
  58. success: "#5cb85c",
  59. warning: "#f0ad4e",
  60. danger: "#d9534f",
  61. // Calendar/Agenda
  62. agendaBackgroundColor: '#171717',
  63. agendaDayTextColor: '#6d6d6d',
  64. // PROXIWASH
  65. proxiwashFinishedColor: "rgba(17,149,32,0.53)",
  66. proxiwashReadyColor: "transparent",
  67. proxiwashRunningColor: "rgba(29,59,175,0.65)",
  68. proxiwashRunningBgColor: "rgba(99,109,255,0.14)",
  69. proxiwashBrokenColor: "#000000",
  70. proxiwashErrorColor: "rgba(213,8,0,0.57)",
  71. // Screens
  72. planningColor: '#d99e09',
  73. proximoColor: '#ec5904',
  74. proxiwashColor: '#1fa5ee',
  75. menuColor: '#b81213',
  76. tutorinsaColor: '#f93943',
  77. },
  78. };
  79. }
  80. /**
  81. * Get this class instance or create one if none is found
  82. * @returns {ThemeManager}
  83. */
  84. static getInstance(): ThemeManager {
  85. return ThemeManager.instance === null ?
  86. ThemeManager.instance = new ThemeManager() :
  87. ThemeManager.instance;
  88. }
  89. /**
  90. * @returns {boolean} Night mode state
  91. */
  92. static getNightMode(): boolean {
  93. return AsyncStorageManager.getInstance().preferences.nightMode.current === '1';
  94. }
  95. /**
  96. * Get the current theme based on night mode
  97. * @returns {Object}
  98. */
  99. static getCurrentTheme(): Object {
  100. if (ThemeManager.getNightMode())
  101. return ThemeManager.getDarkTheme();
  102. else
  103. return ThemeManager.getWhiteTheme();
  104. }
  105. /**
  106. * Get the variables contained in the current theme
  107. * @returns {Object}
  108. */
  109. static getCurrentThemeVariables(): Object {
  110. return ThemeManager.getCurrentTheme().colors;
  111. }
  112. /**
  113. * Set the function to be called when the theme is changed (allows for general reload of the app)
  114. * @param callback Function to call after theme change
  115. */
  116. setUpdateThemeCallback(callback: ?Function) {
  117. this.updateThemeCallback = callback;
  118. }
  119. /**
  120. * Set night mode and save it to preferences
  121. *
  122. * @param isNightMode Whether to enable night mode
  123. */
  124. setNightMode(isNightMode: boolean) {
  125. let nightModeKey = AsyncStorageManager.getInstance().preferences.nightMode.key;
  126. AsyncStorageManager.getInstance().savePref(nightModeKey, isNightMode ? '1' : '0');
  127. if (this.updateThemeCallback !== null)
  128. this.updateThemeCallback();
  129. }
  130. };