基于 react-native-scrollable-tab-v

作者: cielu | 来源:发表于2017-07-04 15:01 被阅读245次

本 segment 是根据 DefaultTabBar 改写而成 , 由于动画效果会遮挡里面的文字,所以把 动画去掉了。


效果图

以下是 SegmentTabBar.js
<pre>
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';

</br>
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,
},
</br>
getDefaultProps() {
return {
activeTextColor: 'navy',
inactiveTextColor: 'black',
backgroundColor: null,
};
},
</br>
renderTabOption(name, page) {
},
</br>
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>;
},
</br>
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>
);
},
});
</br>
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',
},
});
</br>
module.exports = SegmentTabBar;
</pre>
这里的Button.js
<pre>
const React = require('react');
const ReactNative = require('react-native');
const {
TouchableOpacity,
} = ReactNative;
</br>
const Button = (props) => {
return <TouchableOpacity {...props} activeOpacity={0.95}>
{props.children}
</TouchableOpacity>;
};
</br>
module.exports = Button;
</pre>
然后在 ScrollableTabView 里面使用它
<pre>
<ScrollableTabView
style={styles.container}
tabBarPosition='top'
tabBarBackgroundColor='#FFFFFF'
tabBarActiveTextColor='#fff'
tabBarInactiveTextColor='#333'
tabBarTextStyle={{fontSize: 13}}
renderTabBar={() => <SegmentTabBar navigate />}>
<TopicList tabLabel='发现' {...this.props}/>
<MyCircle tabLabel='我的圈子' {...this.props}/>
</ScrollableTabView>
</pre>
xi
~~~~~~~~

相关文章

  • 基于 react-native-scrollable-tab-v

    本 segment 是根据 DefaultTabBar 改写而成 , 由于动画效果会遮挡里面的文字,所以把 动画去...

  • 三种管理方式

    基于控制 基于责任 基于愿景

  • 推荐系统简介

    推荐问题产生 信息过载 推荐问题解决方法 基于内容 基于协同过滤 基于邻域的方法基于用户基于物品 基于模型的方法隐...

  • Spring配置元数据的三种方式

    基于java配置方式 基于注解方式 基于xml方式

  • 清晨日记 | 高效率慢生活践行DAY24【文案】

    Keep moving forward 过分追求完美,往往过得并不完美 ——基于流程、基于制度、基于习惯、基于训练...

  • 分布式锁(Redis)

    基于数据库的 基于redis 基于zookeeper 基于数据库 基于redis 先来看第一种 改进版 redi...

  • 分布式锁入门

    目前主流的有三种: 基于数据库实现 基于Redis实现 基于ZooKeeper实现 1. 基于数据库实现: 基于数...

  • 关于中文分词

    一. 分词的类型 1. 基于词典:基于字典、词库匹配 2. 基于统计 3. 基于理解 二. 基于词典分词 1. 正...

  • 清晨日记 | 高效率慢生活践行DAY25【千茄】

    Keep moving forward 严肃的个人追求,需要纯时间的积累 ——基于流程、基于制度、基于习惯、基于训...

  • 逃离(1)

    前言: 逃离,可以基于软弱,可以基于无奈,可以基于恐惧,也可以基于淡漠。我的逃离基于什么我自己也不清楚,好像都是,...

网友评论

  • Skyling:情书,这是写死导航title,要是动态数据渲染的title 导航,用这个插件的自定义bar就实现不了手势切换了 不知道是哪里出的问题
  • THOMAX:赞

本文标题:基于 react-native-scrollable-tab-v

本文链接:https://www.haomeiwen.com/subject/xgqxhxtx.html