• RN无限轮播以及ScrollView的大小调节问题


    如果你的ScrollView的大小是全屏,height不能用,这种情况需要给ScrollView添加一个容器View,然后调节容器View的大小

    无限轮播这里我使用的是一个第三方的插件react-native-swiper

    具体可以参考https://www.npmjs.com/package/react-native-swiper

    效果图

    使用:

    $ npm i react-native-swiper --save
    

     代码:

    import React, {Component} from 'react';
    import {
        AppRegistry,
        StyleSheet,
        Text,
        View, TouchableOpacity, Image, ScrollView
    } from 'react-native';
    import Swiper from 'react-native-swiper'
    var Dimensions = require('Dimensions');
    var {width,height} = Dimensions.get("window");//第一种写法
    export default class MyApp extends Component {
    
       _onIndexChanged(index){
           // alert(index)
       }
        render() {
            return (
               <View style={styles.wrapper}>
    
                   <View style={styles.swiperView}>
                       <Swiper style={styles.swiperStyle}
                               showsButtons={false}//左右两边的< >箭头是否显示
                               horizontal={true}//是否水平滚动,默认true
                               loop={true}//是否轮播,默认true
                               index={1}//当前默认第几页,默认0
                               onIndexChanged={this._onIndexChanged}//当前滚动到第几页的事件
                               autoplayTimeout = {1}  //轮播的时间
                               autoplay={true}//是否自动轮播,默认false
                               autoplayDirection={true}//是否反向轮播,默认true 左->右
                               showsPagination = {true}  //是否显示dot
                               dot = {<View style={{8,height:8,backgroundColor:'red',marginRight: 5}}/>} //指定dot
                               paginationStyle = {{bottom: 10}} //dot的位置
                               activeDot = {<View style={{8,height:8,backgroundColor:'yellow',marginRight: 5}} />} //选中的dot的样式
    
                       >
                           <View style={styles.slide1} >
                               <Text style={styles.text}>Hello Swiper{width}</Text>
                           </View>
                           <View style={styles.slide2} >
                               <Text style={styles.text}>Beautiful</Text>
                           </View>
                           <View style={styles.slide3}>
                               <Text style={styles.text}>And simple</Text>
                           </View>
                       </Swiper>
                   </View>
               </View>
            )
        }
    }
    
    const styles = StyleSheet.create({
        wrapper: {
           flex: 1,
           backgroundColor:"#ff0000"
    
        },
        swiperView:{
            width,
            height:200,
            backgroundColor:"#000000"
        },
        swiperStyle:{
            backgroundColor:"#00ff00"
        },
        slide1: {
            justifyContent: 'center',
            alignItems: 'center',
            backgroundColor: '#0000ff',
            flex: 1
        },
        slide2: {
            flex: 1,
            justifyContent: 'center',
            alignItems: 'center',
            backgroundColor: '#0000ff',
        },
        slide3: {
            flex: 1,
            justifyContent: 'center',
            alignItems: 'center',
            backgroundColor: '#0000ff',
        },
        text: {
            color: '#fff',
            fontSize: 30,
            fontWeight: 'bold',
        }
    });
    
  • 相关阅读:
    Netty NioEventLoop 源码解析(运行相关)
    挖矿病毒的回溯(稍后补充,原来是自己傻逼了)
    关于centos后台执行的坑
    记录编写TS的一些想法
    webstorm永久激活
    PCL学习笔记(六):ubuntu下QT配置PCL
    PCL学习笔记(二)、PCL编码风格
    PCL学习笔记(三):PCL的点类型
    PCL学习笔记(四):PCD文件格式
    PCL学习笔记(五):PCD文件的IO操作
  • 原文地址:https://www.cnblogs.com/hualuoshuijia/p/9994075.html
Copyright © 2020-2023  润新知