react-native-swiper使用时候的小坑
react-native版本:0.61.1
react-native-swiper版本:1.5.14
当时第一次使用时候直接粘贴的别人博客的教程代码,只修改了swiper里面的元素,结果发现不能切换,点击下一张按钮,小圆点会跟着切换,但是元素却没有切换,一直保持在最后一张,折腾了半天,发现不能给Swiper元素的style里加width属性,高宽是直接被当做Swiper的属性赋予的
1 <Swiper 2 style={styles.wrapper} 3 showsButtons={true} 4 removeClippedSubviews={false} //这个很主要啊,解决白屏问题 5 autoplay={true} 6 horizontal ={true} 7 autoplayTimeout = {4} 8 loop = {true} 9 > 10 <Image source={{uri:'http://p1.music.126.net/DBN-pGDTN2_LPDnyCYonMA==/109951164474447712.jpg'}} style={styles.bannerImg} /> 11 <Image source={{uri:'http://p1.music.126.net/5lcR4NT8Mu-CBQnpBTqn7w==/109951164474482743.jpg'}} style={styles.bannerImg} /> 12 <Image source={{uri:'http://p1.music.126.net/krcK1qrj6fdcZ28DkXJlWw==/109951164474509253.jpg'}} style={styles.bannerImg} /> 13 <Image source={{uri:'http://p1.music.126.net/YANzhLtF9LpgF17vuUHJ7g==/109951164475251428.jpg'}} style={styles.bannerImg} /> 14 </Swiper>
wrapper:{ width:width * 0.9,//这行不能加 height:200, backgroundColor:'red', zIndex:10000, overflow:'scroll' }, bannerImg:{ width:width * 0.9, height:200, }