Swiper.js 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. /*
  2. * @param:
  3. * autoPlay: 是否自动播放;
  4. * loop: 是否循环,无缝滚动
  5. * ifShowMiddle: 轮播图是否从中间的索引开始
  6. * @todo: 首页轮播图和主题适用
  7. */
  8. import React, { Component } from "react";
  9. import {
  10. StyleSheet,
  11. View,
  12. Image
  13. } from "react-native";
  14. import Dimensions from '../utils/dimensions';
  15. import Swiper from "react-native-swiper";
  16. const dotRegular = <View style={{ borderColor: '#fff', borderWidth: 2, width: 8, height: 8, borderRadius: 4, marginLeft: 5, marginRight: 5, marginBottom: -20, }} />;
  17. const dotActive = <View style={{ backgroundColor: '#fff', width: 8, height: 8, borderRadius: 4, marginLeft: 5, marginRight: 5, marginBottom: -20, }} />;
  18. export default class Swipers extends Component {
  19. render() {
  20. console.log(this.props)
  21. return (
  22. <Swiper
  23. style={styles.wrapper}
  24. horizontal={true}
  25. autoplayTimeout={5}
  26. autoplay={this.props.autoplay}
  27. // loop={this.props.loop}
  28. loop={true}
  29. index={this.props.ifShowMiddle ? 1 : 0}
  30. activeDotColor="#fff"
  31. showsPagination={true}
  32. dot={dotRegular}
  33. activeDot={dotActive}
  34. >
  35. {
  36. this.props.data.map((item, index) => {
  37. return (
  38. <View style={styles.slide} key={index}>
  39. <Image
  40. source={{
  41. uri: item.boothContent
  42. }}
  43. style={styles.img}
  44. />
  45. </View>
  46. )
  47. })
  48. }
  49. </Swiper>
  50. );
  51. }
  52. }
  53. const styles = StyleSheet.create({
  54. wrapper: {
  55. // flex: 1,
  56. },
  57. slide: {
  58. width: Dimensions.getWidth(352),
  59. height: Dimensions.getHeight(153),
  60. marginHorizontal: Dimensions.getDp(3),
  61. zIndex: 1
  62. },
  63. img: {
  64. width: Dimensions.getWidth(352),
  65. height: Dimensions.getHeight(153),
  66. borderRadius: Dimensions.getDp(10),
  67. zIndex: 1
  68. }
  69. });