reactjs - 向下滚动到 React Native ScrollView 中的特定视图
问题描述
我希望能够在按下按钮后滚动一个,以便它在屏幕上可见。我怎样才能告诉一个 react-native ScrollView 移动到某个位置?
解决方案
您好,您可以使用属性 scrollTo 如下所示
import {useRef} from "react"
import {
ScrollView,
Button,
} from 'react-native';
const YouComp = () => {
const refScrollView = useRef(null);
const moveTo = () => {
refScrollView.current.scrollTo({x: value1, y: value2});
// or just refScrollView.current.scrollTo({x: value1}); if you want to scroll horizontally
// or just refScrollView.current.scrollTo({y: value2}); if you want to scroll vertically
}
return (<>
<Button onPress={moveTo} title="title" />
<ScrollView ref={refScrollView}>
...
</ScrollView>
</>);
}
您可以设置 x 或 y 值或两者
在此处查看完整文档
推荐阅读
- docusignapi - Docusign SDK - 为什么在创建 SignHere 标记时忽略 document_id?
- python - 如何使用python制作一个圆角的乌龟矩形?
- python - 如何使用包含字符串的字典键以及包含列表的字典键创建 csv 文件?
- swift - Firebase 快照到对象数组
- python - 使用 GraphQL 和 gql 包 - 更新 GitHub 存储库分支保护规则设置
- html - 为什么我在 Firefox (81.0.1) 中看到垂直滚动条,但在 Chrome (78.0.3904.108)、Edge、Safari、Qtweb 中没有?
- oracle - Oracle ORDS 更新列
- kubernetes - Kubernetes:节点未就绪
- swift - 如何管理多个通知和观察者
- ruby - 使用 google-api-ruby-client 将文本写入 google doc 文件