react native 中使用swiper

1.下载依赖

cnpm install react-native-swiper --save 

2.在组件中使用

import React, { Component } from 'react';
import { StyleSheet, View,Dimensions,Image} from 'react-native';
import Swiper from 'react-native-swiper';
export default class SideItem extends Component {
    render(){
        return(
            <View style={styles.container}>
                <Swiper
                    style={styles.swiper}
                    height={220}
                    horizontal={true}
                    autoplay={true} 
                    paginationStyle={{bottom: 20}}
                    showsButtons={false}>
                    <Image source={require('../assets/images/1.png')} style={styles.img}/>
                    <Image source={require('../assets/images/2.png')} style={styles.img}/>
                    <Image source={require('../assets/images/3.png')} style={styles.img}/>
                </Swiper>
            </View>
        )
    }
}

const styles = StyleSheet.create({
    container: {
        flex: 1
    },
    swiper: {},
    img: {
         Dimensions.width,
        height: 200,
    }
});

3.运行run-Android

原文地址:https://www.cnblogs.com/ldlx-mars/p/9456438.html