反应本机scrollview水平轻击向左或向右滑动 [英] react native scrollview horizontal swipe left or right on tap

查看:59
本文介绍了反应本机scrollview水平轻击向左或向右滑动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在以全屏模式显示图片库.我正在水平使用scrollview滚动图片.现在,我可以通过向左或向右滑动来滚动图片,并使用启用 pagingEnabled 的道具.

I am showing pictures gallery in full screen mode. I am using scrollview in horizontal for scrolling the pictures. Right now I can scroll the pictures by swiping left or right and I using the pagingEnabled enabled props.

但是我想添加更多手势,当用户在左侧或右侧(与边缘的距离)上点击时,它将自动映射交换手势.我该怎么办?

But I want to add more gesture, where when user tap on left or right ( a distance from the edge) , it will automatically mapping the swapping gesture. How can I do this?

推荐答案

获取 ref < ScrollView> ,然后到 scrollToEnd()或使用 scrollTo 方法- https://facebook.github.io/react-native/docs/scrollview.html#scrollto

Get a ref to the <ScrollView> then to scrollToEnd() or use scrollTo methods - https://facebook.github.io/react-native/docs/scrollview.html#scrollto

要计算页码,您可以使用 onLayout 来计算页面大小.如果这是设备的宽度,那很简单,只需使用 Dimensions.get('window').width ,然后将其输入到 scrollTo x 代码>.

To calculate page number, you would use onLayout to calculate sizes of your pages. If it's the width of the device then that's easy, just use Dimensions.get('window').width then feed that to the x in scrollTo.

这篇关于反应本机scrollview水平轻击向左或向右滑动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