FlatList - while list is scrolling/rendering items the JS thread is blocked, onPress are super delayed.
See original GitHub issueDescription
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:
- Created 7 years ago
- Reactions:53
- Comments:63 (10 by maintainers)
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
as an alternative and cleaner solution, I ended up wrap FlatList over ScrollView.
something like this:
it worked for me.
Yeah, it is is pretty tricky balancing memory, fill rate, responsiveness, and frame rate but we’ll keep optimizing!