【问题标题】:swiping on react-native-snap-carousel is not working as expected在 react-native-snap-carousel 上滑动未按预期工作
【发布时间】:2020-05-28 22:13:22
【问题描述】:

我正在尝试使用 react-native-snap-carousel 但是,滑动效果没有按预期工作 - 通常很难左右滑动,它需要用户更加努力地滑动才能移动到另一张图片(如如下链接所示)。

Swiping issue with React Native Snap Carousel

我找不到任何记录在案的解决方案,但我找到了一种可能的道具 - swipeThreshold。我尝试了各种值,但问题仍然存在。

有人知道解决办法吗?

【问题讨论】:

    标签: react-native react-native-snap-carousel


    【解决方案1】:

    我建议你使用 react-native-image-slider

    它灵活且易于使用。 https://www.npmjs.com/package/react-native-image-slider 我制作了一个名为 slider.js 的组件:

    import React, { Component } from 'react';
    import {
      View,
      StyleSheet,
      Image,
    
    } from 'react-native';
    import ImageSlider from 'react-native-image-slider';
    export default class Slider extends Component {
      render() {
        return (
          <ImageSlider
            loop
            autoPlayWithInterval={3000}
            images={this.props.dataSource}
            customSlide={({ index, item, style, width }) => (
              <View key={index} style={[style, styles.customSlide]}>
                <Image source={{ uri: item }} style={styles.customImage} />
              </View>
            )}
          />
        );
      }
    }
    
    const styles = StyleSheet.create({
      customImage: {
        height: 180,
        marginRight: 20,
        marginLeft: 20,
        borderWidth: 1,
        borderRadius: 10,
        marginTop: 8,
      },
      customSlide: {
        backgroundColor: '#eee',
      },
    });
    

    您可以将它添加到您的项目中,并在需要的任何地方使用它,如下所示:

    import Slider from '../component/slider';
    export default class App extends Component {
      constructor(props) {
        super(props);
    
    this.state = {
      images: [
        'https://placeimg.com/640/480/nature',
        'https://placeimg.com/640/480/tech',
        'https://placeimg.com/640/480/animals',
        'https://placeimg.com/640/480/tech',
      ],
    }
    
    
     render() {
        return (
        <View style={{flex: 1, backgroundColor: '#eee'}}>
                    <Slider dataSource={this.state.images} />
                  </View>
    );
    }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2023-01-17
      • 2020-03-18
      • 2018-05-05
      • 2019-09-27
      • 2020-08-19
      • 2019-01-27
      • 2016-09-02
      相关资源
      最近更新 更多