react-native - 在 react-native-snap-carousel 上滑动未按预期工作
问题描述
我正在尝试使用 react-native-snap-carousel 但是,滑动效果没有按预期工作 - 通常很难左右滑动,它需要用户更加努力地滑动才能移动到另一张图片(如图所示下方链接)。
React Native Snap Carousel 的滑动问题
我找不到任何记录在案的解决方案,但我找到了一种可能的道具 - swipeThreshold。我尝试了各种价值,但问题仍然存在。
有谁知道这个问题的解决方案?
解决方案
我建议你使用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>
);
}
}
推荐阅读
- javascript - 为什么当我在同一个目录或父目录中时,“require”的行为会有所不同?
- apache-spark - Spark SQL 窗口超过两个指定时间边界之间的间隔 - 3 小时到 2 小时前
- cassandra - NiFi:将流文件均匀地路由到不同的处理器
- java - 有没有办法通过批处理设置库路径?
- grafana - 使用 PromQL 查询多个应用程序的正常运行时间聚合
- ios - 我获取的数据只显示一个数据而不是显示两个(Firebase,Swift)
- aframe - A-Frame v.0.9.x 动画暂停相机
- ios - iOS - 更改 UICollectionView 布局以填充行而不是列
- python - 如何修复 Python 中的“无效语法”错误?
- c# - 如何为 MVC Razor .NET Core 请求实现 HTML 加载器?