基于 react-native-scrollable-tab-view 自定義的 segment

本 segment 是根據(jù) DefaultTabBar 改寫而成 , 由于動畫效果會遮擋里面的文字壶冒,所以把 動畫去掉了螃成。


效果圖

以下是 SegmentTabBar.js

const React = require('react');
const { ViewPropTypes } = ReactNative = require('react-native');
const {
    StyleSheet,
    Text,
    View,
    TouchableOpacity,
    Dimensions,
} = ReactNative;
const Button = require('./Button');
const PhoneWidth = Dimensions.get('window').width;
import Icon from 'react-native-vector-icons/FontAwesome';

const SegmentTabBar = React.createClass({
    propTypes: {
        goToPage: React.PropTypes.func,
        activeTab: React.PropTypes.number,
        tabs: React.PropTypes.array,
        backgroundColor: React.PropTypes.string,
        activeTextColor: React.PropTypes.string,
        inactiveTextColor: React.PropTypes.string,
        textStyle: Text.propTypes.style,
        tabStyle: ViewPropTypes.style,
        renderTab: React.PropTypes.func,
        underlineStyle: ViewPropTypes.style,
    },

    getDefaultProps() {
        return {
            activeTextColor: 'navy',
            inactiveTextColor: 'black',
            backgroundColor: null,
        };
    },

    renderTabOption(name, page) {
    },

    renderTab(name, page, isTabActive, onPressHandler) {
        const { activeTextColor, inactiveTextColor, textStyle, } = this.props;
        const textColor = isTabActive ? activeTextColor : inactiveTextColor;
        const backgroundColor = isTabActive ? '#0086E5' : '#FFF';
        const fontWeight = isTabActive ? 'bold' : 'normal';
        console.log(textColor)
        return <Button
            style={{flex: 1,height:25,backgroundColor,borderRadius:1}}
            key={name}
            accessible={true}
            accessibilityLabel={name}
            accessibilityTraits='button'
            onPress={() => onPressHandler(page)}
        >
            <View style={[styles.tab, this.props.tabStyle]}>
                <Text style={[{color: textColor, fontWeight}, textStyle, ]}>
                    {name}
                </Text>
            </View>
        </Button>;
    },

    render() {
        return (
            <View style={styles.tabBarBox}>
                <TouchableOpacity style={styles.iconBox} onPress={() => {}} >
                    <Icon name="bell-o" size={20} color="#333" />
                </TouchableOpacity>
                <View style={[styles.tabs, {backgroundColor: this.props.backgroundColor, }, this.props.style, ]}>
                    {this.props.tabs.map((name, page) => {
                        const isTabActive = this.props.activeTab === page;
                        const renderTab = this.props.renderTab || this.renderTab;
                        return renderTab(name, page, isTabActive, this.props.goToPage);
                    })}
                </View>
                <TouchableOpacity style={styles.iconBox} onPress={() => {}} >
                    <Icon name="search" size={20} color="#333"/>
                </TouchableOpacity>
            </View>
        );
    },
});

const styles = StyleSheet.create({
    tabBarBox:{
        height: 50,
        flexDirection:'row',
        alignItems:'center',
        justifyContent:'space-between'
    },
    iconBox:{
        margin:15
    },
    tab: {
        flex: 1,
        alignItems: 'center',
        justifyContent: 'center',
    },
    tabs: {
        borderRadius:2,
        borderColor: '#0086E5',
        borderWidth:1,
        width:PhoneWidth/3,
        flexDirection: 'row',
        alignItems:'center',
        alignContent:'center',
        justifyContent: 'space-around',
    },
});

module.exports = SegmentTabBar;

這里的Button.js

const React = require('react');
const ReactNative = require('react-native');
const {
 TouchableOpacity,
} = ReactNative;

const Button = (props) => {
  return <TouchableOpacity {...props} activeOpacity={0.95}>
    {props.children}
  </TouchableOpacity>;
};

module.exports = Button;

然后在 ScrollableTabView 里面使用它

<ScrollableTabView
          style={styles.container}
          tabBarPosition='top'
          tabBarBackgroundColor='#FFFFFF'
          tabBarActiveTextColor='#fff'
          tabBarInactiveTextColor='#333'
          tabBarTextStyle={{fontSize: 13}}
          renderTabBar={() => <SegmentTabBar navigate />}> 
          <TopicList tabLabel='發(fā)現(xiàn)' {...this.props}/>
          <MyCircle tabLabel='我的圈子' {...this.props}/>
</ScrollableTabView>

xi
~~~~~~~~

