1.1.0 • Published 7 years ago

react-native-sf-tablist v1.1.0

Weekly downloads
-
License
ISC
Repository
-
Last release
7 years ago

react-native-sf-tablist

支持多页数据切换,上拉刷新

支持tab上方悬浮

支持数据缓存,在切换时无卡顿感

支持空数据的页面显示

支持tab展开选择

安装

  • npm install react-native-sf-tablist

Props

parametertyperequireddescriptiondefault
tabFloatTopnumberyestabbar距离屏幕顶端的高度(一般为header的高度)0
headerComponentanyno头部控件null
barHeightnumbernobar的高度40
barWidthnumberno每个bar的宽度50
barTitlesarrayyesbar 标题数组['全部','热门', '附近', '精选','热销']
emptyComponentanyno空数据时显示组件null
emptyDefaultTitlestringnoemptyComponent为空时默认空数据标题'没有数据'
emptyDefaultColorstringnoemptyComponent为空时默认空数据颜色'rgba(200,200,200,1)'
emptyDefaultFontSizenumbernoemptyComponent为空时默认提示字体大小15
barContentStyleanyno整行bar的样式设置(如背景颜色,边框等)borderBottomWidth:1,borderBottomColor:'rgba(240,240,240,1)',backgroundColor: 'white',
barTextStyleanynobar标题样式(颜色、大小等)color:'#5a5a5a',fontSize:15
barTextSelectStyleanynobar标题选中样式(颜色、大小等)color:'black',fontSize:15
barTriangleColorstringnobar倒三角颜色(bar可多选时设置)#c8c8c8
barTriangleSizenumbernobar倒三角大小(bar可多选时设置)6
barItemTextStyleanynobar展开子项的标题样式color:'#333333',fontSize:15,marginLeft:20
barItemFooterStyleanynobar展开列表底部样式height:10,borderBottomWidth:1,borderBottomColor:'rgba(200,200,200,1)'
barItemSeparatorStyleanynobar展开子项的分隔样式height:1,backgroundColor:'rgba(240,240,240,1)'
barCursorColorstringnobar展开子项的分隔样式height:1,backgroundColor:'rgba(240,240,240,1)'
barCursorHeightnumbernobar底部游标的颜色'rgba(258,88,28,1)'
onEndShouldRatenumbernobar底部游标的高度1
onReqDatafunc(index,itemIndex)yes需要请求数据时自动调用null
onBeginRefreshFooterfuncno上拉刷新回调null
onListScrollfuncno列表滚动回调null
onClickBarfunc(index,itemIndex)no点击bar的回调null

Methods

MethodsParamsParam TypesdescriptionExample
setDatadatanullonReqData调用中,数据请求回调里设置,即第一页的数据
addDatadatanull上拉刷新时需要增加数据时调用
endRefreshFooternullnull结束上拉刷新(数据更新成功后调用)
endRefreshNomorenullnull结束上拉刷新,没有更多数据状态,再次加载不会调用onBeginRefreshFooter(数据更新成功后调用)

例子

import React, {Component} from 'react';
import {Platform, StyleSheet, Text, View,TouchableHighlight,Image,Dimensions} from 'react-native';
import SFTabList from "react-native-sf-tablist"
import SFNet from "react-native-sf-net"
const {width,height} = Dimensions.get('window')
export default class App extends Component {
    constructor(props) {
        super(props);
        this.state = {

        }
    }
    componentWillMount(){
        SFNet.config('https://api.food.d2.sf-soft.com/client/');

    }
    renderItems = ({item, index}) => {
        return (
            <View style={{
                padding:20
            }}>
                <Text>
                    {item.shop_name}
                </Text>
                <Image source={{uri:item.shop_banner}} style={{
                    width:width-40,
                    height:100,
                    marginTop:10
                }}>

                </Image>
            </View>
        )
    }
    renderSepara = () => {
        return (
            <View style={{
                height: 10
            }}>

            </View>
        )
    }
    renderHeader = () => {
        return (
            <View style={{
                height:150,
                backgroundColor:'red'
            }}>

            </View>
        )
    }
    clickTest = () => {
        this.tabList.addData(this.state.ds[1]);
    }
    clickBar = (index) => {
        //this.tabList.setData(this.state.ds[index])
    }
    onReqData = (index) => {
        var params = {
            token: '5A1d2sKw2oh4Ewd8SNPyz2ShmcDgUKrg',
            page: 1,
            shop_type: 57,
            type: index,
            la: '121.587767',
            lo: '38.913846',
        }
        SFNet.post('shop/list',params,(ret)=>{
            console.log(ret);
            this.tabList.setData(ret.data);
        },(err)=>{
            console.log(error)
        });

    }
    onBeginRefreshFooter = () => {
        // this.tabList.addData(this.state.ds[1]);
        this.tabList.endRefreshNomore()
    }
    render() {
        return (
            <View style={styles.container}>
                <View style={{
                    height:50,
                    backgroundColor:'black'
                }}>

                </View>
                <SFTabList
                    ref={(ref)=>{this.tabList = ref}}
                    barTitles={[['全部','哈哈'], '附近', '精选','热销']}
                    barWidth={width/4}
                    barHeight={50}
                    renderItem={this.renderItems}
                    headerComponent={this.renderHeader}
                    ItemSeparatorComponent={this.renderSepara}
                    onReqData={this.onReqData}
                    onBeginRefreshFooter={this.onBeginRefreshFooter}
                    onClickBar={this.clickBar}
                    showsVerticalScrollIndicator={false}
                    tabFloatTop={50}
                >

                </SFTabList>
            </View>
        );
    }
}
1.1.0

7 years ago

1.0.9

7 years ago

1.0.8

7 years ago

1.0.7

7 years ago

1.0.6

7 years ago

1.0.5

7 years ago

1.0.4

7 years ago

1.0.3

7 years ago

1.0.2

7 years ago

1.0.1

7 years ago

1.0.0

7 years ago