加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

初学:react-native 轮播图

发布时间:2020-12-15 20:29:01 所属栏目:百科 来源:网络整理
导读:参考资料: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 Carou

参考资料: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.75)‘}}
dotStyle={{
width: 30,
height: 30,
borderRadius: 10,
marginHorizontal: 8,
backgroundColor: ‘red‘
}}
inactiveDotStyle={{
width: 30,
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={{width: 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,width:980,height:450,backgroundColor: ‘blue‘ },cont: { flex:1,flexDirection:"column",width: 1000,height:550,borderWidth: 2 },cont1: { flex:1 },item: { width: 700,height: 100 }});

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读