From 87edec02d15dd8421a6ea9963f9e9268e4e09f88 Mon Sep 17 00:00:00 2001 From: Remi REGNAULT Date: Fri, 24 Nov 2023 11:40:38 +0100 Subject: [PATCH] feat : header bar is now following theme --- LeftOvers/App.tsx | 4 +- LeftOvers/navigation/BottomBar.tsx | 2 +- LeftOvers/navigation/CookingStackScreen.tsx | 33 +++++++++------- LeftOvers/navigation/HomeStackScreen.tsx | 19 ++++----- LeftOvers/navigation/ProfileStackScreen.tsx | 44 ++++++++++++--------- LeftOvers/navigation/Utils.tsx | 24 ++++++----- 6 files changed, 70 insertions(+), 56 deletions(-) diff --git a/LeftOvers/App.tsx b/LeftOvers/App.tsx index a828d17..d804abb 100644 --- a/LeftOvers/App.tsx +++ b/LeftOvers/App.tsx @@ -16,8 +16,8 @@ export default function App() { return ( - }> - + }> + diff --git a/LeftOvers/navigation/BottomBar.tsx b/LeftOvers/navigation/BottomBar.tsx index 69d4496..0dda8b9 100644 --- a/LeftOvers/navigation/BottomBar.tsx +++ b/LeftOvers/navigation/BottomBar.tsx @@ -36,7 +36,7 @@ export default function BottomBar({ state, descriptors, navigation }) { right: 0, left: 0, height: 70, - backgroundColor: theme === 'dark' ? "#3F3C42": "transparent" + backgroundColor: theme === 'dark' ? "#3F3C42" : "transparent" }, BottomBarBlurContainer: { flexDirection: 'row', diff --git a/LeftOvers/navigation/CookingStackScreen.tsx b/LeftOvers/navigation/CookingStackScreen.tsx index e974f41..b94c8d8 100644 --- a/LeftOvers/navigation/CookingStackScreen.tsx +++ b/LeftOvers/navigation/CookingStackScreen.tsx @@ -1,27 +1,30 @@ -import React from 'react' +import React, { useContext } from 'react' import { StyleSheet } from 'react-native' import { createNativeStackNavigator } from '@react-navigation/native-stack'; import IngredientSelection from '../screens/IngredientSelection'; import { HeaderTitle } from './Utils'; +import ThemeContext from '../theme/ThemeContext'; const CookingStack = createNativeStackNavigator() export default function CookingStackScreen() { - return ( - - ( - - ) - }} - /> - - ) + const {theme, toggleTheme} = useContext(ThemeContext); + + return ( + + ( + + ) + }} + /> + + ) } const styles = StyleSheet.create({ diff --git a/LeftOvers/navigation/HomeStackScreen.tsx b/LeftOvers/navigation/HomeStackScreen.tsx index 5c55f2c..631a7c1 100644 --- a/LeftOvers/navigation/HomeStackScreen.tsx +++ b/LeftOvers/navigation/HomeStackScreen.tsx @@ -1,13 +1,15 @@ -import React from 'react'; +import React, { useContext } from 'react'; import { Image, Text, StyleSheet } from 'react-native'; import { createNativeStackNavigator } from '@react-navigation/native-stack'; import HomePage from '../screens/HomePage'; import Profiles from '../screens/Profiles'; -import { HeaderTitle } from './Utils'; -import appLogo from '../assets/images/logo.png'; import CreateProfile from '../screens/CreateProfile'; import ModifyProfile from '../screens/ModifyProfile'; +import ThemeContext from '../theme/ThemeContext'; +import { HeaderTitle } from './Utils'; + +import appLogo from '../assets/images/logo.png'; const HomeStack = createNativeStackNavigator() @@ -20,13 +22,15 @@ function AppIcon() { } export default function HomeStackScreen() { + const {theme, toggleTheme} = useContext(ThemeContext) + return ( ( @@ -46,7 +50,7 @@ export default function HomeStackScreen() { name='Profiles' component={Profiles} options={{ - headerStyle: styles.headerBarContainer, + headerStyle: {backgroundColor: theme === 'light' ? '#F2F0E4' : '#3F3C42'}, headerTitle: () => ( ) @@ -56,7 +60,7 @@ export default function HomeStackScreen() { name='ProfileModification' component={ModifyProfile} options={{ - headerStyle: styles.headerBarContainer, + headerStyle: {backgroundColor: theme === 'light' ? '#F2F0E4' : '#3F3C42'}, headerTitle: () => ( ) @@ -67,9 +71,6 @@ export default function HomeStackScreen() { } const styles = StyleSheet.create({ - headerBarContainer: { - backgroundColor: '#F2F0E4', - }, headerAppIcon: { width: 45, height: 45, diff --git a/LeftOvers/navigation/ProfileStackScreen.tsx b/LeftOvers/navigation/ProfileStackScreen.tsx index 1a18c12..ea88a7f 100644 --- a/LeftOvers/navigation/ProfileStackScreen.tsx +++ b/LeftOvers/navigation/ProfileStackScreen.tsx @@ -1,10 +1,11 @@ -import React from 'react' +import React, { useContext } from 'react' import { StyleSheet, View, Image, Pressable } from 'react-native' import { createNativeStackNavigator } from '@react-navigation/native-stack'; import Profiles from '../screens/Profiles'; import CreateProfile from '../screens/CreateProfile'; import ModifyProfile from '../screens/ModifyProfile'; +import ThemeContext from '../theme/ThemeContext'; import { HeaderTitle } from './Utils'; @@ -14,6 +15,25 @@ import AddIcon from '../assets/images/plus.png' const ProfilesStack = createNativeStackNavigator() export default function ProfilesStackScreen({ navigation }) { + const {theme, toggleTheme} = useContext(ThemeContext); + + const styles = StyleSheet.create({ + headerBarContainer: { + backgroundColor: theme === 'light' ? '#F2F0E4' : '#3F3C42', + }, + headerBarRightContainer: { + display: 'flex', + flexDirection: 'row', + alignContent: 'space-between', + marginHorizontal: 10, + }, + headerBarIcon: { + width: 30, + height: 30, + marginHorizontal: 10 + } + }) + const _handleSearch = () => console.log('Searching'); const _handleHeaderAdd = () => navigation.navigate('ProfileCreation'); @@ -32,12 +52,14 @@ export default function ProfilesStackScreen({ navigation }) { + style={styles.headerBarIcon} + tintColor={theme === 'light' ? '#3F3C42' : '#F2F0E4'}/> + style={styles.headerBarIcon} + tintColor={theme === 'light' ? '#3F3C42' : '#F2F0E4'}/> ) @@ -67,19 +89,3 @@ export default function ProfilesStackScreen({ navigation }) { ) } -const styles = StyleSheet.create({ - headerBarContainer: { - backgroundColor: '#F2F0E4', - }, - headerBarRightContainer: { - display: 'flex', - flexDirection: 'row', - alignContent: 'space-between', - marginHorizontal: 10, - }, - headerBarIcon: { - width: 30, - height: 30, - marginHorizontal: 10 - } -}) \ No newline at end of file diff --git a/LeftOvers/navigation/Utils.tsx b/LeftOvers/navigation/Utils.tsx index f0811dc..ddcf8d3 100644 --- a/LeftOvers/navigation/Utils.tsx +++ b/LeftOvers/navigation/Utils.tsx @@ -1,19 +1,23 @@ -import React from 'react'; +import React, { useContext } from 'react'; import { Text, StyleSheet } from 'react-native'; +import ThemeContext from '../theme/ThemeContext'; + export function HeaderTitle(props) { + const {theme, toggleTheme} = useContext(ThemeContext); + + const styles = StyleSheet.create({ + headerTitle: { + fontSize: 20, + fontWeight: "bold", + color: theme === 'light' ? '#3F3C42' : '#F2F0E4', + } + }) + return ( {props.title} ) -} - -const styles = StyleSheet.create({ - headerTitle: { - fontSize: 20, - fontWeight: "bold", - color: '#3F3C42', - } -}) \ No newline at end of file +} \ No newline at end of file