question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[QUESTION] Implementing this within a FlatList component

See original GitHub issue

To Do First

  • Take a look in the README
  • Take a look in the docs

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:open
  • Created 4 years ago
  • Reactions:1
  • Comments:8

github_iconTop GitHub Comments

4reactions
GitHubGregcommented, Sep 13, 2019

Your code works, but it uses columns={1}, so the images are one atop the other. Screen Shot 2019-09-12 at 8 40 09 AM

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: Screen Shot 2019-09-12 at 8 40 29 AM

For the record, these are the photos of @Luehang, not mine!

1reaction
GitHubGregcommented, Sep 13, 2019

Sorry @jasminmesada I meant to write they were the photos of @Luehang 😃 I’ve corrected the comment.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found