最后編輯于
?著作權歸作者所有,轉載或內容合作請聯(lián)系作者
  • 序言:七十年代末,一起剝皮案震驚了整個濱河市拾稳,隨后出現(xiàn)的幾起案子,更是在濱河造成了極大的恐慌腊脱,老刑警劉巖访得,帶你破解...
    沈念sama閱讀 221,888評論 6 515
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件,死亡現(xiàn)場離奇詭異陕凹,居然都是意外死亡悍抑,警方通過查閱死者的電腦和手機,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 94,677評論 3 399
  • 文/潘曉璐 我一進店門杜耙,熙熙樓的掌柜王于貴愁眉苦臉地迎上來搜骡,“玉大人,你說我怎么就攤上這事佑女〖敲遥” “怎么了?”我有些...
    開封第一講書人閱讀 168,386評論 0 360
  • 文/不壞的土叔 我叫張陵珊豹,是天一觀的道長簸呈。 經常有香客問我榕订,道長店茶,這世上最難降的妖魔是什么? 我笑而不...
    開封第一講書人閱讀 59,726評論 1 297
  • 正文 為了忘掉前任劫恒,我火速辦了婚禮贩幻,結果婚禮上,老公的妹妹穿的比我還像新娘两嘴。我一直安慰自己丛楚,他們只是感情好,可當我...
    茶點故事閱讀 68,729評論 6 397
  • 文/花漫 我一把揭開白布憔辫。 她就那樣靜靜地躺著趣些,像睡著了一般。 火紅的嫁衣襯著肌膚如雪贰您。 梳的紋絲不亂的頭發(fā)上坏平,一...
    開封第一講書人閱讀 52,337評論 1 310
  • 那天拢操,我揣著相機與錄音,去河邊找鬼舶替。 笑死令境,一個胖子當著我的面吹牛,可吹牛的內容都是我干的顾瞪。 我是一名探鬼主播舔庶,決...
    沈念sama閱讀 40,902評論 3 421
  • 文/蒼蘭香墨 我猛地睜開眼,長吁一口氣:“原來是場噩夢啊……” “哼陈醒!你這毒婦竟也來了惕橙?” 一聲冷哼從身側響起,我...
    開封第一講書人閱讀 39,807評論 0 276
  • 序言:老撾萬榮一對情侶失蹤钉跷,失蹤者是張志新(化名)和其女友劉穎吕漂,沒想到半個月后,有當?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體尘应,經...
    沈念sama閱讀 46,349評論 1 318
  • 正文 獨居荒郊野嶺守林人離奇死亡惶凝,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內容為張勛視角 年9月15日...
    茶點故事閱讀 38,439評論 3 340
  • 正文 我和宋清朗相戀三年,在試婚紗的時候發(fā)現(xiàn)自己被綠了犬钢。 大學時的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片苍鲜。...
    茶點故事閱讀 40,567評論 1 352
  • 序言:一個原本活蹦亂跳的男人離奇死亡,死狀恐怖玷犹,靈堂內的尸體忽然破棺而出混滔,到底是詐尸還是另有隱情,我是刑警寧澤歹颓,帶...
    沈念sama閱讀 36,242評論 5 350
  • 正文 年R本政府宣布坯屿,位于F島的核電站,受9級特大地震影響巍扛,放射性物質發(fā)生泄漏领跛。R本人自食惡果不足惜,卻給世界環(huán)境...
    茶點故事閱讀 41,933評論 3 334
  • 文/蒙蒙 一撤奸、第九天 我趴在偏房一處隱蔽的房頂上張望吠昭。 院中可真熱鬧,春花似錦胧瓜、人聲如沸矢棚。這莊子的主人今日做“春日...
    開封第一講書人閱讀 32,420評論 0 24
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽蒲肋。三九已至,卻和暖如春,著一層夾襖步出監(jiān)牢的瞬間兜粘,已是汗流浹背强胰。 一陣腳步聲響...
    開封第一講書人閱讀 33,531評論 1 272
  • 我被黑心中介騙來泰國打工, 沒想到剛下飛機就差點兒被人妖公主榨干…… 1. 我叫王不留妹沙,地道東北人偶洋。 一個月前我還...
    沈念sama閱讀 48,995評論 3 377
  • 正文 我出身青樓,卻偏偏與公主長得像距糖,于是被迫代替她去往敵國和親玄窝。 傳聞我的和親對象是個殘疾皇子,可洞房花燭夜當晚...
    茶點故事閱讀 45,585評論 2 359

推薦閱讀更多精彩內容

  • Android 自定義View的各種姿勢1 Activity的顯示之ViewRootImpl詳解 Activity...
    passiontim閱讀 172,302評論 25 707
  • 發(fā)現(xiàn) 關注 消息 iOS 第三方庫悍引、插件恩脂、知名博客總結 作者大灰狼的小綿羊哥哥關注 2017.06.26 09:4...
    肇東周閱讀 12,120評論 4 61
  • 黑夜 伸手想要抓住靈感的尾巴 靈感啊 這個靈動的小孩 似乎感受到了寫手的意圖 轉身說走就走 徒留可憐的寫手在嘆息惆悵
    紫霞Candice閱讀 73評論 0 0
  • Kate眼鏡由倫敦設計團隊設計,意大利工廠生產趣斤。我們從鼻子墊到鉸鏈俩块,從概念草圖到產品的每一個細節(jié),探索顏色和光浓领,形...
    青蟲和桃子閱讀 545評論 0 0
  • 概述 排序有內部排序和外部排序玉凯,內部排序是數(shù)據(jù)記錄在內存中進行排序,而外部排序是因排序的數(shù)據(jù)很大联贩,一次不能容納全部...
    蟻前閱讀 5,191評論 0 52