Issue with React-Native FlatList's scrolling functionality

Struggling with implementing a scrolling FlatList in React Native. Despite trying various solutions found on Stack Overflow, such as adjusting flex properties and wrapping elements in views, the list still refuses to scroll.

Snippet of code (issue is within the second FlatList) -

                return(
                    <View style = {{ height: '100%' }}>
    
                        <View style = {{ width: '100%' }}>
                            <AppHeader />
                        </View>
    
                        <View style = {{ width: '100%'}}>
    
                            <View style = {{ width: '70%', alignSelf: 'center', flex: 1 }}>
     
                                <View>
                                    <FlatList
                                        data = {this.getTodayDay()}
                                        renderItem = {this.renderItemDays}
                                        keyExtractor = {this.keyExtractor}
                                    />
                                </View>
    
                                    <FlatList
                                        data = {this.getVisibleHours()}
                                        renderItem = {this.renderItem}
                                        keyExtractor = {this.keyExtractor}
                                        scrollEnabled = {true}
                                    />

                
                            </View>
    
                        </View>
    
                    </View>

this.renderItem -

renderItem = () => {

// irrelevant code


        
        if( isClass === true ){
            return(
                <ListItem bottomDivider = {true} style = {styles.renderItemActiveClass}>
                    <ListItem.Content>

                        <TouchableOpacity
                            onPress = {()=>{
                                this.props.navigation.navigate('ClassDetailsScreen', { "data": classData })
                            }}>
                                <ListItem.Title>{ definiteClassTime }</ListItem.Title>
                                <ListItem.Subtitle>{ classData.class_name }</ListItem.Subtitle>
                        </TouchableOpacity>

                    </ListItem.Content>
                </ListItem>
            )
        }
        else{
            return(
                <ListItem bottomDivider = {true} style = {styles.renderItemClass} 
                containerStyle = {styles.renderItemContent}>
                    <ListItem.Content>
                        <ListItem.Title>{item}:00</ListItem.Title>
                        <ListItem.Subtitle>No Class</ListItem.Subtitle>
                    </ListItem.Content>
                </ListItem>
            )
        }

}

the StyleSheet -


    renderItemClass: {
        borderColor: 'purple',
        borderWidth: 2
    }, 

    renderItemActiveClass: {
        borderColor: 'green',
        borderWidth: 2
    },

    renderItemContent: {
    },

Any insights on what might be causing this issue would be greatly appreciated!

Answer №1

Include a height for both flat lists and enclose the second flatlist within a separate view. See below for a sample code snippet:

return (
  <View style={{ height: "100%" }}>
    <View style={{ width: "100%" }}>
      <AppHeader />
    </View>

    <View style={{ width: "100%" }}>
      <View style={{ width: "70%", alignSelf: "center", flex: 1 }}>
        <View style={{ height: 60, alignSelf: "center" }}>
          <FlatList
            data={this.getTodayDay()}
            renderItem={this.renderItemDays}
            keyExtractor={this.keyExtractor}
          />
        </View>
        <View style={{ height: 60, alignSelf: "center" }}>
          <FlatList
            data={this.getVisibleHours()}
            renderItem={this.renderItem}
            keyExtractor={this.keyExtractor}
            scrollEnabled={true}
          />
        </View>
      </View>
    </View>
  </View>
);

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

Expanding the MatBottomSheet's Width: A Guide

The CSS provided above is specifically for increasing the height of an element, but not its width: .mat-bottom-sheet-container { min-height: 100vh; min-width: 100vw; margin-top: 80px; } Does anyone have a solution for expanding the width of MatBott ...

aligning a floating image vertically

One issue I am facing in my UI is that I have buttons with images floating next to text. While the setup works well, I am struggling to vertically align the image with the text. I've experimented with various solutions including using vertical-align: ...

What significance does it hold when an unhandled rejection event lacks a reason field?

Our app tracks client-side errors using Rollbar, but we keep encountering a not very helpful error message from Safari and Chrome: [unhandledrejection] error getting `reason` from event Upon investigation, I found that this message is generated by Rollbar ...

Having trouble figuring out how to load images into a div based on the current page location?

Looking for a solution to my problem - I have a navigation bar with a fixed div (A) on the far right side. The nav bar remains at the top of the page. There are 6 sections in the body of the page, each being 1200px tall divs. What I want is for a different ...

What steps do you need to take in order to transform this individual slideshow script into numerous slideshows

I came across this code online that effectively creates a slideshow. https://css-tricks.com/snippets/jquery/simple-auto-playing-slideshow/ Is there a way to modify the code to support multiple slideshows? I've made several attempts without success ...

The Vite manifest could not find the file "app.jsx" in the resources/js directory. Please run "npm run build

Following the guidelines from , I have successfully created a Laravel application with the following specifications: PHP 8.1.2 Laravel 9.33.0 React During development using VITE (npm run dev), everything works smoothly. However, when attempting to build ...

Having trouble installing the 'ws' npm package on MacOS Big Sur?

Every time I try to install the websocket package using "npm install ws", I keep getting this error message: npm ERR! code ENOSELF npm ERR! Refusing to install package with name "ws" under a package npm ERR! also called "ws". Did you name your project the ...

Stopping XSS Attacks in Express.js by Disabling Script Execution from POST Requests

Just starting to learn ExpressJs. I have a query regarding executing posted javascript app.get('/nothing/:code', function(req, res) { var code = req.params.code; res.send(code) }); When I POST a javascript tag, it ends up getting execut ...

Sharing data between ejs and javascript files

When using Express, I have encountered an issue with passing a variable to an EJS file called "index.ejs". res.render("index",{passedUser:req.user.alias}) Although I am able to successfully print it using <%=passedUser%> in the EJS file, I require ...

Struggling to figure out Visual Studio Code - Having trouble loading images and fonts into my CSS file

It seems like I'm missing something here (just so you know, I'm totally new at this). I attempted to use fonts that are loaded on my computer for my CSS stylesheet (font file in my VSC), but no luck. I also tried using images from my files as bac ...

