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

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