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.

FlatList - while list is scrolling/rendering items the JS thread is blocked, onPress are super delayed.

See original GitHub issue

Description

While FlatList is scrolling and/or rendering items the JS thread is blocked… any events (onPress etc) on TocuchableWhatever are ingored or processed after FlatList finishes rendering. How can I pause FlatList rendering and process onPress?

Content rendered by FlatList while scrolling uses InteractionManager so if you want to pause it you just need to create an interaction handle. © @sahrens

I’ve tried that on my ListItem:

export default class ListItem extends Component { 

    shouldComponentUpdate() {
        return false;
    }

    render() {
        const {item} = this.props;

        return (
                <TouchableHighlight style={styles.item} underlayColor='rgba(255,255,255,.3)' activeOpacity={0.7} onPress={this._onPress}>
                     <View style={styles.row}>
                        <Image style={styles.image} source={{ uri: item.imgUrl}} />
                        <View style={styles.details}>
                            <BaseText style={styles.caption} weight={600}>{item.caption}</BaseText>
                            <BaseText style={styles.points}>{item.points} points</BaseText>
                        </View>
                        <TouchableOpacity hitSlop={{top: 10, left: 10, right: 10, bottom: 10}} >
                            <Icon style={styles.icon} name={item.favorite ? 'heart' : 'heart-outline'} size={24} color={'white'} />
                        </TouchableOpacity>
                    </View>
                </TouchableHighlight>
                )
    }

    _onPress = () => {
        const handle = InteractionManager.createInteractionHandle();
        this.props.onPress(this.props.item.key);
        InteractionManager.clearInteractionHandle(handle);
    }

}

but it does not fix the issue. Am I doing it wrong?

Additional Information

  • React Native version: 0.42.0
  • Platform: tired only on iOS (device)
  • Operating System: MacOS
  • Dev tools: Xcode

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Reactions:53
  • Comments:63 (10 by maintainers)

github_iconTop GitHub Comments

30reactions
farhanfahrezicommented, Oct 13, 2017

as an alternative and cleaner solution, I ended up wrap FlatList over ScrollView.

something like this:

<ScrollView>
  <FlatList />
</ScrollView>

it worked for me.

16reactions
sahrenscommented, Mar 15, 2017

Yeah, it is is pretty tricky balancing memory, fill rate, responsiveness, and frame rate but we’ll keep optimizing!

Read more comments on GitHub >

github_iconTop Results From Across the Web

When SectionList/Flatlist is scrolling/rendering items UI thread ...
Therefore, the onPress function delay for 3~5 seconds. So my questions are: Does Flastlist/Sectionlist re-render the whole list when it's ...
Read more >
Optimizing Flatlist Configuration - React Native
Here are a list of props that can help to improve FlatList performance: ... Cons: More items per batch means longer periods of...
Read more >
React Native: Correct Scrolling In Horizontal Flatlist With Item ...
While FlatList is scrolling and/or rendering items the JS thread is blocked. any events onPress etc on TocuchableWhatever are ingored or processed after....
Read more >
5 Reasons Why Your React Native App is Slow - In Plain English
Large sets of the list, images, assets, API responses and multiple ... will take more the JS thread will be blocked and more...
Read more >
Common bugs in React Native ScrollView and how to fix them
After putting all those elements inside the ScrollView component, ... FlatList exposes to us a long list of props that are designed for...
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