"pre and post" historical context

Is there a way to create a stunning "Before and After" effect using full-sized background images? It would be amazing if I could achieve this! I've been experimenting with different examples but can't seem to get the second 'reveal' di ...

What steps can I take to avoid keypress events causing issues with the browser's input functionality?

Utilizing Bootstrap's modal component, I have implemented an "Add User" dialog within my web application. In order to streamline the user experience and enable quick data entry, I am aiming for the escape and enter keys to close and submit the form re ...

Validate if the JSON data array contains any elements

I'm currently working with an ajax code and I need to determine whether the JSON data contains an array or not. However, despite my attempts, I am still receiving incorrect output. $.ajax({ url: url, type: 'POST', da ...

Removing the column name from a JSON return in C# involves using a variety of techniques

Below is a JSON output I have received : [ { positionCode: "POS1", positionName: "POSITION 1", positionDescription: "", parentPosition: "POS2", }, { positionCode: "POS2", positionName: "POSITION ...

Exploring the World of Infinite Scrolling with React.js and Material_ui

I am currently working on a project using react.js As part of this project, I need to implement a board with infinite scroll similar to Facebook I have a specific question regarding this implementation. When scrolling the board and loading more posts li ...

Using and accessing Ajax response across all routes in an application

I am developing a Node.js Express API application that requires several AJAX calls at the start of the application for global data access in all requests. At the beginning of my app.js file, I include: var users = require('./modules/users'); I ...

When utilizing NavLink in React Router Dom for routing to an external link, a local host is automatically included in the prefix

I'm currently experiencing an issue with routing to an external link using React Router Dom 6.4. It seems that the localhost path is being appended to the URL. Can anyone provide insight on why this might be happening? localhost:3000/#/http://www.sav ...

Incorporating traditional Javascript classes for modeling in React development

Can traditional JavaScript classes be utilized in models within the MVC framework while using React, as opposed to relying on Redux or contexts & reducers which may impact reusability? If this approach is feasible, how can we efficiently 'subscribe&ap ...

Creating CSS-style overlayed images that are resizable

I have a collection of images all the same size, and I want them to be overlaid on top of each other. I've tried setting the position of the images to absolute, but this causes an issue with the container not adjusting its size accordingly. Additiona ...

What is the best way to transfer attribute values from multiple elements and paste them each into a separate element?

I have multiple elements with the tag <a class="banner2">. Each of these elements has a different URL for the background image and href value. <a href="#" target="_blank" class="banner2" style="background-image:url('<?php echo get_templat ...