IndexBanner.js 2.8 KB
/**
 * Created by mac on 2017/11/28.
 */
import React, {Component} from "react";
import {Image, StyleSheet, Text, TouchableOpacity, View,TouchableWithoutFeedback} from "react-native";
import {height, width} from "../../utils/getSize";
import Carousel from "react-native-looped-carousel";
const defaultBanner = require('../../img/banner.png')

export default class IndexBanner extends Component {
    constructor() {
        super();
    }

    // 渲染顶部跑马灯
    render() {
        if (this.props.data.length === 0) {
            return (
                <View />
            );
        }
        return (
            <View>
                <Carousel
                    style={styles.carousel}
                    activeDotColor="white"
                    autoplay
                    bullets
                    delay={5000}
                    bulletsContainerStyle={styles.bulletsContainer}
                    bulletStyle={styles.bullet}
                    chosenBulletStyle={styles.chosenBullet}
                >
                    {
                        this.props.data.map((v, i) =>
                            <TouchableOpacity key={v.id} activeOpacity={1} >
                                <Image
                                    style={styles.carousel} resizeMode="stretch"
                                    defaultSource={defaultBanner}
                                    source={v.pictureUrl}
                                />
                            </TouchableOpacity>,
                        )
                    }
                </Carousel>
            </View>
        );
    }
}

// 跳转至某页面,类型+ID
export function toPage(navigation, type) {
    if (type === 'CREDIT_PLATFORM') {
        navigation.navigate('CreditPlatform', {name: 'CreditPlatform'});
    } else if (type === 'CREDIT_AUTH') {
        navigation.navigate('CreditAuth', {name: 'CreditAuth'});
    } else if (type === 'CREDIT_INFO') {
        navigation.navigate('CreditInfo', {name: 'CreditInfo'});
    }
}

const styles = StyleSheet.create({
    carousel: {
        width,
        height: width * 0.4,
    },
    bulletsContainer: {
        position: 'absolute',
        top: 18,

    },
    bullet: {
        height: 6,
        width: 6,
        margin: 3,
        borderRadius: 3,
        borderWidth: 0,
        backgroundColor: '#999',
    },
    chosenBullet: {
        height: 6,
        width: 6,
        margin: 3,
        borderRadius: 3,
        borderWidth: 0,
        backgroundColor: 'white',
    },
    titleContainer: {
        position: 'absolute',
        bottom: 0,
        left: 0,
        right: 0,
        height: 30,
        paddingTop: 6,
        paddingRight: 10,
        paddingLeft: 10,
        backgroundColor: 'rgba(0,0,0,0.3)',
    },
    title: {
        color: '#ffffff',
        fontSize: 12,
    },
});