2 Star 1 Fork 0

ggluck/react-native-tab-navigator

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
Badge.js 1.46 KB
一键复制 编辑 原始数据 按行查看 历史
Shaun Stanworth 提交于 2016-05-12 07:46 +08:00 . Support RN 0.25 (#72)
'use strict';
import React from 'react';
import {
StyleSheet,
Text,
} from 'react-native';
import Layout from './Layout';
export default class Badge extends React.Component {
static propTypes = Text.propTypes;
constructor(props, context) {
super(props, context);
this._handleLayout = this._handleLayout.bind(this);
}
state = {
computedSize: null,
};
render() {
let { computedSize } = this.state;
let style = {};
if (!computedSize) {
style.opacity = 0;
} else {
style.width = Math.max(computedSize.height, computedSize.width);
}
return (
<Text
{...this.props}
numberOfLines={1}
onLayout={this._handleLayout}
style={[styles.container, this.props.style, style]}>
{this.props.children}
</Text>
);
}
_handleLayout(event) {
let { width, height } = event.nativeEvent.layout;
let { computedSize } = this.state;
if (computedSize && computedSize.height === height &&
computedSize.width === width) {
return;
}
this.setState({
computedSize: { width, height },
});
if (this.props.onLayout) {
this.props.onLayout(event);
}
}
}
let styles = StyleSheet.create({
container: {
fontSize: 12,
color: '#fff',
backgroundColor: 'rgb(0, 122, 255)',
lineHeight: 15,
textAlign: 'center',
borderWidth: 1 + Layout.pixel,
borderColor: '#fefefe',
borderRadius: 17 / 2,
overflow: 'hidden',
},
});
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

搜索帮助