RN筆記-react-native-scrollable-tab-view

scrollable-tab-view 是RN的第三方組件,使用的時(shí)候我們需要做的是用npm導(dǎo)入到項(xiàng)目的組件管理文件夾下。

安裝方法

1:終端窗口"cd 項(xiàng)目工程目錄里"
執(zhí)行命令:npm install react-native-scrollable-tab-view --save

2:安裝成功后在工程文件里引入:
[ES5語法如下,RN最新的版本已經(jīng)不可以使用]
var ScrollableTabView = require('react-native-scrollable-tab-view');
[ES6語法如下]
import 組件類命名,{類型,}from '第三方組件名'
import ScrollableTabView, { DefaultTabBar, } from 'react-native-scrollable-tab-view';

代碼實(shí)現(xiàn)
import ScrollableTabView, { DefaultTabBar, } from 'react-native-scrollable-tab-view';
var Consult = React.createClass({
  render() {
    return (
      <View style={styles.container}>
        { /*首頁導(dǎo)航條*/ }
        {this.renderNavBar()}
        <ScrollableTabView style={{backgroundColor:'white'}} tabBarUnderlineStyle={{backgroundColor: '#1fb5ec',width:width/4-40,height:2,margin:20}} tabBarActiveTextColor="#1fb5ec"
          renderTabBar={() => <DefaultTabBar/>}>
          <ConsultList
            tabLabel='教育資訊'
            classid='439'
            popToHome={(mark)=>this.pushNative(mark)}
            htmlContent={(html)=>this.pushHtml(html)}
          />
          <ConsultList
            tabLabel='通知公告'
            classid='440'
            popToHome={(mark)=>this.pushNative(mark)}
            htmlContent={(html)=>this.pushHtml(html)}
          />
          <ConsultList
            tabLabel='安全教育'
            classid='442'
            popToHome={(mark)=>this.pushNative(mark)}
            htmlContent={(html)=>this.pushHtml(html)}
          />
          <ConsultList
            tabLabel='學(xué)校新聞'
            classid='450'
            popToHome={(mark)=>this.pushNative(mark)}
            htmlContent={(html)=>this.pushHtml(html)}
          />
        </ScrollableTabView>

      </View>
    );
  },
  pushHtml(html){
    //  alert(html);
     this.props.navigator.push(
       {
         component:HtmlDetail,//要跳轉(zhuǎn)的版塊
         passProps:{'html':html}
       }
     );
  },
  // 導(dǎo)航條
  renderNavBar(){
    return(
      <View style={styles.navOutViewStyle}>
        <TouchableOpacity onPress={()=>{this.popBack()}} style={styles.leftViewStyle}>
          <Image source={{uri:'common_back'}} style={styles.navImagStyle} />
        </TouchableOpacity>
        <Text style={{color:'white', fontSize:16, fontWeight:'bold', marginTop:18}}>教育資訊</Text>
      </View>
    )
  },
  popBack(){
    this.props.navigator.pop();
  },
});

var styles = StyleSheet.create({
  navOutViewStyle: {
    height: 64,
    backgroundColor: '#1fb5ec',
    // 設(shè)置主軸方向
    flexDirection: 'row',
    // 垂直居中,設(shè)置側(cè)軸的對(duì)其方式
    alignItems: 'center',
    // 設(shè)置主軸放心居中
    justifyContent: 'center'
  },
  leftViewStyle: {
    //絕對(duì)定位
    position: 'absolute',
    left: 10,
    bottom: 13
  },
  rightViewStyle: {
    //絕對(duì)定位
    position: 'absolute',
    right: 10,
    bottom: 13
  },
  navImagStyle: {
    width: 23,
    height: 23,
  },
  topInputStyle: { // 設(shè)置輸入框
    width: width * 0.71,
    height: 31,
    backgroundColor: 'white',
    marginTop: 20,
    //設(shè)置圓角
    borderRadius: 15,
    //設(shè)置內(nèi)左邊距
    paddingLeft: 10,
    fontSize: 15
  },
  container: {
    flex: 1,
    // justifyContent: 'center', // 主軸對(duì)其方式要去掉
    // alignItems: 'center',
    backgroundColor: '#E8E8E8',
  },
  welcome: {
    fontSize: 20,
    textAlign: 'center',
    margin: 10,
  },
  instructions: {
    textAlign: 'center',
    color: '#333333',
    marginBottom: 5,
  },
});

module.exports = Consult;
效果圖
react-native-scrollable-tab-view.gif

補(bǔ)充:寫此文在于讓react-native開發(fā)者理清類似Tab分頁的代碼實(shí)現(xiàn)邏輯,< ConsultList />為自定義的分頁列表組件,代碼直接拷貝是運(yùn)行不起來的。如果不了解react-native-scrollable-tab-view,分頁可以使用<View></View>組件代替,或者參考網(wǎng)址:http://www.lxweimin.com/p/1782137a7a8a

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

推薦閱讀更多精彩內(nèi)容

  • Android 自定義View的各種姿勢(shì)1 Activity的顯示之ViewRootImpl詳解 Activity...
    passiontim閱讀 173,523評(píng)論 25 708
  • 簡(jiǎn)短說明 收錄一些好用的RN第三方組件,以方便日常的使用,大家有什么推薦的也可以跟我說,我加進(jìn)去。如有冒犯,可以聯(lián)...
    以德扶人閱讀 43,727評(píng)論 44 214
  • React Native學(xué)習(xí)<一> 認(rèn)識(shí)Recat Native 博客原文:http://www.jianshu....
    AFinalStone閱讀 2,721評(píng)論 0 12
  • 前幾天臨時(shí)替了節(jié)肚皮舞課程,好幾年沒上,急匆匆拾了起來。 早年前,就聽說肚皮舞是上天賜給女人的禮物,看...
    白瑪_ceaf閱讀 203評(píng)論 0 0
  • "初來乍到,請(qǐng)多多關(guān)照。” 我對(duì)著面前的三顆樹說完后,一屁股坐在了樹下的石凳上,開始抓緊補(bǔ)交作業(yè)e_e。爭(zhēng)取今后一...
    身體棒棒閱讀 249評(píng)論 0 3