0

I have a simple horizontal slider built using the ScrollView component. There is a button to go to the next slide and when pressed I call scrollTo method on that ScrollView component. I also need to detect when the scroll is finished to display some other animations. I tried using onMomentumScrollEnd and onScrollEndDrag callbacks but on android neither of them is called when I use scrollTo method. Is there any other way to detect scroll 'end' event?

Here is simple example on snack: https://snack.expo.io/@levani/forlorn-bacon

1 Answer 1

1

Try this solution, i've modified your snack

I've used onSroll listener with the function :

 const scrollDirection = (event) => {
    const offsetX = event.nativeEvent.contentOffset.x
    const dif = offsetX - (offset || 0);  
    console.log('dif',dif) 
    if (dif == 200) {
      alert('destination reached')
    } 

    setOffset(offsetX);

  };
Sign up to request clarification or add additional context in comments.

2 Comments

Makes sense. Thank you!
You'r welcome, if you consider its a solution for your problem please check answer. Thanks

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.