react-native-swipe与滑动组件共用时图片无法显示

解决办法是设置setTimeout

componentDidMount() {

setTimeout(()=>{

this.setState({

swiperShow:true

});

},0)

}

 

{

this.state.swiperShow &&<View>

<Swiper style={styles.wrapper}

height={150}

width={width}

// showsButtons={true}

autoplay={true}

showsPagination={true}

horizontal={true}

loop={true}

autoplayTimeout={2}

dotStyle={styles.dotStyle}

activeDotStyle={styles.activeDotStyle}

removeClippedSubviews={false}

paginationStyle={{ bottom: 5 }}

>

<TouchableOpacity style={styles.slide}>

<Image source={require('./images/bg1.png')} style={styles.img} />

</TouchableOpacity>

<TouchableOpacity style={styles.slide}>

<Image source={require('./images/bg2.png')} style={styles.img} />

</TouchableOpacity>

<TouchableOpacity style={styles.slide}>

<Image source={require('./images/bg3.png')} style={styles.img} />

</TouchableOpacity>

</Swiper>

</View>

}