1.0.0 • Published 7 years ago

nuke-tab-slider v1.0.0

Weekly downloads
83
License
-
Repository
gitlab
Last release
7 years ago

tabSlider 1.0.0

重构了原有tabSlider的底层实现,自定义程度更高。

综述

TabSlider: 横滑交互组件

API说明

属性

名称类型默认值描述是否必填
tabListArraynull内容列表,一个item对应一个tab
itemWidthListArraynull每一个头部tab item的宽度,用以计算切换时滚动的距离
tabStyleObjectnull头部tab的样式,scrollview父容器的样式
tabInnerStyleObjectnull头部tab内容的样式,scrollview的样式
tabFocusStyleObjectnull选中tab item的样式,使用了该样式时,会增加选中tab的动画
renderTabItemFunctionnull渲染每一个tab item的方法
renderPageFunctionnull渲染每一个tab对应主体内容的方法
renderNavFunctionnull渲染每一个tab nav的方法,对应着头条的下拉展示更多
renderLoadingFunctionnull作用于非当前页,用于渲染loading提示
tabClickCallbackFunctionnull点击头部tab或者切换列表内容时的回调函数
pageTopNumber取tabStyle或者tabInnerStyle的高度tab内容距离头部的高度
sidesDisablePanBooleanfalse第一帧禁止往左滑动,最后一帧禁止往右滑动
activenumberfalse默认初始化的tab
navTopboolfalsetab nav在头部还是在底
widthnumber750tab渲染宽度,默认全屏
heightnumber全屏tab渲染高度,默认包含tab nav全屏

事件

名称类型默认值描述是否必填
onChangeFunctionnull点击头部tab或者切换列表内容时的回调函数

方法

this.refs.TabSlider.slideTo(2)

  • 用于从外部主动切换到对应的tab项

布局说明

tabSlider的布局是使用绝对定位布局,大致的布局方式如下图。所以,使用该组件时,需要在tabbar的外层有足够宽高让其撑满,建议tabbar的外层容器使用绝对定位布局。

布局说明

使用方法

tabSlider 1.0.0 采用了类似ListView renderRow的渲染方法。对tab头、tab体的渲染都需要使用对应的渲染方法。具体来说,如果需要例子中效果,需要实现几步:

1、定义tabItem,既demo中的热门、黑板报等导航内容。eg:

/** @jsx createElement */
'use strict';
import { createElement, Component } from 'rax';
import View from 'nuke-view';
import Text from 'nuke-text';
import Image from 'nuke-image';
import styles from './demo.styles';

class TabItem extends Component {
  render() {
    const { itemData, index, currentIndex, isRenderCurrent } = this.props;
    if (itemData) {
      return (
        <View
          style={
            isRenderCurrent && index === currentIndex ? (
              [styles.tabItem, styles.tabItemCur]
            ) : (
              styles.tabItem
            )
          }
        >
          {itemData.name ? (
            <View style={styles.tabTitle}>
              <Text
                style={
                  isRenderCurrent && index === currentIndex ? (
                    [styles.tabText, styles.tabTextCur]
                  ) : (
                    styles.tabText
                  )
                }
              >
                {itemData.name}
              </Text>
            </View>
          ) : null}
        </View>
      );
    }
    return null;
  }
}

export default TabItem;

2、 tabItem的传入数据包括 itemData, index, currentIndex, isRenderCurrent。

其中itemData是开发者自己定义的导航list数据如下,根据渲染方法的不同。数据格式和内容均是可以自定义的:

tabList: [
    {
      name: '热门',
      sceneId: '1',
      tabType: '1'
    },
    ...
  ],

3、定义renderPage,渲染tab的contain部分,以下是一个典型的tabPage。

class TabPage extends Component {

  render() {
    const { index } = this.props;
    return (
      <ListView
        id={`list${index}`}
        ref={`list${index}`}
        renderRow={this.renderRow}
        dataSource={this.qdList}
      />
    );
  }

  renderRow = (itemData, i) => {
    const { index } = this.props;
    return <Item itemData={itemData} index={i} pageIndex={index} />;
  };
}

4、可选定义切换时的动画组件 renderLoading

class TabLoading extends Component {
  render() {
    return (
      <View style={styles.pageLoading} data-ignore="true">
        <Image
          style={styles.loadingImg}
          source={{
            uri: '//gw.alicdn.com/tfs/TB1x9J7PXXXXXcHXVXXXXXXXXXX-140-80.gif'
          }}
        />
      </View>
    );
  }
}

5、 其他API请参考上面的API文档和使用demo。

PS:如果依旧无法实现,可使用脚手架打开场景场景市场,查看tabSlider的使用源代码。

1.0.0

7 years ago

0.3.2

7 years ago

0.3.1

7 years ago

0.3.0

7 years ago

0.2.0

7 years ago

0.1.14

7 years ago

0.1.13

7 years ago

0.1.12

7 years ago

0.1.11

7 years ago

0.1.10

7 years ago

0.1.9

7 years ago

0.1.8

7 years ago

0.1.7

7 years ago

0.1.6

7 years ago

0.1.5

7 years ago

0.1.4

7 years ago

0.1.3

7 years ago

0.1.2

7 years ago

0.1.1

7 years ago

0.1.0

8 years ago

0.0.33

8 years ago

0.0.32

8 years ago

0.0.31

8 years ago

0.0.30

8 years ago

0.0.29

8 years ago

0.0.28

8 years ago

0.0.27

8 years ago

0.0.26

8 years ago

0.0.25

8 years ago

0.0.24

8 years ago

0.0.23

8 years ago

0.0.22

8 years ago

0.0.21

8 years ago

0.0.20

8 years ago

0.0.19

8 years ago

0.0.18

8 years ago

0.0.17

8 years ago

0.0.16

8 years ago

0.0.15

8 years ago

0.0.14

8 years ago

0.0.13

8 years ago

0.0.12

8 years ago

0.0.11

8 years ago

0.0.10

8 years ago

0.0.9

8 years ago

0.0.8

8 years ago

0.0.7

8 years ago

0.0.6

8 years ago

0.0.5

8 years ago

0.0.4

8 years ago

0.0.3

8 years ago

0.0.1

8 years ago