RN 轮播

Swiper轮播图组件

1、功能说明

banner图标或者文字轮播

2、组件效果

3、代码演示

import React, { Component } from "react";
import {
    StyleSheet,
    Text,
    ScrollView,
    Image,
    Alert,
    TextInput,
    View,
    TouchableOpacity,
    TouchableHighlight,
    Dimensions
} from "react-native";
import { Radio, CheckBox, DatePicker, Swiper } from "@/rn-design";
import PropTypes from "prop-types";
const styles = StyleSheet.create({
    flex: {
        flex: 1,
        marginTop: 65
    },
    image: {
        width: Dimensions.get("window").width,
        height: 80
    },
    item: {
        height: 100,
        justifyContent: "center",
        alignItems: "center"
    },
    one: {
        backgroundColor: "#0ca"
    },
    two: {
        backgroundColor: "#0cc"
    },
    three: {
        backgroundColor: "#0ac"
    },
    paginationStyle: {
        flexDirection: "row",
        alignItems: "center",
        justifyContent: "center",
        bottom: 10
    }
});

class Demo extends Component {
    constructor(props) {
        super(props);
        this.state = {
            images: [
                {
                    uri: "http://img.58cdn.com.cn/images/car/activitypic/reactnative/pic1.jpg"
                },
                {
                    uri: "http://img.58cdn.com.cn/images/car/activitypic/reactnative/pic2.jpg"
                }
            ]
        };
    }
    static defaultProps = {
        count: ["one", "two", "three"]
    };

    render() {
        //图片轮播
        const images = this.state.images.map((source, index) => (
            <View key={index} style={styles.image}>
                <Image style={styles.image} source={source} resizeMode={"stretch"} />
            </View>
        ));
        //普通轮播
        const items = this.props.count.map((name, index) => (
            <View key={index} style={[styles.item, styles[name]]}>
                <Text>{name}</Text>
            </View>
        ));
        return (
            <ScrollView>
                <View style={styles.flex}>
                    <Swiper
                        width={Dimensions.get("window").width}
                        height={80}
                        autoplay={true}
                        horizontal={true}
                        loop={true}
                        index={1}
                        paginationStyle={styles.paginationStyle}
                        showsPagination={true}
                        dotColor="#000"
                        dotStyle={{ width: 5, height: 5, backgroundColor: "red" }}
                        autoplayTimeout={3}>
                        {images}
                    </Swiper>
                </View>
            </ScrollView>
        );
    }
}

export default Demo;

4、API

参数说明类型默认值
width宽度,默认flex:1全屏如果不写宽高可能会导致内容闪屏一下number-
height高度,默认flex:1全屏number-
index初始进入页面标识为0的页面number0
style设置轮播样式style-
horizontal设置轮播方向,默认水平方向booltrue
loop是否循环播放booltrue
autoPlay是否自动轮播boolfalse
autoplayTimeout设置轮播间隔number2.5
onIndexChanged当用户拖拽时更新索引调用func(index)=>null
showsPagination是否显示小圆点booltrue
paginationStyle设置轮播原点的整体样式{flexDirection: “row”,alignItems: “center”,justifyContent: “center”,bottom: 10}style-
dotColor设置未选中小圆点颜色string#fff
dotStyle设置未选中小圆点样式{ width: 10, height: 2, backgroundColor: “red” }注意:如果dotColor和dotStyle同时存在,dotColor会覆盖dotStyle里面的backgroundColorstyle-
activeDotColor设置选中小圆点颜色string#ff552e
activeDotStyle设置选中小圆点样式(同上)style-

源码地址
https://github.com/gongchenghuigch/rn-design/tree/master/swiper

  • 2
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值