1.0.2 • Published 6 years ago

react-s-scrollable-tab-view v1.0.2

Weekly downloads
6
License
ISC
Repository
github
Last release
6 years ago

react-s-scrollable-tab-view

这是一个基于JavaScript原生实现的react组件,实现了滚动tabbar,滑动切换页面

npm.io

安装

npm install react-s-scrollable-tab-view

使用

import ScrollableTabBarView, {ScrollableTabBar, DefaultTabBar} from 'components/ScrollableTabBarView/ScrollableTabBarView';

export default class Demo extends PureComponent {

    render() {
        return (
            <ScrollableTabBarView
                handleTab={this.handleTab}
                renderTabBar={() => <ScrollableTabBar/>}>
                <div tabLabel='title1' >content1</div>
                <div tabLabel='title2' >content2</div>
                <div tabLabel='title3' >content3</div>
                <div tabLabel='title4' >content4</div>
                <div tabLabel='title5' >content5</div>
                <div tabLabel='title6' >content6</div>
            </ScrollableTabBarView>
        )
    }
}

介绍

组件自带两种tabbar:
1.ScrollableTabBar
2.DefaultTabBar
同学们可自行选择合适的tabbar,也可自定义tabbar

属性

属性值类型默认值描述
initItemIndexnumber0初始化显示页面的下标
underlineStyleobjecttabbar下划线样式
textStyleobjecttabbar文字样式
activeTextColorstring#333tabbar选中时文字高亮颜色
renderTabBaranyDefaultTabBar自定义tabbar
handleTabfunc页面切换回调

内置组件(Carousel, ScrollView)

1.Carousel

import {Carousel} from 'components/ScrollableTabBarView/ScrollableTabBarView';
const windows = {
	width: window.innerWidth,
	height: window.innerHeight
};
export default class DemoC extends PureComponent {

    render() {
        return (
            <Carousel className={styles.hcarousel}>
                <div className={styles.carouselItem} style={{width: windows.width, backgroundColor: '#000'}}/>
                <div className={styles.carouselItem} style={{width: windows.width, backgroundColor: 'red'}}/>
                <div className={styles.carouselItem} style={{width: windows.width, backgroundColor: 'yellow'}}/>
            </Carousel>
        )
    }
}

npm.io

属性

属性值类型默认值描述
initItemnumber0初始化显示页面的下标
loopbooltrue是否循环滚动
autobooltrue是否自动滚动
autoplayTimenumber3000自动滚动间隔
indicatorbooltrue是否显示指示器
indicatorStyleobject默认样式指示器样式
indicatorDefany默认自定义指示器布局
indicatorActiveany默认自定义选中指示器布局
bounceboolfalse切换页面是否具有回弹效果
pageScrollEndfunc页面切换完成回调
itemClsstringitem class
itemStyleobjectitem 样式

2.ScrollView

import {ScrollView} from 'components/ScrollableTabBarView/ScrollableTabBarView';
const windows = {
	width: window.innerWidth,
	height: window.innerHeight
};
export default class DemoS extends PureComponent {

    render() {
        return (
            <ScrollView>
                <div className={styles.carouselItem} style={{backgroundColor: '#000'}}/>
                <div className={styles.carouselItem} style={{backgroundColor: 'red'}}/>
                <div className={styles.carouselItem} style={{backgroundColor: 'yellow'}}/>
                <div className={styles.carouselItem} style={{backgroundColor: '#000'}}/>
                <div className={styles.carouselItem} style={{backgroundColor: 'red'}}/>
                <div className={styles.carouselItem} style={{backgroundColor: 'yellow'}}/>
                <div className={styles.carouselItem} style={{backgroundColor: '#000'}}/>
                <div className={styles.carouselItem} style={{backgroundColor: 'red'}}/>
                <div className={styles.carouselItem} style={{backgroundColor: 'yellow'}}/>
            </ScrollView>
        )
    }
}

npm.io

属性

属性值类型默认值描述
startYnumber0纵向初始化位置
startXnumber0横向初始化位置
horizontalboolfalse是否横向显示布局,默认纵向显示
bounceboolfalse滑动至顶/底部是否具有回弹效果
onScrollfunc滑动回调
onScrollEndfunc滑动结束回调