From 1ba07401e05b6f1128f35cd4ccbea718c471535c Mon Sep 17 00:00:00 2001 From: Nouman Tahir Date: Sat, 16 Apr 2022 02:27:14 +0500 Subject: [PATCH] properly setting redux isDarkTheme and setTheme separatly to differ between active and saved state --- .../settings/container/settingsContainer.js | 25 ++++++++++++++----- 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/src/screens/settings/container/settingsContainer.js b/src/screens/settings/container/settingsContainer.js index bb6f73976..b8d5c7971 100644 --- a/src/screens/settings/container/settingsContainer.js +++ b/src/screens/settings/container/settingsContainer.js @@ -1,5 +1,5 @@ import React, { Component } from 'react'; -import { Platform, Alert } from 'react-native'; +import { Platform, Alert, Appearance } from 'react-native'; import { connect } from 'react-redux'; import { Client } from '@hiveio/dhive'; import VersionNumber from 'react-native-version-number'; @@ -7,6 +7,8 @@ import Config from 'react-native-config'; import { injectIntl } from 'react-intl'; import messaging from '@react-native-firebase/messaging'; import { languageRestart } from '../../../utils/I18nUtils'; +import THEME_OPTIONS from '../../../constants/options/theme'; + // Realm import { getExistUser, @@ -22,6 +24,7 @@ import { setAuthStatus, setExistUser, removeAllUserData, + getTheme, } from '../../../realm/realm'; // Services and Actions @@ -119,6 +122,21 @@ class SettingsContainer extends Component { setNsfw2DB(action); break; + case 'theme': + let setting = THEME_OPTIONS[action].value; + const systemTheme = Appearance.getColorScheme(); + + dispatch(isDarkTheme(setting === null + ? systemTheme === 'dark' + : setting + )); + + setTheme(setting); + this.setState({ + themeSetting:setting + }) + break; + default: break; } @@ -208,11 +226,6 @@ class SettingsContainer extends Component { this._handleNotification(action, actionType); break; - case 'theme': - dispatch(isDarkTheme(action)); - setTheme(action); - break; - case 'default_footer': dispatch(isDefaultFooter(action)); // setDefaultFooter(action);