代码拉取完成,页面将自动刷新
'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',
},
});
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。