From 953556c65a5721f9a374eed1e42872d3fb1fed4a Mon Sep 17 00:00:00 2001 From: tapframe Date: Sun, 4 May 2025 02:52:47 +0530 Subject: [PATCH] Refactor CalendarSection, NotificationSettingsScreen, and SettingsScreen for improved theme integration and code consistency This update enhances the CalendarSection, NotificationSettingsScreen, and SettingsScreen components by removing unnecessary props related to dark mode and integrating the ThemeContext for dynamic theming. Styles have been adjusted to reflect the current theme colors, improving visual consistency across the application. Key changes include updates to button styles, text colors, and background settings, ensuring a cohesive interface that adapts to different themes. Additionally, code formatting has been improved for better readability. --- src/components/calendar/CalendarSection.tsx | 48 +++---- src/screens/NotificationSettingsScreen.tsx | 2 +- src/screens/SettingsScreen.tsx | 151 +++++--------------- 3 files changed, 62 insertions(+), 139 deletions(-) diff --git a/src/components/calendar/CalendarSection.tsx b/src/components/calendar/CalendarSection.tsx index 7050b903..2d443e13 100644 --- a/src/components/calendar/CalendarSection.tsx +++ b/src/components/calendar/CalendarSection.tsx @@ -47,28 +47,28 @@ const DayItem = ({ }: DayItemProps) => { const { currentTheme } = useTheme(); return ( - onPress(date)} - > - onPress(date)} + > + - {date.getDate()} - - {hasEvents && ( + today && styles.todayText, + isSelected && styles.selectedDayText + ]}> + {date.getDate()} + + {hasEvents && ( - )} - - ); + )} + +); }; export const CalendarSection: React.FC = ({ @@ -117,13 +117,13 @@ export const CalendarSection: React.FC = ({ const start = startOfMonth(currentDate); const end = endOfMonth(currentDate); const days = eachDayOfInterval({ start, end }); - + // Get the day of the week for the first day (0-6) const firstDayOfWeek = start.getDay(); // Add empty days at the start const emptyDays = Array(firstDayOfWeek).fill(null); - + // Calculate remaining days to fill the last row const totalDays = emptyDays.length + days.length; const remainingDays = 7 - (totalDays % 7); @@ -135,7 +135,7 @@ export const CalendarSection: React.FC = ({ for (let i = 0; i < allDays.length; i += 7) { weeks.push(allDays.slice(i, i + 7)); } - + return weeks.map((week, weekIndex) => ( {week.map((day, dayIndex) => { @@ -201,7 +201,7 @@ export const CalendarSection: React.FC = ({ - + {weekDays.map((day, index) => ( = ({ ))} - + {renderDays()} diff --git a/src/screens/NotificationSettingsScreen.tsx b/src/screens/NotificationSettingsScreen.tsx index 360dfb4b..dda3dcaf 100644 --- a/src/screens/NotificationSettingsScreen.tsx +++ b/src/screens/NotificationSettingsScreen.tsx @@ -314,7 +314,7 @@ const NotificationSettingsScreen = () => { = ({ children, isDarkMode, title }) => { +const SettingsCard: React.FC = ({ children, title }) => { const { currentTheme } = useTheme(); return ( @@ -47,14 +45,14 @@ const SettingsCard: React.FC = ({ children, isDarkMode, title {title && ( {title.toUpperCase()} )} {children} @@ -69,7 +67,6 @@ interface SettingItemProps { renderControl: () => React.ReactNode; isLast?: boolean; onPress?: () => void; - isDarkMode: boolean; badge?: string | number; } @@ -80,7 +77,6 @@ const SettingItem: React.FC = ({ renderControl, isLast = false, onPress, - isDarkMode, badge }) => { const { currentTheme } = useTheme(); @@ -92,22 +88,22 @@ const SettingItem: React.FC = ({ style={[ styles.settingItem, !isLast && styles.settingItemBorder, - { borderBottomColor: isDarkMode ? 'rgba(255,255,255,0.08)' : 'rgba(0,0,0,0.05)' } + { borderBottomColor: 'rgba(255,255,255,0.08)' } ]} > - + {title} {description && ( - + {description} )} @@ -127,8 +123,6 @@ const SettingItem: React.FC = ({ const SettingsScreen: React.FC = () => { const { settings, updateSetting } = useSettings(); - const systemColorScheme = useColorScheme(); - const isDarkMode = systemColorScheme === 'dark' || settings.enableDarkMode; const navigation = useNavigation>(); const { lastUpdate } = useCatalogContext(); const { isAuthenticated, userProfile } = useTraktContext(); @@ -141,23 +135,6 @@ const SettingsScreen: React.FC = () => { const [mdblistKeySet, setMdblistKeySet] = useState(false); const [discoverDataSource, setDiscoverDataSource] = useState(DataSource.STREMIO_ADDONS); - // Force consistent status bar settings - useEffect(() => { - const applyStatusBarConfig = () => { - StatusBar.setBarStyle('light-content'); - if (Platform.OS === 'android') { - StatusBar.setTranslucent(true); - StatusBar.setBackgroundColor('transparent'); - } - }; - - applyStatusBarConfig(); - - // Re-apply on focus - const unsubscribe = navigation.addListener('focus', applyStatusBarConfig); - return unsubscribe; - }, [navigation]); - const loadData = useCallback(async () => { try { // Load addon count and get their catalogs @@ -236,9 +213,9 @@ const SettingsScreen: React.FC = () => { ); @@ -246,7 +223,7 @@ const SettingsScreen: React.FC = () => { ); @@ -264,52 +241,51 @@ const SettingsScreen: React.FC = () => { return ( - {/* Fixed position header background to prevent shifts */} - - + - {/* Header Section with proper top spacing */} - + Settings - - Reset - - {/* Content Container */} - + navigation.navigate('TraktSettings')} + isLast={false} + /> + + + + navigation.navigate('ThemeSettings')} isLast={true} /> - + navigation.navigate('Calendar')} - isDarkMode={isDarkMode} /> { icon="notifications" renderControl={ChevronRight} onPress={() => navigation.navigate('NotificationSettings')} - isDarkMode={isDarkMode} isLast={true} /> - + navigation.navigate('Addons')} badge={addonCount} @@ -336,7 +310,6 @@ const SettingsScreen: React.FC = () => { title="Catalogs" description="Configure content sources" icon="view-list" - isDarkMode={isDarkMode} renderControl={ChevronRight} onPress={() => navigation.navigate('CatalogSettings')} badge={catalogCount} @@ -345,23 +318,20 @@ const SettingsScreen: React.FC = () => { title="Home Screen" description="Customize layout and content" icon="home" - isDarkMode={isDarkMode} renderControl={ChevronRight} onPress={() => navigation.navigate('HomeScreenSettings')} /> navigation.navigate('MDBListSettings')} /> navigation.navigate('LogoSourceSettings')} /> @@ -369,14 +339,13 @@ const SettingsScreen: React.FC = () => { title="TMDB" description="API & Metadata Settings" icon="movie-filter" - isDarkMode={isDarkMode} renderControl={ChevronRight} onPress={() => navigation.navigate('TMDBSettings')} isLast={true} /> - + { : (settings.useExternalPlayer ? 'External Player' : 'Built-in Player') } icon="play-arrow" - isDarkMode={isDarkMode} renderControl={ChevronRight} onPress={() => navigation.navigate('PlayerSettings')} isLast={true} /> - + ( { /> - - ( - updateSetting('enableDarkMode', value)} - /> - )} - isDarkMode={isDarkMode} - /> - navigation.navigate('ThemeSettings')} - isDarkMode={isDarkMode} - isLast - /> - - - + Version 1.0.0 @@ -484,18 +427,6 @@ const styles = StyleSheet.create({ container: { flex: 1, }, - headerBackground: { - position: 'absolute', - top: 0, - left: 0, - right: 0, - zIndex: 1, - }, - contentContainer: { - flex: 1, - zIndex: 1, - width: '100%', - }, header: { paddingHorizontal: 20, flexDirection: 'row', @@ -510,13 +441,10 @@ const styles = StyleSheet.create({ fontWeight: '800', letterSpacing: 0.3, }, - resetButton: { - paddingVertical: 8, - paddingHorizontal: 12, - }, - resetButtonText: { - fontSize: 16, - fontWeight: '600', + contentContainer: { + flex: 1, + zIndex: 1, + width: '100%', }, scrollView: { flex: 1, @@ -577,11 +505,6 @@ const styles = StyleSheet.create({ settingTextContainer: { flex: 1, }, - settingTitleRow: { - flexDirection: 'row', - justifyContent: 'space-between', - alignItems: 'center', - }, settingTitle: { fontSize: 16, fontWeight: '500',