p;
//求出当前页数
let pageIndex = Math.floor(offsetX / ScreenWidth);
//更改状态机
this.setState({ currentPage: pageIndex });
}
/**3.页面指针实现 */
_renderAllIndicator() {
let indicatorArr = [];
let style;
let imgsArr = ImageData.data;
for (let i = 0; i < imgsArr.length; i++) {
//判断
style = (i==this.state.currentPage)?{color:'orange'}:{color:'white'};
indicatorArr.push(
<Text key={i} style={[{fontSize:30},style]}>
?
</Text>
);
}
return indicatorArr;
}
/**4.通过定时器实现自动播放轮播图 */
_startTimer(){
let scrollView = this.refs.scrollView;
this.timer = setInterval(
()=>{console.log('开启定时器');
let imageCount = ImageData.data.length;
//4.1 设置圆点
let activePage = 0;
//4.2判断
if(this.state.currentPage>=imageCount+1){
activePage = 0;
}else{
activePage = this.state.currentPage+1;
}
//4.3 更新状态机
this.setState({currentPage:activePage});
//4.4 让scrollview 滚动起来
let offsetX = activePage * ScreenWidth;
&nb |