React-Native 环形进度条组件 react-native-circular-progress

先上效果图

在这里插入图片描述

实现

在RN中,要实现环形进度条效果,一般都是需要借助chart图实现;最近做RN项目,经过折腾,发现react-native-circular-progress这个组件几乎能完美的解决。故分享出来,废话不多说了,直接上代码

1、react-native-circular-progress组件Circle.js的封装
import React, { PureComponent } from 'react';
import {StyleSheet, View, Dimensions} from 'react-native';
import { AnimatedCircularProgress } from 'react-native-circular-progress';
import PropTypes from 'prop-types';
const { width } = Dimensions.get(`window`);
const styles = StyleSheet.create({
    container: {
        alignItems: `center`
    },
    text: {
        backgroundColor: `transparent`
    },
    content: {
        borderColor: `#96DEE8`,
        borderBottomWidth: 1,
        paddingBottom: 5,
        paddingHorizontal: 5,
        marginBottom: 5
    }
});
export default class Circle extends PureComponent {
    static propTypes = {
        warn: PropTypes.number,
        mount: PropTypes.number,
        name: PropTypes.string,
        tintColor : PropTypes.string,
        backgroundColor : PropTypes.string,
        textOne : PropTypes.string,
        textTwo : PropTypes.string,
    }

    static defaultProps = {
        warn: 0,
        mount: 0,
        name: ``,
        tintColor : '2196F3',
        backgroundColor : '#9E9E9E',
        textOne : '',
        textTwo : ''
    }

    render() {
        const { warn, mount, name,tintColor,backgroundColor,textOne,textTwo } =        this.props;
        return (
          <View style={[styles.container, {width: (width - 30)/2, paddingBottom: 10}]}>
              <AnimatedCircularProgress
                  size={130}
                  width={8}
                    backgroundWidth={6}
                   fill={mount === 0 ? 0 : mount * 100 / (mount + warn)}
                    tintColor= {tintColor}
                    backgroundColor= {backgroundColor}
                    arcSweepAngle={360}
                  rotation={180}
                  lineCap="square"
                >
                  {() => (
                        <View style={{ alignItems: `center` }}>
                            <Text style={[styles.text, { fontWeight: `bold`, fontSize: 20 }]}>{warn}</TextView>
                            <View style={styles.content}>
                            <Text style={[styles.text, { fontSize: 11 }]}>{textOne}</Text>
                          </View>
                      <Text style={[styles.text, { fontWeight: `bold`, fontSize: 14 }]}>{mount}</Text>
                      <Text style={[styles.text, { fontSize: 11 }]}>{textTwo}</Text>
                    </View>
                    )}
                </AnimatedCircularProgress>
            </View>
        );
    }
}

2、调用
import Circle from 'Circle.js';

<Circle 
   key={`circle_one`} 
   mount={120} 
   warn={15} 
   name={`test`}
   tintColor = {`#FFC30F`}
   backgroundColor = {`#606266`}
   textOne = {`正常`}
   textTwo = {`故障`}
 />
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值