Skip to content

Commit

Permalink
Add light theme
Browse files Browse the repository at this point in the history
  • Loading branch information
thornbill committed Jan 7, 2021
1 parent df836d9 commit 3a5f461
Show file tree
Hide file tree
Showing 11 changed files with 98 additions and 8 deletions.
5 changes: 2 additions & 3 deletions App.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import PropTypes from 'prop-types';

import { useStores } from './hooks/useStores';
import AppNavigator from './navigation/AppNavigator';
import DarkTheme from './themes/dark';
import NativeShellLoader from './utils/NativeShellLoader';

// Import i18n configuration
Expand Down Expand Up @@ -106,9 +105,9 @@ const App = observer(({ skipLoadingScreen }) => {

return (
<SafeAreaProvider>
<ThemeProvider theme={DarkTheme.Elements}>
<ThemeProvider theme={rootStore.settingStore.theme.Elements}>
<StatusBar
style="light"
style='light'
backgroundColor={theme.colors.grey0}
hidden={rootStore.isFullscreen}
/>
Expand Down
Binary file added assets/images/logoblack.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions langs/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
"settings": {
"version": "Version: {{version}}",
"keepAwake": "Keep Screen Awake",
"lightTheme": "Use Light Theme",
"rotationLock": "Rotation Lock",
"tabLabels": "Show Tab Labels",
"expoVersion": "Expo Version: {{version}}"
Expand Down
3 changes: 1 addition & 2 deletions navigation/AppNavigator.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import ErrorScreen from '../screens/ErrorScreen';
import HomeScreen from '../screens/HomeScreen';
import SettingsScreen from '../screens/SettingsScreen';
import { getIconName } from '../utils/Icons';
import DarkTheme from '../themes/dark';

const RootStack = createStackNavigator();
const Tab = createBottomTabNavigator();
Expand Down Expand Up @@ -124,7 +123,7 @@ const AppNavigator = observer(() => {
SplashScreen.hideAsync();

return (
<NavigationContainer theme={DarkTheme.Navigation}>
<NavigationContainer theme={rootStore.settingStore.theme.Navigation}>
<RootStack.Navigator
initialRouteName={(rootStore.serverStore.servers?.length > 0) ? 'Main' : 'AddServer'}
headerMode='screen'
Expand Down
8 changes: 7 additions & 1 deletion screens/AddServerScreen.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,13 @@ import { SafeAreaView } from 'react-native-safe-area-context';
import { useHeaderHeight } from '@react-navigation/stack';
import { useTranslation } from 'react-i18next';

import { useStores } from '../hooks/useStores';
import ServerInput from '../components/ServerInput';

const AddServerScreen = () => {
const { t } = useTranslation();
const headerHeight = useHeaderHeight();
const { rootStore } = useStores();
const { theme } = useContext(ThemeContext);

return (
Expand All @@ -32,7 +34,11 @@ const AddServerScreen = () => {
<View style={styles.logoContainer}>
<Image
style={styles.logoImage}
source={require('../assets/images/logowhite.png')}
source={
rootStore.settingStore.theme.dark ?
require('../assets/images/logowhite.png') :
require('../assets/images/logoblack.png')
}
fadeDuration={0} // we need to adjust Android devices (https://facebook.github.io/react-native/docs/image#fadeduration) fadeDuration prop to `0` as it's default value is `300`
/>
</View>
Expand Down
13 changes: 12 additions & 1 deletion screens/SettingsScreen.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ const SettingsScreen = observer(() => {
const { rootStore } = useStores();
const navigation = useNavigation();
const { t } = useTranslation();
const { theme } = useContext(ThemeContext);
const { theme, replaceTheme } = useContext(ThemeContext);

useEffect(() => {
// Fetch server info
Expand Down Expand Up @@ -125,6 +125,17 @@ const SettingsScreen = observer(() => {
onValueChange: action(value => rootStore.settingStore.isTabLabelsEnabled = value)
});

// TODO: This should be able to select from a list not just a switch
settingsData.push({
key: 'theme-switch',
title: t('settings.lightTheme'),
value: rootStore.settingStore.themeId === 'light',
onValueChange: action(value => {
rootStore.settingStore.themeId = value ? 'light' : 'dark';
replaceTheme(rootStore.settingStore.theme.Elements);
})
});

return [
{
title: t('headings.servers'),
Expand Down
13 changes: 12 additions & 1 deletion stores/SettingStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
import { action, decorate, observable } from 'mobx';
import { action, computed, decorate, observable } from 'mobx';
import { Platform } from 'react-native';

import Themes from '../themes';

/**
* Data store for application settings
*/
Expand All @@ -30,11 +32,18 @@ export default class SettingStore {
*/
isTabLabelsEnabled = true

themeId = 'dark'

get theme() {
return Themes[this.themeId];
}

reset() {
this.activeServer = 0;
this.isRotationLockEnabled = Platform.OS === 'ios' && !Platform.isPad;
this.isScreenLockEnabled = Platform.OS === 'ios' ? (parseInt(Platform.Version, 10) < 14) : true;
this.isTabLabelsEnabled = true;
this.themeId = 'dark';
}
}

Expand All @@ -43,5 +52,7 @@ decorate(SettingStore, {
isRotationLockEnabled: observable,
isScreenLockEnabled: observable,
isTabLabelsEnabled: observable,
themeId: observable,
theme: computed,
reset: action
});
12 changes: 12 additions & 0 deletions themes/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/**
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
import dark from './dark';
import light from './light';

export default {
dark,
light
};
19 changes: 19 additions & 0 deletions themes/light/elements.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/**
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
import BaseTheme from '../base/elements';
import Colors from '../../constants/Colors';

export default {
...BaseTheme,
colors: {
...BaseTheme.colors,
background: '#F2F2F2',
primary: Colors.blue,
secondary: Colors.purple,
grey0: '#303030',
grey1: '#999'
}
};
13 changes: 13 additions & 0 deletions themes/light/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/**
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
import Elements from './elements';
import Navigation from './navigation';

export default {
dark: false,
Elements,
Navigation
};
19 changes: 19 additions & 0 deletions themes/light/navigation.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/**
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
import { DefaultTheme } from '@react-navigation/native';
import Colors from '../../constants/Colors';

export default {
...DefaultTheme,
colors: {
...DefaultTheme.colors,
primary: Colors.blue,
background: '#F2F2F2',
card: '#303030',
text: Colors.white,
border: '#272729'
}
};

0 comments on commit 3a5f461

Please sign in to comment.