【问题标题】:React Native - Is it possible to control the speed at which the ScrollView scrollsReact Native - 是否可以控制 ScrollView 滚动的速度
【发布时间】:2020-04-07 17:24:56
【问题描述】:

我看过很多帖子,他们似乎暗示这是不可能的。但是,它们是非常古老的帖子。我很好奇现在这是否可能。

我在我的项目中使用 expo 并参考了以下内容,

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

我似乎没有找到作为功能请求的以下拉取请求中建议的持续时间变量。

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

任何帮助将不胜感激。如果这是不可能的任何解决方法?我正在考虑设置一个时间间隔并环绕滚动视图,但我不确定这是否有效。

【问题讨论】:

  • 检查滚动视图的decelerationRate
  • @SDushan 我认为减速率是用户移开手指后scrollView滚动的速度。在我的情况下,按下按钮后,我需要 scrollView 以自定义速度滚动,更像是自动滚动。

标签: reactjs react-native scrollview react-native-android react-native-ios


【解决方案1】:

想知道您为什么需要这样做。也许明白我们可以通过其他方式提供帮助。

【讨论】:

  • 单击按钮后,滚动视图中的内容会滚动,而后面有音频播放。滚动速度必须与读取内容的速度保持一致。
【解决方案2】:

我通过 setInterval 调用一个函数来完成这项工作(您可以在其中定义滚动应该移动的逻辑或速度)。

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 });
}

确保在完成后调用 clearInterval(this.interval)。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-09-04
    • 2019-07-16
    • 2018-04-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多