Skip to content

Commit d5c15b9

Browse files
committed
feat: Implement safe access for theme properties with fallbacks in FriendsScreen, GroupDetailsScreen, HomeScreen, ModernButton, ModernCard, and useAppTheme
1 parent b3b7916 commit d5c15b9

File tree

6 files changed

+38
-26
lines changed

6 files changed

+38
-26
lines changed

frontend/screens/FriendsScreen.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ const FriendsScreen = () => {
2626
explanationContainer: {
2727
backgroundColor: '#f8fafc',
2828
margin: 8,
29-
borderRadius: theme.custom.borderRadius,
29+
borderRadius: theme?.custom?.borderRadius || 8, // Safe access with fallback
3030
borderLeftWidth: 3,
3131
borderLeftColor: '#3b82f6',
3232
shadowOffset: { width: 0, height: 1 },

frontend/screens/GroupDetailsScreen.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ const GroupDetailsScreen = ({ route, navigation }) => {
6161
},
6262
owedSection: {
6363
backgroundColor: '#fef7f7',
64-
borderRadius: theme.custom.borderRadius,
64+
borderRadius: theme?.custom?.borderRadius || 8, // Safe access with fallback
6565
padding: 16,
6666
borderLeftWidth: 3,
6767
borderLeftColor: '#ef4444',
@@ -72,7 +72,7 @@ const GroupDetailsScreen = ({ route, navigation }) => {
7272
},
7373
receiveSection: {
7474
backgroundColor: '#f0fdf4',
75-
borderRadius: theme.custom.borderRadius,
75+
borderRadius: theme?.custom?.borderRadius || 8, // Safe access with fallback
7676
padding: 16,
7777
borderLeftWidth: 3,
7878
borderLeftColor: '#22c55e',

frontend/screens/HomeScreen.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ const HomeScreen = ({ navigation }) => {
4444
backgroundColor: 'white',
4545
padding: 20,
4646
margin: 20,
47-
borderRadius: theme.custom.borderRadiusLarge || 12,
47+
borderRadius: theme?.custom?.borderRadiusLarge || 12, // Safe access with fallback
4848
shadowOffset: { width: 0, height: 2 },
4949
shadowOpacity: 0.08,
5050
shadowRadius: 8,

frontend/src/components/ModernButton.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ const ModernButton = ({ style, mode = 'contained', children, ...props }) => {
1010

1111
const getButtonStyle = () => {
1212
const baseStyle = {
13-
borderRadius: theme.custom.borderRadius,
13+
borderRadius: theme?.custom?.borderRadius || 8, // Safe access with fallback
1414
};
1515

1616
switch (mode) {

frontend/src/components/ModernCard.js

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,23 +10,29 @@ const ModernCard = ({ children, style, variant = 'default', ...props }) => {
1010

1111
const getCardStyle = () => {
1212
const baseStyle = {
13-
backgroundColor: theme.colors.surface,
14-
borderRadius: theme.custom.borderRadius,
15-
...theme.custom.shadow.small,
13+
backgroundColor: theme?.colors?.surface || '#ffffff',
14+
borderRadius: theme?.custom?.borderRadius || 8,
15+
shadowOffset: { width: 0, height: 1 },
16+
shadowOpacity: 0.05,
17+
shadowRadius: 2,
18+
elevation: 1,
1619
};
1720

1821
switch (variant) {
1922
case 'elevated':
2023
return {
2124
...baseStyle,
22-
...theme.custom.shadow.medium,
25+
shadowOffset: { width: 0, height: 2 },
26+
shadowOpacity: 0.08,
27+
shadowRadius: 8,
28+
elevation: 3,
2329
};
2430
case 'outlined':
2531
return {
2632
...baseStyle,
2733
borderWidth: 1,
28-
borderColor: theme.colors.outline,
29-
shadowOpacity: 0, // Remove shadow for outlined variant
34+
borderColor: theme?.colors?.outline || '#e1e1e6',
35+
shadowOpacity: 0,
3036
elevation: 0,
3137
};
3238
default:

frontend/src/theme/useAppTheme.js

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -10,44 +10,50 @@ export const useAppTheme = () => {
1010
return {
1111
theme,
1212
// Utility functions for common styling patterns
13-
borderRadius: theme.custom.borderRadius,
14-
spacing: theme.custom.spacing,
13+
borderRadius: theme?.custom?.borderRadius || 8,
14+
spacing: theme?.custom?.spacing || { xs: 4, sm: 8, md: 16, lg: 24, xl: 32 },
1515

1616
// Common container styles with modern design
1717
getCardStyle: (customStyles = {}) => ({
18-
borderRadius: theme.custom.borderRadius,
19-
backgroundColor: theme.colors.surface,
20-
...theme.custom.shadow.small,
18+
borderRadius: theme?.custom?.borderRadius || 8,
19+
backgroundColor: theme?.colors?.surface || '#ffffff',
20+
shadowOffset: { width: 0, height: 1 },
21+
shadowOpacity: 0.05,
22+
shadowRadius: 2,
23+
elevation: 1,
2124
...customStyles,
2225
}),
2326

2427
getModalStyle: (customStyles = {}) => ({
25-
backgroundColor: theme.colors.surface,
26-
padding: theme.custom.spacing.lg,
27-
margin: theme.custom.spacing.lg,
28-
borderRadius: theme.custom.borderRadiusLarge, // Use larger radius only for modals
29-
...theme.custom.shadow.medium,
28+
backgroundColor: theme?.colors?.surface || '#ffffff',
29+
padding: theme?.custom?.spacing?.lg || 24,
30+
margin: theme?.custom?.spacing?.lg || 24,
31+
borderRadius: theme?.custom?.borderRadiusLarge || 12, // Use larger radius only for modals
32+
shadowOffset: { width: 0, height: 2 },
33+
shadowOpacity: 0.08,
34+
shadowRadius: 8,
35+
elevation: 3,
3036
...customStyles,
3137
}),
3238

3339
getSectionStyle: (backgroundColor, borderColor, customStyles = {}) => ({
34-
backgroundColor: backgroundColor || theme.colors.surfaceVariant,
35-
borderRadius: theme.custom.borderRadius,
36-
padding: theme.custom.spacing.md,
40+
backgroundColor: backgroundColor || theme?.colors?.surfaceVariant || '#f5f5f7',
41+
borderRadius: theme?.custom?.borderRadius || 8,
42+
padding: theme?.custom?.spacing?.md || 16,
3743
borderLeftWidth: 3, // Reduced from 4 for more subtle accent
3844
borderLeftColor: borderColor,
3945
...customStyles,
4046
}),
4147

4248
// Modern input styles
4349
getInputStyle: (customStyles = {}) => ({
44-
backgroundColor: theme.colors.surface,
50+
backgroundColor: theme?.colors?.surface || '#ffffff',
4551
...customStyles,
4652
}),
4753

4854
// Clean button styles
4955
getButtonStyle: (variant = 'contained', customStyles = {}) => ({
50-
borderRadius: theme.custom.borderRadius,
56+
borderRadius: theme?.custom?.borderRadius || 8,
5157
...customStyles,
5258
}),
5359
};

0 commit comments

Comments
 (0)