Code Monkey home page Code Monkey logo

react-native-percentage-circle's Introduction

react-native-percentage-circle

Twitter URL npm

React Native Version >= 0.25

React-Native-Percentage-Cirlce is a component which supports you define your percent and draw the circle.And also you can use it as a progress bar.And you can show some data in a circle you want.

react.js version

This is a screenshot of the Demo

Start

npm i react-native-percentage-circle --save
import PercentageCircle from 'react-native-percentage-circle';

//...

render() {
  <View>
    <PercentageCircle radius={35} percent={50} color={"#3498db"}></PercentageCircle>  
  </View>
   <View>
    <PercentageCircle radius={35} percent={50} color={"#3498db"}>
      <Image style={{width:20,height:20}} source={{require('your image')}} />
    </PercentageCircle>  
  </View>
}

Options

Props Type Example Description
color string '#000' the color of border
bgcolor string '#e3e3e3' the background color of the circle
innerColor string '#fff' the color of the inside of the circle
percent Number 30 the percent you need
radius Number 20 how large the circle is
borderWidth Number(default 2) 5 the width of percentage progress bar
textStyle Array {fontSize: 24, color: 'red'} define the style of the text which in the circle
children jsx <Text>123</Text> define the children component in the circle

Contributions

Your contributions and suggestions are welcome 😄😄😄

MIT License

react-native-percentage-circle's People

Contributors

areiterer avatar hanxf3 avatar jackpu avatar jkomyno avatar ravingupta avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

react-native-percentage-circle's Issues

wrong progress

wrong progress is following 0%=100%, 10%=90%, 20%=80, 30%=80%, 40%=60%

percentage issue

image
I'm using your package, and i noticed a bug, while simulating a count down from 100 - 0.

From 100 to 50 it alright, but when it reached 49 it resets back (looks like how 1 percent looks)

This image i've added is at 48 percent

no live reload

<PercentageCircle radius={150} percent={this.state.charge} color={"#3498db"} borderWidth={7} >

The solution to fix wrong progress when percentage is less than 50

Env:

Wrong Example on Android:
android

Normal Example on iOS:
ios

When percentage is less than 50, the circle is wrong.

I thought it might be caused by overflow on Android, and I found an known issue in [email protected] described as below:

overflow样式在Android默认为hidden而且无法更改
这是Android本身的渲染机制所致。我们没有实现这一特性,因为这是个大工程,而且我们还有很多其他重要的任务。
Android的overflow:hidden还有另外一个问题:如果父容器有borderRadius圆角边框样式,那么即便开启了overflow:hidden也仍然无法把子视图超出圆角边框的部分裁切掉。这个问题只存在于Android上,iOS并没有这个问题(子视图的内容不会超出父容器的圆角边框)。你可以在这里看到问题的演示,以及在这里查看这个问题的报告以及后续进展。

So the implementation of overflow differs in Android and iOS, that's why the issue only occurs on Android in my project.

I have tried the solutions which I can found here, unfortunately none of them works.

So I have to dig into it and this is my solution:

Solution

Step 1

line 74 in method constructor:

    if (percent >= 50) {
      rightTransformerDegree = '180deg';
      leftTransformerDegree = (percent - 50) * 3.6 + 'deg';
    } else {
      rightTransformerDegree = percent * 3.6 + 'deg';
      leftTransformerDegree = '0deg'; 
    }

changed into

    if (percent >= 50) {
      rightTransformerDegree = '180deg';
      leftTransformerDegree = (percent - 50) * 3.6 + 'deg';
    } else {
      rightTransformerDegree = percent * 3.6 + 'deg';
      leftTransformerDegree = '180deg';   // line 74: changed here
    }

Step2

line 94 in method componentWillReceiveProps

    if (percent >= 50) {
      rightTransformerDegree = '180deg';
      leftTransformerDegree = (percent - 50) * 3.6 + 'deg';
    } else {
      rightTransformerDegree = percent * 3.6 + 'deg';
    }

insert a line:

    if (percent >= 50) {
      rightTransformerDegree = '180deg';
      leftTransformerDegree = (percent - 50) * 3.6 + 'deg';
    } else {
      rightTransformerDegree = percent * 3.6 + 'deg';
      leftTransformerDegree = "180deg";   // insert a line here
    }

Step 3

Adjust content between line 123 and 152:

        <View style={[styles.leftWrap,{
          width: this.props.radius,
          height: this.props.radius * 2,
          left:0,
        }]}>
          <View style={[styles.loader,{
            left: this.props.radius,
            width:this.props.radius,
            height: this.props.radius*2,
            borderTopLeftRadius:0,
            borderBottomLeftRadius:0,
            backgroundColor:this.props.color,
            transform:[{translateX:-this.props.radius/2},{rotate:this.state.leftTransformerDegree},{translateX:this.props.radius/2}],
          }]}></View>
        </View>
        <View style={[styles.leftWrap,{
          left:this.props.radius,
          width: this.props.radius,
          height: this.props.radius * 2,
        }]}>
          <View style={[styles.loader,{
            left:-this.props.radius,
            width:this.props.radius,
            height: this.props.radius*2,
            borderTopRightRadius:0,
            borderBottomRightRadius:0,
            backgroundColor: this.props.color,
            transform:[{translateX:this.props.radius/2},{rotate:this.state.rightTransformerDegree},{translateX:-this.props.radius/2}],
          }]}></View>
        </View>

