From a1567e0efe92cb731bae8585d8bb0fb6069d4f7a Mon Sep 17 00:00:00 2001 From: ue Date: Thu, 22 Nov 2018 00:35:12 +0300 Subject: [PATCH] implemented theme changing --- .../container/applicationContainer.js | 22 +++++++------------ .../application/screen/applicationScreen.js | 10 +++++++++ src/themes/darkTheme.js | 22 ++++++++++--------- src/themes/lightTheme.js | 2 ++ 4 files changed, 32 insertions(+), 24 deletions(-) diff --git a/src/screens/application/container/applicationContainer.js b/src/screens/application/container/applicationContainer.js index dc431963c..757004482 100644 --- a/src/screens/application/container/applicationContainer.js +++ b/src/screens/application/container/applicationContainer.js @@ -1,13 +1,9 @@ import React, { Component } from 'react'; import { connect } from 'react-redux'; -import EStyleSheet from 'react-native-extended-stylesheet'; import { addLocaleData } from 'react-intl'; import en from 'react-intl/locale-data/en'; import tr from 'react-intl/locale-data/tr'; import { ApplicationScreen } from '..'; -// themes -import darkTheme from '../../../themes/darkTheme'; -import lightTheme from '../../../themes/lightTheme'; addLocaleData([...en, ...tr]); // symbol polyfills @@ -23,33 +19,31 @@ class ApplicationContainer extends Component { constructor() { super(); this.state = { - shouldRender: true, + isRenderRequire: true, }; } - componentDidMount() { - const { isDarkTheme } = this.props; - EStyleSheet.build(isDarkTheme ? darkTheme : lightTheme); - } - componentWillReceiveProps(nextProps) { const { isDarkTheme } = this.props; if (isDarkTheme !== nextProps.isDarkTheme) { - const theme = nextProps.isDarkTheme ? darkTheme : lightTheme; - EStyleSheet.build(theme); - this.setState({ shouldRender: false }, () => this.setState({ shouldRender: true })); + this.setState({ isRenderRequire: false }, () => this.setState({ isRenderRequire: true })); } } render() { const { selectedLanguage } = this.props; + const { isRenderRequire } = this.state; + const locale = (navigator.languages && navigator.languages[0]) || navigator.language || navigator.userLanguage || selectedLanguage; - return ; + if (isRenderRequire) { + return ; + } + return null; } } diff --git a/src/screens/application/screen/applicationScreen.js b/src/screens/application/screen/applicationScreen.js index 175c2d0cf..7f1f2b418 100644 --- a/src/screens/application/screen/applicationScreen.js +++ b/src/screens/application/screen/applicationScreen.js @@ -1,16 +1,26 @@ import React, { Component } from 'react'; import { IntlProvider } from 'react-intl'; +import EStyleSheet from 'react-native-extended-stylesheet'; import { ReduxNavigation } from '../../../config/reduxNavigation'; import { flattenMessages } from '../../../utils/flattenMessages'; import messages from '../../../config/locales'; +// Themes (Styles) +import darkTheme from '../../../themes/darkTheme'; +import lightTheme from '../../../themes/lightTheme'; + class ApplicationScreen extends Component { constructor(props) { super(props); this.state = {}; } + componentWillMount() { + const { isDarkTheme } = this.props; + EStyleSheet.build(isDarkTheme ? darkTheme : lightTheme); + } + render() { const { locale } = this.props; diff --git a/src/themes/darkTheme.js b/src/themes/darkTheme.js index 22d48d855..57d8ae62d 100644 --- a/src/themes/darkTheme.js +++ b/src/themes/darkTheme.js @@ -2,16 +2,18 @@ import { Dimensions } from 'react-native'; export default { // Primary Colors - $white: 'black', - $black: 'black', - $primaryBlue: 'red', - $primaryDarkBlue: 'black', - $primaryLightBlue: 'black', - $primaryGray: 'red', - $primaryDarkGray: 'red', - $primaryLightGray: 'red', - $primaryRed: 'red', - $primaryBlack: 'red', + $theme: 'darkTheme', + $mainBackgroundColor: '#1e2835', + $white: '#1e2835', + $black: '#000000', + $primaryBlue: '#357ce6', + $primaryDarkBlue: '#1a509a', + $primaryLightBlue: '#eaf2fc', + $primaryGray: '#ffff', + $primaryDarkGray: '#ffff', + $primaryLightGray: '#f6f6f6', + $primaryRed: '#e63535', + $primaryBlack: '#3c4449', // General Colors $borderColor: '#c5c5c5', diff --git a/src/themes/lightTheme.js b/src/themes/lightTheme.js index 455a570f0..01d8d3132 100644 --- a/src/themes/lightTheme.js +++ b/src/themes/lightTheme.js @@ -2,6 +2,8 @@ import { Dimensions } from 'react-native'; export default { // Primary Colors + $theme: 'lightTheme', + $mainBackgroundColor: '#FFFFFF', $white: '#FFFFFF', $black: '#000000', $primaryBlue: '#357ce6',