React Native - Is it possible to control the speed at which the ScrollView scrolls

Viewed 1423

I have looked at many posts and they seem to suggest that it is not possible. However, they are very old posts. I am curious if this is possible now.

I am using expo in my project and referred the below,

https://github.com/expo/react-native/archive/sdk-36.0.0.tar.gz

I don't seem to find the duration variable as suggested in the below pull request that is requested as a feature.

https://github.com/facebook/react-native/pull/17422

Any help would be appreciated.Any workarounds if this is not possible? I am thinking of setting a time interval and wrap the scrollview around but I am not sure if that works.

2 Answers

would like to know why you need to do this. Maybe understand we'll can help with other way.

I got this working by having setInterval call a function(in which you define the logic or the pace at which the scroll should move).

this.interval= setInterval(this.scrollwithSpeed, 100); // Set the function to this timer

scrollwithSpeed() {
  position = this.state.currentPosition + x; // x decides the speed and currentPosition is set to 0 initially.
  this.scrollObject.scrollTo(
      { y: position, animated: true }
  );
  this.setState({ currentPosition: position });
}

Make sure you call clearInterval(this.interval) after it is done.

Related