react-native - 如何在函数组件的 ScrollView 中使用 ScrollTo 函数?
问题描述
当元素确实安装时,我需要将 ScrollView 元素设置为我需要的位置(5 幻灯片,例如)。我怎样才能在功能组件中做到这一点?在反应原生
解决方案
使用 Ref 和 onContentSizeChange
const ref = React.useRef(null);
<ScrollView
ref={ref}
onContentSizeChange={() => {ref.current.scrollTo({x:1000,animated: false, duration:0})}}
>
推荐阅读
- java - 如何向 JComponent 添加多个矩形?
- javascript - 为什么在 vuejs 中将数据插入表时我的提交按钮不起作用
- javascript - 如何获取没有双引号的 Jade 文件
- javascript - 如何在 Sequelize Js 中更改数据库迁移顺序
- blockchain - 如何使用 web3 获取以太坊区块的数据
- mysql - CASE WHEN "__" LIKE "__" ELSE "__" MySQL 错误
- android - 从 TextView 的文本中获取字符串资源名称
- android - 移动模拟器/模拟器 Detox 屏幕截图工件在不同主机上运行时会有所不同
- c# - .Net Core Context ServiceLifetime 类型
- docker-swarm - 无需重启即可旋转 docker swarm 配置