• 初学:react-native 轮播图


    参考资料:http://reactscript.com/react-native-card-carousel-component/

    import React, {Component} from 'react';
    import {
    StyleSheet,
    Text,
    Image,
    View
    } from 'react-native';
    import CarouselCard from '../carouselCard/Card';
    import Carousel, {Pagination} from 'react-native-snap-carousel';

    // ES6生成组件 (推荐)
    export default class MyCarouselCard extends React.Component {
    constructor(props) {
    super(props);
    this.state = {
    itemArr: [
    require('../images/sowingone.png'),
    require('../images/sowingtwo.png'),
    require('../images/sowingthree.png')
    ]

    }
    }
    _renderItem({item, index}) {
    return <MySlideComponent data={item}/>
    }
    get pagination() {
    const {itemArr, activeSlide} = this.state;
    return (
    <Pagination
    dotsLength={this.state.itemArr.length}
    activeDotIndex={activeSlide}
    containerStyle={{backgroundColor: 'rgba(0, 0, 0, 0.75)'}}
    dotStyle={{
    30,
    height: 30,
    borderRadius: 10,
    marginHorizontal: 8,
    backgroundColor: 'red'
    }}
    inactiveDotStyle={{
    30,
    height: 30,
    borderRadius: 10,
    marginHorizontal: 8,
    backgroundColor: '#000'
    }}
    inactiveDotOpacity={0.4}
    inactiveDotScale={0.6}
    />
    );
    }
    render() {
    return (
    <View style={styles.cont}>
    <View style={styles.container}>
    <CarouselCard
    width={596}
    height={403}
    backgroundColor='red'
    autoplay
    interval={4000}
    data={this.state.itemArr}
    onPress={item => {
    }}
    contentRender={item => <Image source={item} style={{ 596, height: 403}}/> }
    />
    </View>
    <View style={styles.cont1}>
    <Carousel
    itemWidth={500}
    itemHeight={300}
    windowSize={10}
    data={this.state.itemArr}
    renderItem={this._renderItem}
    onSnapToItem={(item) => this.setState({activeSlide: item})}
    />
    {this.pagination}
    </View>
    </View>


    )
    }
    }

    const styles = StyleSheet.create({
    container: {
    flex:4,
    980,
    height:450,
    backgroundColor: 'blue'
    },
    cont: {
    flex:1,
    flexDirection:"column",
    1000,
    height:550,
    borderWidth: 2
    },
    cont1: {
    flex:1
    },
    item: {
    700,
    height: 100
    }
    });

  • 相关阅读:
    ubuntu安装软件失败
    阶乘函数 注意事项
    汇编退出
    vim比较文件
    汇编调试
    Redis
    记录一次ajax使用
    oracle11g导出dmp文件时不能导出空表,导致缺表
    将小数点后的0去掉
    redis
  • 原文地址:https://www.cnblogs.com/candyzhmm/p/9097370.html
Copyright © 2020-2023  润新知