Refactor PlayerSettingsScreen to integrate ThemeContext for dynamic theming

This update modifies the PlayerSettingsScreen component to utilize the ThemeContext, allowing for dynamic theming throughout the settings interface. Styles have been adjusted to reflect the current theme colors, enhancing visual consistency and user experience. Key changes include the removal of the isDarkMode prop, updates to text colors, and background settings, ensuring a cohesive interface that adapts to different themes.
This commit is contained in:
tapframe 2025-05-04 02:46:35 +05:30
parent 29347ee028
commit d126d0ec40

View file

@ -6,14 +6,13 @@ import {
ScrollView, ScrollView,
SafeAreaView, SafeAreaView,
Platform, Platform,
useColorScheme,
TouchableOpacity, TouchableOpacity,
StatusBar, StatusBar,
} from 'react-native'; } from 'react-native';
import { useNavigation } from '@react-navigation/native'; import { useNavigation } from '@react-navigation/native';
import { useSettings, AppSettings } from '../hooks/useSettings'; import { useSettings, AppSettings } from '../hooks/useSettings';
import { colors } from '../styles/colors';
import MaterialIcons from 'react-native-vector-icons/MaterialIcons'; import MaterialIcons from 'react-native-vector-icons/MaterialIcons';
import { useTheme } from '../contexts/ThemeContext';
const ANDROID_STATUSBAR_HEIGHT = StatusBar.currentHeight || 0; const ANDROID_STATUSBAR_HEIGHT = StatusBar.currentHeight || 0;
@ -21,7 +20,6 @@ interface SettingItemProps {
title: string; title: string;
description?: string; description?: string;
icon: string; icon: string;
isDarkMode: boolean;
isSelected: boolean; isSelected: boolean;
onPress: () => void; onPress: () => void;
isLast?: boolean; isLast?: boolean;
@ -31,67 +29,69 @@ const SettingItem: React.FC<SettingItemProps> = ({
title, title,
description, description,
icon, icon,
isDarkMode,
isSelected, isSelected,
onPress, onPress,
isLast, isLast,
}) => ( }) => {
<TouchableOpacity const { currentTheme } = useTheme();
onPress={onPress}
activeOpacity={0.7} return (
style={[ <TouchableOpacity
styles.settingItem, onPress={onPress}
!isLast && styles.settingItemBorder, activeOpacity={0.7}
{ borderBottomColor: isDarkMode ? 'rgba(255,255,255,0.08)' : 'rgba(0,0,0,0.05)' }, style={[
]} styles.settingItem,
> !isLast && styles.settingItemBorder,
<View style={styles.settingContent}> { borderBottomColor: 'rgba(255,255,255,0.08)' },
<View style={[ ]}
styles.settingIconContainer, >
{ backgroundColor: isDarkMode ? 'rgba(255,255,255,0.1)' : 'rgba(0,0,0,0.05)' } <View style={styles.settingContent}>
]}> <View style={[
<MaterialIcons styles.settingIconContainer,
name={icon} { backgroundColor: 'rgba(255,255,255,0.1)' }
size={20} ]}>
color={colors.primary} <MaterialIcons
/> name={icon}
</View> size={20}
<View style={styles.settingText}> color={currentTheme.colors.primary}
<Text />
style={[ </View>
styles.settingTitle, <View style={styles.settingText}>
{ color: isDarkMode ? colors.highEmphasis : colors.textDark },
]}
>
{title}
</Text>
{description && (
<Text <Text
style={[ style={[
styles.settingDescription, styles.settingTitle,
{ color: isDarkMode ? colors.mediumEmphasis : colors.textMutedDark }, { color: currentTheme.colors.text },
]} ]}
> >
{description} {title}
</Text> </Text>
{description && (
<Text
style={[
styles.settingDescription,
{ color: currentTheme.colors.textMuted },
]}
>
{description}
</Text>
)}
</View>
{isSelected && (
<MaterialIcons
name="check"
size={24}
color={currentTheme.colors.primary}
style={styles.checkIcon}
/>
)} )}
</View> </View>
{isSelected && ( </TouchableOpacity>
<MaterialIcons );
name="check" };
size={24}
color={colors.primary}
style={styles.checkIcon}
/>
)}
</View>
</TouchableOpacity>
);
const PlayerSettingsScreen: React.FC = () => { const PlayerSettingsScreen: React.FC = () => {
const { settings, updateSetting } = useSettings(); const { settings, updateSetting } = useSettings();
const systemColorScheme = useColorScheme(); const { currentTheme } = useTheme();
const isDarkMode = systemColorScheme === 'dark' || settings.enableDarkMode;
const navigation = useNavigation(); const navigation = useNavigation();
const playerOptions = [ const playerOptions = [
@ -144,13 +144,13 @@ const PlayerSettingsScreen: React.FC = () => {
<SafeAreaView <SafeAreaView
style={[ style={[
styles.container, styles.container,
{ backgroundColor: isDarkMode ? colors.darkBackground : '#F2F2F7' }, { backgroundColor: currentTheme.colors.darkBackground },
]} ]}
> >
<StatusBar <StatusBar
translucent translucent
backgroundColor="transparent" backgroundColor="transparent"
barStyle={isDarkMode ? "light-content" : "dark-content"} barStyle="light-content"
/> />
<View style={styles.header}> <View style={styles.header}>
@ -162,13 +162,13 @@ const PlayerSettingsScreen: React.FC = () => {
<MaterialIcons <MaterialIcons
name="arrow-back" name="arrow-back"
size={24} size={24}
color={isDarkMode ? colors.highEmphasis : colors.textDark} color={currentTheme.colors.text}
/> />
</TouchableOpacity> </TouchableOpacity>
<Text <Text
style={[ style={[
styles.headerTitle, styles.headerTitle,
{ color: isDarkMode ? colors.highEmphasis : colors.textDark }, { color: currentTheme.colors.text },
]} ]}
> >
Video Player Video Player
@ -183,7 +183,7 @@ const PlayerSettingsScreen: React.FC = () => {
<Text <Text
style={[ style={[
styles.sectionTitle, styles.sectionTitle,
{ color: isDarkMode ? colors.mediumEmphasis : colors.textMutedDark }, { color: currentTheme.colors.textMuted },
]} ]}
> >
PLAYER SELECTION PLAYER SELECTION
@ -192,9 +192,7 @@ const PlayerSettingsScreen: React.FC = () => {
style={[ style={[
styles.card, styles.card,
{ {
backgroundColor: isDarkMode backgroundColor: currentTheme.colors.elevation2,
? colors.elevation2
: colors.white,
}, },
]} ]}
> >
@ -204,7 +202,6 @@ const PlayerSettingsScreen: React.FC = () => {
title={option.title} title={option.title}
description={option.description} description={option.description}
icon={option.icon} icon={option.icon}
isDarkMode={isDarkMode}
isSelected={ isSelected={
Platform.OS === 'ios' Platform.OS === 'ios'
? settings.preferredPlayer === option.id ? settings.preferredPlayer === option.id