IndexBanner.js 2.96 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 activeOpacity={1} onPress={() => toPage(this.props.navigation, v)} key={i}>
                                <Image
                                    style={styles.carousel} resizeMode="stretch"
                                    defaultSource={defaultBanner}
                                    source={v.pictureUrl}
                                />
                            </TouchableOpacity>,
                        )
                    }
                </Carousel>
            </View>
        );
    }
}

// 跳转至某页面,类型+ID
export function toPage(navigation, v) {
    if (v.type == '2') {
        navigation.navigate('ChooseActivityAttribute', { name: 'ChooseActivityAttribute', title: '平安地铁先锋行', defultValue: global.user.partyName ? global.user.partyName : '' });
    } else if (v.type == '3') {
        navigation.navigate('chooseVolunteerActivity', { name: 'chooseVolunteerActivity', title: '上海市平安志愿者', defultValue: global.user.volunteerName ? global.user.volunteerName : '' });
    }
}

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,
    },
});