Skip to content

Commit a727f8b

Browse files
committed
Refactor food items view in App component
1 parent e5b4d17 commit a727f8b

File tree

2 files changed

+31
-17
lines changed

2 files changed

+31
-17
lines changed

src/app/index.tsx

Lines changed: 4 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,12 @@
11
import { StyleSheet, Text, View } from "react-native";
2-
import { AntDesign } from "@expo/vector-icons";
2+
import FoodListItem from "../components/FoodListItem";
33

44
export default function App() {
55
return (
66
<View style={styles.container}>
77
{/* Food Items View */}
8-
<View
9-
style={{
10-
backgroundColor: "gainsboro",
11-
padding: 10,
12-
borderRadius: 5,
13-
flexDirection: "row",
14-
justifyContent: "space-between",
15-
alignItems: "center",
16-
}}
17-
>
18-
<View style={{ flex: 1, gap: 5 }}>
19-
<Text style={{ fontWeight: "bold", fontSize: 16 }}>Pizza</Text>
20-
<Text style={{ color: "dimgray" }}>350 cal, Dominos</Text>
21-
</View>
22-
<AntDesign name="pluscircleo" size={24} color="royalblue" />
23-
</View>
8+
<FoodListItem item={{ label: "Pizza", cal: 75, brand: "Dominos" }} />
9+
<FoodListItem item={{ label: "Apple", cal: 50, brand: "Generic" }} />
2410
</View>
2511
);
2612
}
@@ -31,5 +17,6 @@ const styles = StyleSheet.create({
3117
backgroundColor: "#fff",
3218
justifyContent: "center",
3319
padding: 10,
20+
gap: 5,
3421
},
3522
});

src/components/FoodListItem.tsx

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import { StyleSheet, Text, View } from "react-native";
2+
import { AntDesign } from "@expo/vector-icons";
3+
4+
const FoodListItem = ({ item }) => {
5+
return (
6+
<View
7+
style={{
8+
backgroundColor: "gainsboro",
9+
padding: 10,
10+
borderRadius: 5,
11+
flexDirection: "row",
12+
justifyContent: "space-between",
13+
alignItems: "center",
14+
}}
15+
>
16+
<View style={{ flex: 1, gap: 5 }}>
17+
<Text style={{ fontWeight: "bold", fontSize: 16 }}>{item.label}</Text>
18+
<Text style={{ color: "dimgray" }}>
19+
{item.cal} cal, {item.brand}
20+
</Text>
21+
</View>
22+
<AntDesign name="pluscircleo" size={24} color="royalblue" />
23+
</View>
24+
);
25+
};
26+
27+
export default FoodListItem;

0 commit comments

Comments
 (0)