I'm running a loop inside a ScrollView and for no apparent reason it doesn't scroll. I've read other posts where they set flex:1 or flexGrow:1 which I tried but it still doesn't work.
I'm using expo to run the app on my android device.
fooditems.js
import React from "react";
import { View, Text, StyleSheet, ScrollView } from "react-native";
import { Divider, Image } from "react-native-elements";
const foods = [
{
title: "chicken",
description:
"Lorem ipsum dolor sit amet consectetur, recusandae error amet cum doloremque mollitia hic, porro autem qui libero fugit atque.",
image:
"some image link",
price: "$ 10.99",
},
{
title: "barbecued chicken",
description:
"Lorem ipsum dolor sit amet consectetur, adipisicing elit. Eaque quis quam architecto. ",
image:
"some image link",
price: "$ 14.99",
},
{
title: "barbecued chicken",
description:
"Lorem ipsum dolor sit amet consectetur, adipisicing elit. Eaque quis quam architecto. ",
image:
"some image link",
price: "$ 14.99",
},
];
export default function MenuItems() {
return (
<ScrollView>
{foods.map((food, index) => (
<View key={index}>
<View style={styles.menuItemStyle}>
<FoodInfo food={food} />
<FoodImage food={food} />
</View>
<Divider width={0.5} />
</View>
))}
</ScrollView>
);
}
const styles = StyleSheet.create({
menuItemStyle: {
flexDirection: "row",
justifyContent: "space-between",
margin: 20,
},
titleStyle: {
fontSize: 19,
fontWeight: "600",
},
});
I'm not too sure why this is happening but on ios there don't seem to be such a problem.
EDIT: Same code with FlatList but it still won't scroll.
export default function MenuItems() {
const renderItem = ({ item }) => (
<View>
<View style={styles.menuItemStyle}>
<FoodInfo food={item} />
<FoodImage food={item} />
</View>
<Divider
width={0.5}
orientation="vertical"
style={{ marginHorizontal: 20 }}
/>
</View>
);
return (
<View>
<FlatList
data={foods}
renderItem={renderItem}
keyExtractor={(item) => item.id}
/>
</View>
);
}
const styles = StyleSheet.create({
menuItemStyle: {
flexDirection: "row",
justifyContent: "space-between",
margin: 20,
},
titleStyle: {
fontSize: 19,
fontWeight: "600",
},
});
const FoodInfo = (props) => (
<View style={{ width: 240, justifyContent: "space-between" }}>
<Text style={styles.titleStyle}>{props.food.title}</Text>
<Text>{props.food.description}</Text>
<Text>{props.food.price}</Text>
</View>
);
const FoodImage = (props) => (
<View>
<Image
source={{ uri: props.food.image }}
style={{ width: 100, height: 100, borderRadius: 9 }}
/>
</View>
);