Swiper.js 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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. return (
  21. <Swiper
  22. style={styles.wrapper}
  23. horizontal={true}
  24. autoplayTimeout={5}
  25. autoplay={this.props.autoplay}
  26. loop={this.props.loop}
  27. index={this.props.ifShowMiddle ? 1 : 0}
  28. activeDotColor="#fff"
  29. showsPagination={true}
  30. dot={dotRegular}
  31. activeDot={dotActive}
  32. >
  33. <View style={styles.slide}>
  34. <Image
  35. source={{
  36. uri:
  37. "https://ss1.bdstatic.com/70cFvXSh_Q1YnxGkpoWK1HF6hhy/it/u=1295208965,3056573814&fm=26&gp=0.jpg"
  38. }}
  39. style={styles.img}
  40. />
  41. </View>
  42. <View style={styles.slide}>
  43. <Image
  44. source={{
  45. uri:
  46. "https://ss1.bdstatic.com/70cFvXSh_Q1YnxGkpoWK1HF6hhy/it/u=1295208965,3056573814&fm=26&gp=0.jpg"
  47. }}
  48. style={styles.img}
  49. />
  50. </View>
  51. </Swiper>
  52. );
  53. }
  54. }
  55. const styles = StyleSheet.create({
  56. wrapper: {
  57. // flex: 1,
  58. },
  59. slide: {
  60. width: Dimensions.getDp(352),
  61. height: Dimensions.getDp(153),
  62. marginHorizontal: Dimensions.getDp(3),
  63. zIndex: 1
  64. },
  65. img: {
  66. width: Dimensions.getDp(352),
  67. height: Dimensions.getDp(153),
  68. borderRadius: Dimensions.getDp(10),
  69. zIndex: 1
  70. }
  71. });