[QUESTION] Implementing this within a FlatList component
See original GitHub issueTo Do First
Ask your Question
Thanks for this great tool. I am using it within a feed post system, similar to Facebook. I use a <FlatList> to render each post, and then each post uses its own <MasonryList> with the photos from that post. However, the images don’t appear in a grid. They appear one atop the other. I have tried with several different options, and have also tried with your basic example, with the same result.
Works (shows images as grid):
import MasonryList from "react-native-masonry-list";
//...
render() {
return (
<MasonryList
images={[
{ source: { uri: "https://luehangs.site/pic-chat-app-images/beautiful-beautiful-women-beauty-40901.jpg" } },
{ uri: "https://luehangs.site/pic-chat-app-images/animals-avian-beach-760984.jpg",
{ URI: "https://luehangs.site/pic-chat-app-images/beautiful-blond-fishnet-stockings-48134.jpg",
id: "blpccx4cn" },
{ url: "https://luehangs.site/pic-chat-app-images/beautiful-beautiful-woman-beauty-9763.jpg" },
{ URL: "https://luehangs.site/pic-chat-app-images/attractive-balance-beautiful-186263.jpg" },
]}
/>
);
}
//...
Doesn’t work (shows images one atop the other):
import MasonryList from "react-native-masonry-list";
//...
render() {
return (
<FlatList
data={posts}
renderItem={({ item }) => {
return (
<MasonryList
images={[
{ source: { uri: "https://luehangs.site/pic-chat-app-images/beautiful-beautiful-women-beauty-40901.jpg" } },
{ uri: "https://luehangs.site/pic-chat-app-images/animals-avian-beach-760984.jpg",
{ URI: "https://luehangs.site/pic-chat-app-images/beautiful-blond-fishnet-stockings-48134.jpg",
id: "blpccx4cn" },
{ url: "https://luehangs.site/pic-chat-app-images/beautiful-beautiful-woman-beauty-9763.jpg" },
{ URL: "https://luehangs.site/pic-chat-app-images/attractive-balance-beautiful-186263.jpg" },
]}
/>
);
}}
/>
);
}
//...
Do you have any ideas on what might be causing this issue?
Thanks very much.
Tags FlatList, single column
Issue Analytics
- State:
- Created 4 years ago
- Reactions:1
- Comments:8
Top Results From Across the Web
reactjs - Implementation of flatlist - Stack Overflow
use FlatList like this, <FlatList data={flatListData} renderItem={({ item, index }) => ( <FlatListItem item={item}, index={index} /> )} />.
Read more >React Native FlatList Component - GeeksforGeeks
In this article, We are going to see how to create a FlatList in react-native. For this, we are going to use FlatList...
Read more >A deep dive into React Native FlatList - LogRocket Blog
FlatList is a React Native component that allows you to render lists with zero hassle and minimal code. Learn how to customize FlatList....
Read more >Optimizing Flatlist Configuration - React Native
The more complex your components are, the slower they will render. Try to avoid a lot of logic and nesting in your list...
Read more >How to use the FlatList component in React Native - Educative.io
Using the FlatList component · data - list of data that needs to be rendered. · renderItem - a function that needs to...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

Your code works, but it uses
columns={1}, so the images are one atop the other.If I change it to
columns={2}then it doesn’t show them in a grid as expected, it shows them one atop the other, in half the screen:For the record, these are the photos of @Luehang, not mine!
Sorry @jasminmesada I meant to write they were the photos of @Luehang 😃 I’ve corrected the comment.