如何在React Native中创建图片滑动器?

时间:2018-07-13 18:56:03

标签: reactjs react-native

现在在我们的应用程序中,我们能够在ScrollView中滚动图像,但是图像在滚动之间卡住了。如果用户没有在应用程序中完全滚动图像,我想使其滚动到哪里,从而完成了他们的工作,并且图像固定到位。我希望能够计算出图像向哪个方向滑动了多少,但是我很难找到实现此目的的方法。有人知道这样做的简单方法吗?

<ScrollView style={{borderRadius: 7}}
    horizontal
    showsHorizontalScrollIndicator={false}
    scrollEventThrottle={10}
    pagingEnabled
    onScroll={
        Animated.event(
            [{nativeEvent: {contentOffset: {x: this.calcImgPosition()}}}]
        )
    }
>
    {imageArray}
</ScrollView>

2 个答案:

答案 0 :(得分:2)

您可以使用react-native-swiper-flatlist组件。使用起来相当简单,而且文档很好(https://github.com/gusgard/react-native-swiper-flatlist)。

答案 1 :(得分:0)

如果您想通过链接使用多张图片,那么react-native-image-swiper将为您提供帮助。

用法如此简单。

import {Dimensions} from 'react-native';
import ImagesSwiper from "react-native-image-swiper";

const { width, height } = Dimensions.get("window");
const customImg = [
  "https://..",       // img link 1
  "https://...",      // img link 2
  "https://...."      // img link 3
  // ..
];

<ImagesSwiper 
  images={customImg}
  width={width} 
  height={height - 400} 
/>
相关问题