使用滚动视图自动慢速滚动



我正在尝试使ScrollView中的文本自动滚动,速度慢到能够阅读它

我已经尝试过滚动到结束,但持续时间选项已被弃用。 我也尝试使用 scrollTo 并慢慢增加 y 偏移量,但它不是那么好。 也许我可以通过模拟用户滚动来做到这一点,但我不知道如何做。

startStopScrolling() {
if (this.state.scrolling == false) {
this.setState(state => ({ scrolling: true }));
let that = setInterval(() => {
if (this.state.scrolling == true) {
this.state.scrollOf = this.state.scrollOf + 1;
this.ref.scrollTo({ x: 0, y: this.state.scrollOf, animated: true });
}
}, 10);
} else {
this.setState(state => ({ scrolling: false }));
this.state.scrollOf = 0;
}
}
<ScrollView
ref={data => {
this.ref = data;
}}
>
<TouchableOpacity
onPress={() => {
this.startStopScrolling();
}}
>
<Text
style={{
fontSize: 25
}}
>
{this.props.navigation.state.params.text}
</Text>
</TouchableOpacity>
</ScrollView>

我创建了世博会零食工作示例: https://snack.expo.io/HyI0QBm_r

最新更新