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.

(Android/FlatList) Fix onMomentumScrollEnd being called multiple times

See original GitHub issue

Description

image

Version

0.64.1

Output of react-native info

image

Steps to reproduce

image

Snack, code example, screenshot, or link to a repository

No response

Issue Analytics

  • State:open
  • Created 2 years ago
  • Reactions:4
  • Comments:12 (1 by maintainers)

github_iconTop GitHub Comments

9reactions
josecarlosrxcommented, Apr 20, 2022

Solution using useRef:

const canMomentum = React.useRef(false);

const onMomentumScrollBegin = () => {
  canMomentum.current = true;
};

const onMomentumScrollEnd = () => {
  if (canMomentum.current) {
    // console.log('onMomentumScrollEnd');
  }

  canMomentum.current = false;
};

return (
  <ScrollView
    onMomentumScrollBegin={onMomentumScrollBegin}
    onMomentumScrollEnd={onMomentumScrollEnd}
  ></ScrollView>
);

4reactions
rubydevecommented, Jan 13, 2022

This is how it worked for me

const [canmomentum, setCanMomentum] = useState(false);
<ScrollView
      onScroll={( event ) => {
           setCanMomentum(true)
     }}
     onMomentumScrollEnd={() => {
           if (canmomentum) console.log('onMomentumScrollEnd')
           setCanMomentum(false)
     }}
>
     <Content/>
</ScrollView>
Read more comments on GitHub >

github_iconTop Results From Across the Web

FlatList onEndReached being called multiple times [duplicate]
This solution worked for me. Add onMomentumScrollBegin and modify onEndReached in FlatList Component. <FlatList style = { .
Read more >
FlatList - React Native
Multiple column support. ... To render multiple columns, use the numColumns prop. ... Called once when the scroll position gets within ...
Read more >
scrolleventthrottle android - You.com | The search engine you control.
IOS animation works perfectly, but Android animation jumping and lagging when i scroll. I tried to inscrease scroll value and Android animation became...
Read more >
iOS : FlatList onEndReached being called multiple times
iOS : FlatList onEndReached being called multiple times [ Gift : Animated Search Engine : https://bit.ly/AnimSearch ] iOS : FlatList ...
Read more >
Common bugs in React Native ScrollView and how to fix them
Now that we know when to use the ScrollView component, let's take a look at how to use it. Beginners often waste a...
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