Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Issue #223 #239

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 19 additions & 1 deletion lib/components/ThemeProvider.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,18 @@ export function ThemeProvider({ children }) {
const [isDarkmode, setIsDarkmode] = useState(false);
colors.darkColors.homeColor = appThemeColor;
colors.lightColors.homeColor = appThemeColor;

// function to update the theme color dynamically
const updateThemeColor = (newColor) => {
colors.darkColors.homeColor = newColor;
colors.lightColors.homeColor = newColor;
AsyncStorage.save('appThemeColor', newColor)
};

console.log(colors.darkColors.homeColor, appThemeColor)

const toggleDarkmode = () => {
setIsDarkmode((prevMode) => !prevMode);

// Save the theme preference in AsyncStorage
AsyncStorage.save('themePreference', !isDarkmode ? 'dark' : 'light');
};
Expand All @@ -33,6 +41,16 @@ export function ThemeProvider({ children }) {
.catch((error) => {
console.error('Error loading theme preference:', error);
});

AsyncStorage.get('appThemeColor')
.then((storedColor) => {
if (storedColor) {
updateThemeColor(storedColor);
}
})
.catch((error) => {
console.error('Error loading custom theme color: ', error);
});
}, []);

const theme = isDarkmode ? colors.darkColors : colors.lightColors;
Expand Down
79 changes: 61 additions & 18 deletions lib/screens/AppThemeSelectorScreen.tsx
Original file line number Diff line number Diff line change
@@ -1,18 +1,26 @@
import React, { useState } from 'react';
import { View, Text, StyleSheet, TouchableOpacity } from 'react-native';
import { SafeAreaView } from 'react-native-safe-area-context';
import { View, Text, StyleSheet, TouchableOpacity, Modal } from 'react-native';
import { useTheme } from '../components/ThemeProvider';
import { appTheme } from '../components/colors';
import { useDispatch, UseDispatch } from 'react-redux';
import { themeReducer } from '../../redux/slice/ThemeSlice';

import ColorWheel from 'react-native-wheel-color-picker';

function AppThemeSelectorScreen() {

const dispatch = useDispatch();
const { theme, isDarkmode } = useTheme();
const { theme, updateThemeColor } = useTheme();
const [colorPickerVisible, setColorPickerVisible] = useState(false);
const [selectedColor, setSelectedColor] = useState(theme.homeColor);
// const [selectedColor, setSelectedColor] = useState('#ff0000'); // Default color
// const [sliderValue, setSliderValue] = useState(0.5); // Slider value state

const handleColorSelected = (color) => {
setSelectedColor(color);
updateThemeColor(color);
setColorPickerVisible(false);
}
// const handleColorChange = (color) => {
// console.log('Selected Color:', color);
// setSelectedColor(color);
Expand All @@ -24,16 +32,23 @@ function AppThemeSelectorScreen() {
<Text style={[styles.currentThemeTxt, { color: 'green' }]}>Current Theme</Text>

{/** Theme Box */}
<View style={[styles.themeContainer, {
backgroundColor: theme.homeColor, height: 40,
width: 80,
borderRadius: 30,
}]}></View>
<View
style={[
styles.themeContainer,
{
backgroundColor: theme.homeColor,
height: 40,
width: 80,
borderRadius: 30,
},
]}
/>

<View style={styles.ThemeSection}>
{
appTheme.map((theme, key) => (
<TouchableOpacity key={key}
<TouchableOpacity
key={key}
onPress={() => {
dispatch(themeReducer(theme.themeColor))
}}
Expand All @@ -42,17 +57,39 @@ function AppThemeSelectorScreen() {
</TouchableOpacity>
))
}
<TouchableOpacity>
<TouchableOpacity onPress={() => setColorPickerVisible(true)}>
<View style={[styles.themeContainer, { backgroundColor: '#a3a3a3', justifyContent: 'center', alignItems: 'center' }]}>
<Text style={{ fontSize: 35, }}>+</Text>
</View>
</TouchableOpacity>
</View>



<Modal
visible={colorPickerVisible}
animationType="slide"
transparent={false}
onRequestClose={() => setColorPickerVisible(false)}
>
<View style={styles.colorPickerContainer}>
<Text style={styles.modalTitle}>Pick a Color</Text>
<ColorWheel
initialColor={selectedColor}
onColorChangeComplete={(color) => setSelectedColor(color)}
style={styles.colorWheel}
thumbStyle={{ borderWidth: 2, borderColor: '#fff'}}
/>
<TouchableOpacity onPress={handleConfirmColor} style={styles.confirmButton}>
<Text style={styles.buttonText}>Confirm</Text>
</TouchableOpacity>
<TouchableOpacity onPress={() => setColorPickerVisible(false)}
style={styles.closeButton}
>
<Text style={styles.closeButtonText}>Cancel</Text>
</TouchableOpacity>
</View>
</Modal>
</View>
)
);
}

export default AppThemeSelectorScreen;
Expand Down Expand Up @@ -89,12 +126,18 @@ const styles = StyleSheet.create({
alignItems: 'center',
},
colorPicker: {
width: '100%',
height: 200,
width: '90%',
height: 30,
},
closeButton: {
width: '90%',
backgroundColor: '#ccc',
marginTop: 20,
borderRadius: 5,
},
slider: {
width: '100%',
height: 40,
closeButtonText: {
fontSize: 15,
color: '#333',
},
selectedColorPreview: {
height: 50,
Expand Down
Loading