You don't need to define height for comment parent component view.
import * as React from "react";
import {
Text,
View,
StyleSheet,
FlatList,
Image,
Dimensions,
} from "react-native";
import Constants from "expo-constants";
const comments = [
{
id: 1,
username: "elonmusk",
message:
"If I dig my grave deep enough, maybe it comes out other side of Earth ",
avatar:
"https://pbs.twimg.com/profile_images/1590968738358079488/IY9Gx6Ok.jpg",
},
{
id: 2,
username: "ValaAfshar",
message: "This incredible animation shows how deep humans have dug.",
avatar: "https://pbs.twimg.com/profile_images/1259558245/vala_300dpi.jpg",
},
{
id: 3,
username: "Erdayastronaut",
message:
"In my opinion this is you at your best. Getting super deep into really nerdy aspects of rocket science. No agenda, division or trolling. Just pure rocket science. Now THAT is inspiring and uniting! Let’s get humans to Mars!!!",
avatar:
"https://pbs.twimg.com/profile_images/1253477073265532928/MmGBMWsQ.jpg",
},
];
export default function App() {
const renderItem = ({ item }) => (
<View
style={{
backgroundColor: "white",
borderRadius: 10,
borderWidth: 0.3,
borderColor: "#333",
marginBottom: 5,
padding: 10,
}}
>
<View style={{ flexDirection: "row", paddingVertical: 2 }}>
<Image
source={{ uri: item.avatar }}
style={{ width: 30, height: 30, borderRadius: 30 / 2 }}
/>
<View style={{ paddingHorizontal: 5 }}>
<Text style={{ fontWeight: "700" }}> {item.username} </Text>
<Text style={{ width: Dimensions.get("window").width - (60 + 20) }}>
{item.message}
</Text>
</View>
</View>
</View>
);
return (
<View style={styles.container}>
<FlatList
data={comments}
renderItem={renderItem}
keyExtractor={({ id }) => id.toString()}
/>
</View>
);
}
const styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: "center",
paddingTop: Constants.statusBarHeight,
backgroundColor: "#ecf0f1",
padding: 8,
},
});
Live Demo - https://snack.expo.dev/@emmbyiringiro/eea97f