Swiper.js 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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. index={this.props.ifShowMiddle ? 1 : 0}
  29. activeDotColor="#fff"
  30. showsPagination={true}
  31. dot={dotRegular}
  32. activeDot={dotActive}
  33. >
  34. {
  35. this.props.data.map((item, index) => {
  36. return (
  37. <View style={styles.slide} key={index}>
  38. <Image
  39. source={{
  40. uri: item.boothContent
  41. }}
  42. style={styles.img}
  43. />
  44. </View>
  45. )
  46. })
  47. }
  48. </Swiper>
  49. );
  50. }
  51. }
  52. const styles = StyleSheet.create({
  53. wrapper: {
  54. // flex: 1,
  55. },
  56. slide: {
  57. width: Dimensions.getDp(352),
  58. height: Dimensions.getDp(153),
  59. marginHorizontal: Dimensions.getDp(3),
  60. zIndex: 1
  61. },
  62. img: {
  63. width: Dimensions.getDp(352),
  64. height: Dimensions.getDp(153),
  65. borderRadius: Dimensions.getDp(10),
  66. zIndex: 1
  67. }
  68. });