use*_*578 4 scrollview react-native
我有一个应用程序,其中有一个 ScrollView 和一个按钮,里面有一个长文本:
return (
<ScrollView>
<Button onPress={slowlyScrollDown} title="Slowly scroll a bit down..." />
<Text>
[ Very long text here where user has to scroll ]
</Text>
</ScrollView>
)
Run Code Online (Sandbox Code Playgroud)
当用户按下按钮时,我想慢慢向下滚动一点,这样他就可以看到文本的前 5-10 行。
我会接受任何提供一段代码的答案,我可以如何实现它。
我不确定它会起作用,但这就是方向:
const [offset,setOffset] = useState(0);
const scrollViewRef = useRef();
const slowlyScrollDown = () => {
const y = offset + 80;
scrollViewRef.current.scrollTo({x: 0, y, animated: true});
setOffset(y);
}
return (
<ScrollView ref={scrollViewRef} >
<Button onPress={slowlyScrollDown} title="Slowly scroll a bit down..." />
<Text>
[ Very long text here where user has to scroll ]
</Text>
</ScrollView>
)
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3418 次 |
| 最近记录: |