Tips for arranging images in a horizontal layout using FlatList in React Native

Is there a way to display feed images horizontally instead of vertically in FlatList? I've tried wrapping the images in a view with flex-direction set to row, as well as adding horizontal={true} to the FlatList, but nothing seems to work. Any suggestions on how to achieve this?

I have created a simple app using the code which you can access from this link: https://codesandbox.io/s/runtime-leaf-jywqqr?file=/src/App.js

Answer №1

sideways functions perfectly well, take a look at this straightforward illustration:

const Picture = ({url}) => (
  <Image style={{width: 320, height: 180}} source={{uri: url}} />
);

const Application = () => {
  const [pictures, setPictures] = useState([])
  useEffect(() => {
    const getImages = async () => {
        const response = await fetch("https://photos.example.com/v2/list")
        if (response.ok) {
          setPictures(await response.json())
        }
    }
    getImages()
  }, [])
  return (
    <FlatList
      data={pictures}
      sideways
      renderItem={({item}) => <Picture url={item.download_url} />}
      keyExtractor={item => item.id}
    />
  );
};

Answer №2

In my opinion, it would be beneficial to define the width and height for the item.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Is there a way to customize the color of the bar displaying my poll results?

My poll features two results bars that are currently both blue. I attempted to change the color of these bars but was unsuccessful. I've searched for solutions on stack overflow, specifically How can I change the color of a progress bar using javascr ...

Uploading image files using Node Express and returning them as JSON in an API response

Is it possible to send json along with an image file in Express? I know that you can serve an image using res.sendFile const path = require('path'); app.get('/image/:filename', (req, res, next) => { res.type('png'); r ...

Issue with the event handler not updating the state

I'm encountering a bit of a conundrum here. Inside the useEffect() hook, I've added an event listener. The event is firing (console.log() prints as expected), but unfortunately the state isn't updating accordingly. Any idea what might be cau ...

Dynamic value for textbox using Selenium

While working on building a test case, I encountered a problem with a search text box on my web page. The Selenium IDE was used to record the actions taken. type | id=search_input_char_name_136 | myproduct // textbox for search click | css=button.oe_ ...

Getting the value of a JavaScript variable and storing it in a Python variable within a Python-CGI script

Is there a way to capture the value of a JavaScript variable and store it in a Python variable? I have a Python-CGI script that generates a selection box where the user can choose an option from a list. I want to then take this selected value and save it ...

The JavaScript filter function will only return arrays that have matching IDs

How can I filter out book data based on the author's id? I have a list of books with various author ids, and I want to only return the books that match a specific author id. However, my current filtering method doesn't seem to work correctly as i ...

Encountering the error message "PreviewBuilder.corePresets is not iterable" while integrating Storybook into a fresh Next.js project

After some searching, I couldn't find a solution to my Storybook issue as a newbie. Starting with a new NextJS project and adding ESLint, Jest, and Tailwind went smoothly. Trying to integrate Storybook following the instructions at this link: Upon ...

The grid is experiencing improper sizing in the row orientation

Challenges with Grid Layout In my current project, I am facing a challenge in creating a responsive layout with a dynamic grid within a page structure that includes a header and footer. The main issue arises when the grid items, designed to resemble books ...

Having Trouble with Gulp and AutoPrefixer Integration

I have integrated Gulp into my project and am looking to utilize the autoprefixer feature. Here is a glimpse of my current gulp file: // Including gulp var gulp = require('gulp'); // Including necessary plugins var concat = require('gulp-c ...

Increasing the height of nested Bootstrap columns by stretching them out

I am trying to ensure that the first two columns in both the green and violet rows always have the same height. I initially thought of using d-flex align-items-stretch, but it seems like it is not working because those elements are not within the same row ...

Encountering a JavaScript toJSON custom method causing a StackOverflow error

Unique Scenario Upon discovering this answer, a new idea struck me - creating an object from a JSON literal. This led me to believe I could do the opposite using the handy JSON method: JSON.stringify(myObject). Curious, I proceeded as follows: function ...

I'm struggling to grasp the reason behind the error message stating that x is not a function

Can someone help explain why I keep getting the error message "5Style is not a function"? NationalLevelCategoriesChosenList = [ ["5Style", "5MelodyHarmony", "5RhythmTempo", "5TextureStructureForm", "5Timbre"] ], [ [] ]; if (NationalLevelCategoriesC ...

Interactive YouTube Video Player that keeps video playing in original spot upon clicking the button

Currently, I'm working on a project that involves combining navigation and a video player within the same div container. Here is an image link And another image link The concept is that when you click on one of the four boxes, a new video will appe ...

Exporting an HTML table to Excel while excluding any hidden <td> elements

I have a web application with an HTML table that displays data to users. I wanted to export the table to Excel and found a jQuery code for it. However, the exported data includes information that is hidden in the table. Is there a way to export the tabl ...

Looking to minimize the amount of HTML code in Angularjs by utilizing ng-repeat

Working with some HTML <tr class="matrix_row" ng-repeat="process in matrixCtrl.processes | filter : { park: parentIndex } track by $index"> <td class="properties" ng-click="dashboardCtrl.currParam=0; dashboardCtrl.currentProcess=process"> ...

Is your sticky sidebar getting in the way of your footer?

I've developed a custom sticky sidebar for displaying ads, but I'm facing an issue. When I scroll to the bottom of the page, it overlaps with the footer. Can someone please take a look at this? - var stickySidebar = $('.sticky'); if ...

Is the key to achieving optimal client interactions within a client layout, while still maintaining its role as a server component, truly possible?

My current challenge involves managing modals opening and closing with server components instead of client components. In the past, I used to lift the state up to my Layout for client components: export default function Layout({ children }) { const [showP ...

What caused the sudden malfunction in the extended Express Request?

Currently, I am utilizing Node v12 along with Express v4.16.4 and Typescript version 3.8.3 within VSCode. This particular snippet of code has remained unchanged for almost 8 months and is utilized in all our routers. export interface ICustomRequest exten ...

Using the setInterval function in conjunction with the remoteCommand to create a

I am attempting to create a remote command that calls a bean function and updates a progress bar every 2 seconds until cancelled. The remote command looks like this: <p:remoteCommand id="usedCall" name="queryUsed" onco ...

Tips for achieving comma-separated user input via ngModel and appending it to an array

I am working on an email template that includes a cc option. I want users to be able to add email addresses with commas separating them and then push them to an array called $scope.notifyCtrl.cc. How can I accomplish this using AngularJS 1.5 and above? mai ...