2 Star 1 Fork 0

ggluck/react-native-tab-navigator

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
Tab.js 2.11 KB
一键复制 编辑 原始数据 按行查看 历史
'use strict';
import React, {
PropTypes,
} from 'react';
import {
StyleSheet,
Text,
TouchableOpacity,
View,
} from 'react-native';
import Layout from './Layout';
export default class Tab extends React.Component {
static propTypes = {
testID : PropTypes.string,
title: PropTypes.string,
titleStyle: Text.propTypes.style,
badge: PropTypes.element,
onPress: PropTypes.func,
hidesTabTouch: PropTypes.bool,
allowFontScaling: PropTypes.bool,
style: View.propTypes.style,
};
constructor(props, context) {
super(props, context);
this._handlePress = this._handlePress.bind(this);
}
render() {
let { title, badge } = this.props;
let icon = null;
if (React.Children.count(this.props.children) > 0) {
icon = React.Children.only(this.props.children);
}
if (title) {
title =
<Text
numberOfLines={1}
allowFontScaling={!!this.props.allowFontScaling}
style={[styles.title, this.props.titleStyle]}>
{title}
</Text>;
}
if (badge) {
badge = React.cloneElement(badge, {
style: [styles.badge, badge.props.style],
});
}
let tabStyle = [
styles.container,
title ? null : styles.untitledContainer,
this.props.style,
];
return (
<TouchableOpacity
testID={this.props.testID}
activeOpacity={this.props.hidesTabTouch ? 1.0 : 0.8}
onPress={this._handlePress}
style={tabStyle}>
<View>
{icon}
{badge}
</View>
{title}
</TouchableOpacity>
);
}
_handlePress(event) {
if (this.props.onPress) {
this.props.onPress(event);
}
}
}
let styles = StyleSheet.create({
badge: {
position: 'absolute',
top: -6,
right: -10,
},
container: {
flex: 1,
flexDirection: 'column',
justifyContent: 'flex-end',
alignItems: 'center',
},
untitledContainer: {
paddingBottom: 13,
},
title: {
color: '#929292',
fontSize: 10,
textAlign: 'center',
alignSelf: 'stretch',
marginTop: 4,
marginBottom: 1 + Layout.pixel,
},
});
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/ggluck/react-native-tab-navigator.git
git@gitee.com:ggluck/react-native-tab-navigator.git
ggluck
react-native-tab-navigator
react-native-tab-navigator
master

搜索帮助