Skip to content

Commit b3b7916

Browse files
committed
feat: Refactor FriendsScreen, GroupDetailsScreen, and HomeScreen to use theme-based styling and improve code organization
1 parent 2f815fb commit b3b7916

File tree

3 files changed

+193
-182
lines changed

3 files changed

+193
-182
lines changed

frontend/screens/FriendsScreen.js

Lines changed: 45 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,61 @@
11
import { useIsFocused } from '@react-navigation/native';
22
import { useContext, useEffect, useState } from 'react';
33
import { Alert, FlatList, StyleSheet, View } from 'react-native';
4-
import { ActivityIndicator, Appbar, Divider, IconButton, List, Text } from 'react-native-paper';
4+
import { ActivityIndicator, Appbar, Divider, IconButton, List, Text, useTheme } from 'react-native-paper';
55
import { getFriendsBalance } from '../api/groups';
66
import { AuthContext } from '../context/AuthContext';
77

88
const FriendsScreen = () => {
99
const { token, user } = useContext(AuthContext);
10+
const theme = useTheme();
1011
const [friends, setFriends] = useState([]);
1112
const [isLoading, setIsLoading] = useState(true);
1213
const [showTooltip, setShowTooltip] = useState(true);
1314
const isFocused = useIsFocused();
1415

16+
// Create styles inside component to access theme
17+
const styles = StyleSheet.create({
18+
container: {
19+
flex: 1,
20+
},
21+
loaderContainer: {
22+
flex: 1,
23+
justifyContent: 'center',
24+
alignItems: 'center',
25+
},
26+
explanationContainer: {
27+
backgroundColor: '#f8fafc',
28+
margin: 8,
29+
borderRadius: theme.custom.borderRadius,
30+
borderLeftWidth: 3,
31+
borderLeftColor: '#3b82f6',
32+
shadowOffset: { width: 0, height: 1 },
33+
shadowOpacity: 0.05,
34+
shadowRadius: 2,
35+
elevation: 1,
36+
},
37+
explanationContent: {
38+
flexDirection: 'row',
39+
alignItems: 'flex-start',
40+
padding: 12,
41+
},
42+
explanationText: {
43+
fontSize: 12,
44+
color: '#555',
45+
lineHeight: 16,
46+
flex: 1,
47+
paddingRight: 8,
48+
},
49+
closeButton: {
50+
margin: 0,
51+
marginTop: -4,
52+
},
53+
emptyText: {
54+
textAlign: 'center',
55+
marginTop: 20,
56+
}
57+
});
58+
1559
useEffect(() => {
1660
const fetchData = async () => {
1761
setIsLoading(true);
@@ -119,43 +163,4 @@ const FriendsScreen = () => {
119163
);
120164
};
121165

122-
const styles = StyleSheet.create({
123-
container: {
124-
flex: 1,
125-
},
126-
loaderContainer: {
127-
flex: 1,
128-
justifyContent: 'center',
129-
alignItems: 'center',
130-
},
131-
explanationContainer: {
132-
backgroundColor: '#f8fafc', // More subtle blue-gray background
133-
margin: 8,
134-
borderRadius: theme.custom.borderRadius,
135-
borderLeftWidth: 3, // Reduced border width
136-
borderLeftColor: '#3b82f6', // Modern blue
137-
...theme.custom.shadow.small,
138-
},
139-
explanationContent: {
140-
flexDirection: 'row',
141-
alignItems: 'flex-start',
142-
padding: 12,
143-
},
144-
explanationText: {
145-
fontSize: 12,
146-
color: '#555',
147-
lineHeight: 16,
148-
flex: 1,
149-
paddingRight: 8,
150-
},
151-
closeButton: {
152-
margin: 0,
153-
marginTop: -4,
154-
},
155-
emptyText: {
156-
textAlign: 'center',
157-
marginTop: 20,
158-
}
159-
});
160-
161166
export default FriendsScreen;

frontend/screens/GroupDetailsScreen.js

Lines changed: 102 additions & 98 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,108 @@ const GroupDetailsScreen = ({ route, navigation }) => {
1313
const [settlements, setSettlements] = useState([]);
1414
const [isLoading, setIsLoading] = useState(true);
1515

16-
// Create styles with theme access
17-
const styles = createStyles(theme);
16+
// Create styles inside component to access theme
17+
const styles = StyleSheet.create({
18+
container: {
19+
flex: 1,
20+
},
21+
contentContainer: {
22+
flex: 1,
23+
padding: 16,
24+
},
25+
loaderContainer: {
26+
flex: 1,
27+
justifyContent: 'center',
28+
alignItems: 'center',
29+
},
30+
card: {
31+
marginBottom: 16,
32+
},
33+
expensesTitle: {
34+
marginTop: 16,
35+
marginBottom: 8,
36+
fontSize: 20,
37+
fontWeight: 'bold',
38+
},
39+
memberText: {
40+
fontSize: 16,
41+
lineHeight: 24,
42+
},
43+
fab: {
44+
position: 'absolute',
45+
margin: 16,
46+
right: 0,
47+
bottom: 0,
48+
},
49+
// Settlement Summary Styles
50+
settlementContainer: {
51+
gap: 16,
52+
},
53+
settledContainer: {
54+
alignItems: 'center',
55+
paddingVertical: 12,
56+
},
57+
settledText: {
58+
fontSize: 16,
59+
color: '#2e7d32',
60+
fontWeight: '500',
61+
},
62+
owedSection: {
63+
backgroundColor: '#fef7f7',
64+
borderRadius: theme.custom.borderRadius,
65+
padding: 16,
66+
borderLeftWidth: 3,
67+
borderLeftColor: '#ef4444',
68+
shadowOffset: { width: 0, height: 1 },
69+
shadowOpacity: 0.05,
70+
shadowRadius: 2,
71+
elevation: 1,
72+
},
73+
receiveSection: {
74+
backgroundColor: '#f0fdf4',
75+
borderRadius: theme.custom.borderRadius,
76+
padding: 16,
77+
borderLeftWidth: 3,
78+
borderLeftColor: '#22c55e',
79+
shadowOffset: { width: 0, height: 1 },
80+
shadowOpacity: 0.05,
81+
shadowRadius: 2,
82+
elevation: 1,
83+
},
84+
sectionTitle: {
85+
fontSize: 16,
86+
fontWeight: '600',
87+
marginBottom: 8,
88+
color: '#333',
89+
},
90+
amountOwed: {
91+
color: '#d32f2f',
92+
fontWeight: 'bold',
93+
},
94+
amountReceive: {
95+
color: '#2e7d32',
96+
fontWeight: 'bold',
97+
},
98+
settlementItem: {
99+
marginVertical: 4,
100+
},
101+
personInfo: {
102+
flexDirection: 'row',
103+
justifyContent: 'space-between',
104+
alignItems: 'center',
105+
paddingVertical: 4,
106+
},
107+
personName: {
108+
fontSize: 14,
109+
color: '#555',
110+
flex: 1,
111+
},
112+
settlementAmount: {
113+
fontSize: 14,
114+
fontWeight: '600',
115+
color: '#333',
116+
},
117+
});
18118

19119
// Currency configuration - can be made configurable later
20120
const currency = '₹'; // Default to INR, can be changed to '$' for USD
@@ -191,100 +291,4 @@ const GroupDetailsScreen = ({ route, navigation }) => {
191291
);
192292
};
193293

194-
const styles = StyleSheet.create({
195-
container: {
196-
flex: 1,
197-
},
198-
contentContainer: {
199-
flex: 1,
200-
padding: 16,
201-
},
202-
loaderContainer: {
203-
flex: 1,
204-
justifyContent: 'center',
205-
alignItems: 'center',
206-
},
207-
card: {
208-
marginBottom: 16,
209-
},
210-
expensesTitle: {
211-
marginTop: 16,
212-
marginBottom: 8,
213-
fontSize: 20,
214-
fontWeight: 'bold',
215-
},
216-
memberText: {
217-
fontSize: 16,
218-
lineHeight: 24,
219-
},
220-
fab: {
221-
position: 'absolute',
222-
margin: 16,
223-
right: 0,
224-
bottom: 0,
225-
},
226-
// Settlement Summary Styles
227-
settlementContainer: {
228-
gap: 16,
229-
},
230-
settledContainer: {
231-
alignItems: 'center',
232-
paddingVertical: 12,
233-
},
234-
settledText: {
235-
fontSize: 16,
236-
color: '#2e7d32',
237-
fontWeight: '500',
238-
},
239-
owedSection: {
240-
backgroundColor: '#fef7f7', // More subtle background
241-
borderRadius: theme.custom.borderRadius,
242-
padding: 16,
243-
borderLeftWidth: 3, // Reduced border width for modern look
244-
borderLeftColor: '#ef4444',
245-
...theme.custom.shadow.small,
246-
},
247-
receiveSection: {
248-
backgroundColor: '#f0fdf4', // More subtle background
249-
borderRadius: theme.custom.borderRadius,
250-
padding: 16,
251-
borderLeftWidth: 3, // Reduced border width for modern look
252-
borderLeftColor: '#22c55e',
253-
...theme.custom.shadow.small,
254-
},
255-
sectionTitle: {
256-
fontSize: 16,
257-
fontWeight: '600',
258-
marginBottom: 8,
259-
color: '#333',
260-
},
261-
amountOwed: {
262-
color: '#d32f2f',
263-
fontWeight: 'bold',
264-
},
265-
amountReceive: {
266-
color: '#2e7d32',
267-
fontWeight: 'bold',
268-
},
269-
settlementItem: {
270-
marginVertical: 4,
271-
},
272-
personInfo: {
273-
flexDirection: 'row',
274-
justifyContent: 'space-between',
275-
alignItems: 'center',
276-
paddingVertical: 4,
277-
},
278-
personName: {
279-
fontSize: 14,
280-
color: '#555',
281-
flex: 1,
282-
},
283-
settlementAmount: {
284-
fontSize: 14,
285-
fontWeight: '600',
286-
color: '#333',
287-
},
288-
});
289-
290294
export default GroupDetailsScreen;

0 commit comments

Comments
 (0)