React Native 购物车数量红色小角标封装

import React, {Component} from 'react';
import {
    StyleSheet,
    View,
    Dimensions,
    Text
} from 'react-native';
const {width, height} = Dimensions.get('window');
//模块声名并导出
export default class CountTag extends Component {
    //属性声名
    static propTypes = {
        text: React.PropTypes.any
    };
    //默认属性
    static defaultProps = {
        fontSize: Constant.fontSizeXSmall,//字体大小
        backgroundColor: Constant.colorTxtPrimary,//背景颜色
        color: '#ffffff',//字体颜色
        defaultWidth: 14,

    };
    //构造函数
    constructor(props) {
        super(props);
        this.state = { //状态机变量声明
        }
    }

    //渲染
    render() {
        return (
            <View
                style={[styles.contentStyle,this.props.style,{backgroundColor: this.props.backgroundColor,borderColor: this.props.backgroundColor,minWidth: this.props.defaultWidth,height: this.props.defaultWidth}]}>
                <Text numberOfLines={1}
                      style={{color: this.props.color,fontSize:this.props.fontSize,margin:3}}>{this.props.text}</Text>
            </View>
        );
    }
};


const styles = StyleSheet.create({
    contentStyle: {
        borderRadius: 100,
        position: 'absolute',
        alignItems: 'center',
        justifyContent: 'center',
        flexDirection: 'row',
    }
});

使用

<CountTag style={{}}
          text={0 < this.state.count < 100 ? this.state.count : "99+"  }/> // text为any类型,可以数字,可以字符串
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 3
    评论
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值