Put View#rightTransformerDegree before View#leftTransformerDegree, and change backgroundColor of View#leftTransformerDegree

        <View style={[styles.leftWrap,{
          left:this.props.radius,
          width: this.props.radius,
          height: this.props.radius * 2,
        }]}>
          <View style={[styles.loader,{
            left:-this.props.radius,
            width:this.props.radius,
            height: this.props.radius*2,
            borderTopRightRadius:0,
            borderBottomRightRadius:0,
            backgroundColor: this.props.color,
            transform:[{translateX:this.props.radius/2},{rotate:this.state.rightTransformerDegree},{translateX:-this.props.radius/2}],
          }]}></View>
        </View>
        <View style={[styles.leftWrap,{
          width: this.props.radius,
          height: this.props.radius * 2,
          left:0,
        }]}>
          <View style={[styles.loader,{
            left: this.props.radius,
            width:this.props.radius,
            height: this.props.radius*2,
            borderTopLeftRadius:0,
            borderBottomLeftRadius:0,
            backgroundColor:percent >= 50 ? this.props.color : this.props.bgcolor,    // changed this line
            transform:[{translateX:-this.props.radius/2},{rotate:this.state.leftTransformerDegree},{translateX:this.props.radius/2}],
          }]}></View>
        </View>

Conclusion

I have forked this project and rewritten the code, I hope it could be merged into this project, or you can visit at My forked repo

Some changes in forked repo:

  1. Fixed the issue when percentage is less than 50.
  2. Fixed textStyle prop which is applied in Text in View#innerCircle.
  3. Added new prop rotate to support customizing the start position of progress circle.

Warning

I have tested my solution only in environments below:

  • Android:

    • Device: XiaoMi 5
    • OS: Android 6.0.1 MXB48T
    • react: 15.4.1
    • react-native: 0.39.2
  • iOS:

    • Device: iPhone 6s
    • OS: iOS 11.4
    • react: 15.3.1
    • react-native: 0.33.1

radius not working

it is allways the same, 35/50/70

any way to create a fullscreen width circle with padding?

Warning: componentWillReceiveProps has been renamed

Hello, your package has been published since a long time i know, but i have trouble with the mentionned warning when using the package. It will be good if you can update this. I am newbie in react native and i can't fix this in my own. Thanks

Android bug

Hello thanks for your great plugin, im having the following weird issue, in ios works like a charm but in android it looks like cut a few parts of the circle.

captura de pantalla 2017-07-06 a la s 15 48 20

this is my code

<PercentageCircle
						bgcolor={colors.gray}
						innerColor={colors.gray}
						radius={circleRadius}
						percent={80}
						color={colors.orange}
						textStyle={{
							fontSize : measures.fontSize * 3
						}}
						style={{marginTop : measures.unit * 2}} />

Percentage less than 50 and how to fix it

change this: constructor(props) { super(props); let percent = this.props.percent; let leftTransformerDegree = '0deg'; let rightTransformerDegree = '0deg'; if (percent >= 50) { rightTransformerDegree = '180deg'; leftTransformerDegree = (percent - 50) * 3.6 + 'deg'; } else { rightTransformerDegree = percent * 3.6 + 'deg'; }

to this: constructor(props) { super(props); let percent = this.props.percent; let leftTransformerDegree = '0deg'; let rightTransformerDegree = '0deg'; if (percent >= 50) { rightTransformerDegree = '180deg'; leftTransformerDegree = (percent - 50) * 3.6 + 'deg'; } else { rightTransformerDegree = -(50-percent) * 3.6 + 'deg'; }

not work in RN 0.36+

This is the reason

Fix unconstraint sizing in main axis 0a9b6be

So, the percentage circle cannot display correctly.

Solution:
remove flex: 1, line: 17 in file index.js
can make it work. but I don't test it in RN 0.36-

Percentage circle for ReactJS?

Hi, I love the percentage circle for React Native, It works very well, good work. I was wondering If it could be possible to use it with ReactJS in the web?

Color gradient

Hi @JackPu , congratulations for the module.
Would it be possible to have the color that is gradient?

change dircection

Is it possible to change direction from left to right instead of right to left?

组件会跟着opacity的渐变,底色会显示出来

详情见下图,希望不要出现渐变色。

7gzhm6jqfg2p9558f0h1300

<Animated.View style={[styles.contView, {
width: width0.95,
height: height
0.6,
marginLeft: width0.025,
marginTop: height
0.9,
opacity: activeOpacity,
}]}>


<PercentageCircle radius={35} percent={80} color={"#E4E4E4"} bgcolor={'#0088FC'} innerColor={'#fff'} borderWidth={4}>
11:47



</Animated.View>
其中activeOpacity是从0-1的渐变值

Need animation effect

We need an animation effect like progressing from 0 to respective percentage or values.

Support for Touchable

Hello,

Really nice app! Exactly what I was looking for.
Quick question, is the circle Touchable ?
With a finger, can we set increase/decrease the percent in the middle by drawing along the circle ?

I am looking to reproduce this behavior that I saw in the Philips Hue app.
hue

Thanks a lot

Make inside color of the circle configurable

Hi,

when I tried this component, I noticed that you can't use it on dark backgrounds because the inside of the circle is always white.

My suggestion would be to make this color also configurable via props, like the other ones.
Am I allowed to change this and create a PR for that?

rnpc_demo packaged with apps built using react-native-percentage-circle

It seems like by including this package, the demo app rnpc_demo is also included in all builds (on iOS, if you open the .xcworkspace for the app, you can see rnpc_demo listed as a build scheme and in Libraries). This doesn't seem necessary, and in fact deleting the scheme/folder lets the app compile as normal. Is there any way to disable this example app from being packaged into my app? I'm getting some build errors that only appear in rnpc_demo, so I need to delete the folder every time I npm install to get the app to build. Any help would be appreciated — thanks!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.