From da8075e30317a68096ea48baedd65ebf374421aa Mon Sep 17 00:00:00 2001 From: Remi REGNAULT Date: Mon, 27 Nov 2023 15:49:37 +0100 Subject: [PATCH] feat add colors context see next push if its working --- LeftOvers/App.tsx | 17 ++- LeftOvers/components/ProfileElement.tsx | 2 +- LeftOvers/components/ValidateButton.tsx | 15 +- LeftOvers/navigation/BottomBar.tsx | 8 +- LeftOvers/screens/HomePage.tsx | 177 +++++++++++------------- LeftOvers/theme/ColorContext.tsx | 42 ++++++ LeftOvers/theme/ThemeContext.tsx | 2 +- LeftOvers/theme/colors.ts | 57 ++++++++ 8 files changed, 207 insertions(+), 113 deletions(-) create mode 100644 LeftOvers/theme/ColorContext.tsx create mode 100644 LeftOvers/theme/colors.ts diff --git a/LeftOvers/App.tsx b/LeftOvers/App.tsx index d804abb..9ef8c57 100644 --- a/LeftOvers/App.tsx +++ b/LeftOvers/App.tsx @@ -7,6 +7,7 @@ import ProfilesStackScreen from './navigation/ProfileStackScreen'; import CookingStackScreen from './navigation/CookingStackScreen'; import BottomBar from './navigation/BottomBar'; import { ThemeProvider } from './theme/ThemeContext'; +import { ColorProvider } from './theme/ColorContext'; const Tab = createBottomTabNavigator(); @@ -15,13 +16,15 @@ export default function App() { return ( - - }> - - - - - + + + }> + + + + + + ); } \ No newline at end of file diff --git a/LeftOvers/components/ProfileElement.tsx b/LeftOvers/components/ProfileElement.tsx index f7c392d..fb8bd35 100644 --- a/LeftOvers/components/ProfileElement.tsx +++ b/LeftOvers/components/ProfileElement.tsx @@ -1,4 +1,4 @@ -import {React, useState} from 'react'; +import React, { useState } from 'react'; import {StyleSheet,Pressable, Text, View, Image} from 'react-native'; type Profile = { diff --git a/LeftOvers/components/ValidateButton.tsx b/LeftOvers/components/ValidateButton.tsx index fa517a6..9a8d544 100644 --- a/LeftOvers/components/ValidateButton.tsx +++ b/LeftOvers/components/ValidateButton.tsx @@ -72,15 +72,14 @@ export default function ValidateButton(props: ValidateButtonProps) { padding: "2%", paddingRight: "3%",}}> - + height: "90%", + width: "9%", + marginLeft: "2%", + marginRight: "3%", + resizeMode: "contain",}} + tintColor={props.colour}/> - + @@ -102,96 +182,3 @@ export default function HomePage({ navigation, props }) { ); } -const styles = StyleSheet.create({ - container: { - width: "100%", - flex: 1, - backgroundColor: '#3F3C42', - alignItems: 'center', - justifyContent: 'center', - }, - linearGradient: { - width: "100%", - flex: 1, - padding: "2%", - paddingTop: 0, - }, - separator: { - marginTop: "6%" - }, - - filterBar: { - flexDirection: "row", - width: "85%", - paddingTop: "3%", - paddingBottom: "2%", - alignItems: "flex-end", - justifyContent: "center", - }, - filters: { - fontSize: 20, - color: '#ACA279', - flex: 1, - }, - nbSelected: { - fontSize: 11, - color: "#3F3C42", - textAlign: "right", - }, - - profilesSelection: { - alignItems: 'center', - justifyContent: 'center', - borderRadius: 20, - backgroundColor: '#F2F0E4', - marginHorizontal: "3%", - paddingBottom: "3%", - }, - - welcome: { - alignItems: 'center', - justifyContent: 'center', - borderRadius: 20, - backgroundColor: '#F2F0E4', - paddingVertical: "3%", - paddingHorizontal: "7%", - marginHorizontal: "3%", - }, - text: { - fontSize: 20, - color: '#ACA279', - }, - name: { - fontSize: 20, - fontWeight: "bold", - color: '#59BDCD', - }, - - ingredientSelection: { - width: "90%", - alignItems: 'center', - justifyContent: 'center', - borderRadius: 20, - backgroundColor: '#E3DEC9', - borderWidth: 2, - borderColor: "#ACA279", - padding: "2%" - }, - - appName: { - fontSize: 20, - fontWeight: "bold", - color: '#3F3C42', - textAlign: "center", - flex: 0.8, - }, - topBar: { - flexDirection: 'row', - width: "100%", - height: "11%", - alignItems: 'center', - justifyContent: 'center', - backgroundColor: '#F2F0E4', - paddingTop: "8%", - }, -}); \ No newline at end of file diff --git a/LeftOvers/theme/ColorContext.tsx b/LeftOvers/theme/ColorContext.tsx new file mode 100644 index 0000000..5cad2ce --- /dev/null +++ b/LeftOvers/theme/ColorContext.tsx @@ -0,0 +1,42 @@ +import React, {createContext, useState, useEffect} from 'react'; +import AsyncStorage from '@react-native-async-storage/async-storage'; + +import { DarkTheme, LightTheme, Theme } from './colors'; + +interface ColorContextType { + colors: Theme, + toggleColor: (Theme) => void +}; + +const ColorContext = createContext(null); + +export const ColorProvider = ({ children }) => { + const [colors, setColors] = useState(LightTheme); + + useEffect(() => { + const getColors = async () => { + try { + const savedColors = await AsyncStorage.getItem('colors'); + if (savedColors) { + setColors(JSON.parse(savedColors)); + } + } catch (error) { + console.log('Error loading colors:', error); + } + }; + getColors(); + }, []); + + const toggleColor = (newColors: Theme) => { + setColors(newColors); + AsyncStorage.setItem('colors', JSON.stringify(newColors)) + }; + + return ( + + {children} + + ); +}; + +export default ColorContext; \ No newline at end of file diff --git a/LeftOvers/theme/ThemeContext.tsx b/LeftOvers/theme/ThemeContext.tsx index 080fec7..e8e9817 100644 --- a/LeftOvers/theme/ThemeContext.tsx +++ b/LeftOvers/theme/ThemeContext.tsx @@ -9,7 +9,7 @@ interface ThemeContextType { const ThemeContext = createContext(null); -export const ThemeProvider = ({children}) => { +export const ThemeProvider = ({ children }) => { const [theme, setTheme] = useState('light'); useEffect(() => { diff --git a/LeftOvers/theme/colors.ts b/LeftOvers/theme/colors.ts new file mode 100644 index 0000000..2ce4786 --- /dev/null +++ b/LeftOvers/theme/colors.ts @@ -0,0 +1,57 @@ +const Ecru = '#ACA279' +const Alabaster = '#F2F0E4' +const Jet = '#3F3C42' +const Moonstone = '#59BDCD' +const Cerulean = '#2680AA' +const Celeste = '#ADF3EA' +const Tan = '#E0C293' +const Pearl = '#E3DEC9' +const EerieBlack = '#222222' +const CarolinaBlue = '#8DB4D9' +const SteelBlue = '#5882A8' + +export interface Theme { + primary: string, + primaryComplement: string, + cardBackground: string, + cardTitle: string, + cardDetail: string, + cardElementBackground: string, + cardElementText: string, + cardElementBorder: string, + cardElementTitle: string + ingredientBackground: string, + ingredientContent: string, + ingredientBorder: string, +} + +export const LightTheme : Theme = { + primary: Cerulean, + primaryComplement: Moonstone, + cardBackground: Alabaster, + cardTitle: Ecru, + cardDetail: Jet, + cardElementBackground: Pearl, + cardElementText: Jet, + cardElementBorder: Ecru, + cardElementTitle: Jet, + ingredientBackground: Pearl, + ingredientBorder: EerieBlack, + ingredientContent: Jet, +} + +export const DarkTheme : Theme = { + primary: EerieBlack, + primaryComplement: Jet, + cardBackground: Jet, + cardTitle: Ecru, + cardDetail: Alabaster, + cardElementBackground: SteelBlue, + cardElementText: Jet, + cardElementTitle: Alabaster, + cardElementBorder: SteelBlue, + ingredientBackground: EerieBlack, + ingredientBorder: SteelBlue, + ingredientContent: Alabaster +} +