12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758 |
- import {AsyncStorage} from 'react-native'
- import platform from '../native-base-theme/variables/platform';
- import platformDark from '../native-base-theme/variables/platformDark';
- import getTheme from '../native-base-theme/components';
-
- const nightModeKey = 'nightMode';
-
- export default class ThemeManager {
-
- static instance = null;
-
- constructor() {
- this.nightMode = false;
- this.updateThemeCallback = undefined;
- }
-
- static getInstance() {
- if (ThemeManager.instance == null) {
- ThemeManager.instance = new ThemeManager();
- }
- return this.instance;
- }
-
- setUpdateThemeCallback(callback) {
- this.updateThemeCallback = callback;
- }
-
- async getDataFromPreferences() {
- let result = await AsyncStorage.getItem(nightModeKey);
-
- if (result === '1')
- this.nightMode = true;
- console.log('nightmode: ' + this.nightMode);
- }
-
- setNightmode(isNightMode) {
- this.nightMode = isNightMode;
- AsyncStorage.setItem(nightModeKey, isNightMode ? '1' : '0');
- if (this.updateThemeCallback !== undefined)
- this.updateThemeCallback();
- }
-
- getNightMode() {
- return this.nightMode;
- }
-
- getCurrentTheme() {
- if (this.nightMode)
- return getTheme(platformDark);
- else
- return getTheme(platform);
- }
-
- getCurrentThemeVariables() {
- return this.getCurrentTheme().variables;
- }
-
- };
|