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

The Bootstrap carousel's transition effect is not functioning as expected

The fade transition I added to my Bootstrap 4 carousel isn't working properly. It seems like the effect is not being applied to the carousel. Here is the HTML code snippet: <div id="testimonialsSlides" class="carousel carousel-fade" data-ride="fa ...

Parsing JSON data received from Angular using JSP

As I navigate through my Angular application, I'm encountering a challenge when trying to save data on the server side using JSP. The issue arises when Angular's $save method sends the object data in a JSON format that is not familiar to me. This ...

The jQuery Show Hide feature is experiencing issues specifically on Internet Explorer

Everything looks good in Firefox and Chrome, but unfortunately it's malfunctioning in IE. Does anyone have a suggestion for hiding select Dropdown options? I attempted using CSS with display: none but it didn't work. $j("#id option[value=&apos ...

Choose from the options provided to display the table on the screen

One of the challenges I am facing involves a table with two columns and a select option dropdown box. Each row in the table is associated with a color - green indicates good, red indicates bad, and so on. My goal is to have all values displayed when the pa ...

What are the drawbacks of implementing Redux Toolkit in React and React Native applications?

As a novice in the realm of React and React Native, I found implementing Redux Toolkit to be remarkably easier compared to traditional Redux. However, now I am at a crossroads: should I invest my time into learning Redux or focus solely on mastering Redu ...

File or directory does not exist: ENOENT error occurred while trying to scan 'pages'

Having trouble adding a sitemap to my nextjs app - when I go to http://localhost:3000/sitemap.xml, I get this error: Error: ENOENT: no such file or directory, scandir 'pages' https://i.sstatic.net/cxuvB.png The code in pages/sitemap.xml.js is a ...

Troubleshooting: My React project's Material UI dropdown menu is malfunctioning

I have created a component for building a dynamic drop-down menu that is based on a REST API URL: Here is the code for the Combo component: export default class Combo extends React.Component { constructor(props) { super(props) this.state = {dat ...

Record the cumulative amount computed using an asynchronous callback

If I use code similar to the one below, I am able to obtain the total byte size value every time a file is added. How can I log out only the total files size after it has been calculated in the fs.stat callback? var fs = require('fs'); var to ...

Highest Positioned jQuery Mobile Section

Requesting something a bit out of the ordinary, I understand. I currently have a jQueryMobile page set up with simplicity: <div data-role="page" class="type-home" id="home"> <div data-role="header" data-theme="b"> <h1>Our To ...

Updating React Form State with Redux Props

I have a custom component that receives data from its parent using Redux. This component is responsible for managing a multistep form, allowing users to go back and update input fields in previous steps. However, I'm facing an issue with clearing out ...

Adjusting the outline color of a Material UI Select component in outlined mode to a different color when the dropdown is activated (currently shown as blue)

Is there a way to change the outline color of Material-UI select component outlined variant correctly? I need help changing the default blue color to red, any assistance would be greatly appreciated Click here for an image reference Reference code snippe ...

javascript issue with setting the id attribute on a select option

I can't seem to set the id attribute in my select element using JavaScript. When I inspect it, the id attribute isn't showing up... Here's the first method using JS: var selectorElem = document.getElementById('selector') var ...

Using ThreeJs to create interactive 3D objects with button-controlled movement

Currently, I'm diving into the world of Three.js and I have a fascinating project in mind. I want to create movement buttons that will control the position of a sphere object. Through some research, I found out that I can use the onclick function on b ...

JQuery method for extracting a specific span's content from a div

I am faced with extracting specific text from a span within a div element. Below is the code snippet for my Div: '<div class="dvDynamic_' + pid + '"><p hidden="true">'+pid+'</p><span class="count_' + pid ...

Incorporating various language URLs in Next.js using next-i18n-next functionality

Thinking about using the next-i18next internationalization library. Check out next-i18next on GitHub Curious about how to change the language in the path of my URL. For example: /about-us /over-ons -> takes you to the Dutch version of the about us p ...

What could be causing the Angular router outlet to not route properly?

Check out this demo showcasing 2 outlets (Defined in app.module.ts): <router-outlet></router-outlet> <router-outlet name="b"></router-outlet> The specified routes are: const routes: Routes = [ { path: 'a', com ...

Keep things in line with async functions in Node JS

Hello, I am just starting out with NodeJs and I have a question. I am trying to push elements into an array called files based on the order of the urls provided, but it seems like I'm getting a random order instead. Below is the code I've been wo ...

Implementing Click-Activated Scroll-to-Div Feature in React

I need to implement a scroll-to-div feature in my React App. However, the current structure of my app is preventing me from passing refs as props correctly, making it challenging to utilize ref.current.scrollIntoView(). The layout of my code looks like th ...

Why isn't the jQuery click() function functioning on my modified HTML?

I am trying to create a unique version of the go-moku game using different programming languages and databases. My aim is to enhance the game's functionality by incorporating jQuery, PHP, and a MySQL database. var moveCount = -1; setInterval(function ...

Create a dynamic form using JSON data and the Material UI library

Looking for assistance in creating a dynamic form on Next.js by parsing JSON files and generating the required components from the JSON data. Additionally, seeking guidance on utilizing the Material UI library for styling. Any examples or help would be g ...