Skip to content

Commit

Permalink
Merge pull request #13 from nithinpp69/develop
Browse files Browse the repository at this point in the history
Add gradient effect
  • Loading branch information
nithinpp69 authored Aug 10, 2021
2 parents 4d39be9 + 2cbfb05 commit ea48099
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 3 deletions.
19 changes: 19 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ This project is inspired from this [Youtube tutorial](https://www.youtube.com/wa
![](demo3.gif)
![](demo4.gif)
![](demo5.gif)
![](gradient.png)

## Prerequisites

Expand Down Expand Up @@ -167,6 +168,23 @@ import CircularProgress from 'react-native-circular-progress-indicator';

![](demo5.gif)

#### with gradient effect

```
import CircularProgress from 'react-native-circular-progress-indicator';
....
<CircularProgress
value={100}
activeStrokeColor={'#2465FD'}
activeStrokeSecondaryColor={'#C25AFF'}
/>
```

![](gradient.png)

## Props
| Prop | Description | Type | Default Value | Required |
| :-----------: |:-------------:| :-----:| :-----: | :-----: |
Expand All @@ -187,6 +205,7 @@ import CircularProgress from 'react-native-circular-progress-indicator';
| valuePrefix | prefix value | String | '' | false |
| valueSuffix | suffix value | String | '' | false |
| activeStrokeColor | active progress circle color | String | '#2ecc71' | false |
| activeStrokeSecondaryColor | active progress secondary color. Use this to provide a gradient effect | String | '' | false |
| inActiveStrokeColor | inactive progress circle color | String | 'rgba(0,0,0,0.3)' | false |
| showProgressValue | show or hide the progress text value | Bool | true | false |

Expand Down
Binary file added gradient.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "react-native-circular-progress-indicator",
"version": "1.1.1",
"version": "1.1.2",
"description": "React Native customizable circular progress indicator",
"main": "index.js",
"scripts": {
Expand Down
16 changes: 14 additions & 2 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React, { useEffect, useRef } from 'react';
import { StyleSheet, View, TextInput, Animated } from 'react-native';
import PropTypes from 'prop-types';
import Svg, { G, Circle } from 'react-native-svg';
import Svg, { G, Circle, Defs, LinearGradient, Stop } from 'react-native-svg';

const AnimatedCircle = Animated.createAnimatedComponent(Circle);
const AnimatedInput = Animated.createAnimatedComponent(TextInput);
Expand All @@ -22,6 +22,7 @@ const CircularProgress = (props) => {
valuePrefix,
valueSuffix,
activeStrokeColor,
activeStrokeSecondaryColor,
activeStrokeWidth,
inActiveStrokeColor,
inActiveStrokeWidth,
Expand Down Expand Up @@ -82,6 +83,15 @@ const CircularProgress = (props) => {
width={radius * 2}
height={radius * 2}
viewBox={`0 0 ${halfCircle * 2} ${halfCircle * 2}`}>
{activeStrokeSecondaryColor ?
<Defs>
<LinearGradient id={'grad'} x1="0%" y1="0%" x2="0%" y2="100%">
<Stop offset="0%" stopColor={activeStrokeSecondaryColor} />
<Stop offset="100%" stopColor={activeStrokeColor} />
</LinearGradient>
</Defs>
: null}

<G rotation={'-90'} origin={`${halfCircle}, ${halfCircle}`}>
<Circle
cx="50%"
Expand All @@ -96,7 +106,7 @@ const CircularProgress = (props) => {
ref={circleRef}
cx="50%"
cy="50%"
stroke={activeStrokeColor}
stroke={activeStrokeSecondaryColor ? `url(#grad)` : activeStrokeColor}
strokeWidth={activeStrokeWidth}
r={radius}
fill={'transparent'}
Expand Down Expand Up @@ -147,6 +157,7 @@ CircularProgress.propTypes = {
valuePrefix: PropTypes.string,
valueSuffix: PropTypes.string,
activeStrokeColor: PropTypes.string,
activeStrokeSecondaryColor: PropTypes.string,
inActiveStrokeColor: PropTypes.string,
inActiveStrokeOpacity: PropTypes.number,
activeStrokeWidth: PropTypes.number,
Expand All @@ -167,6 +178,7 @@ CircularProgress.defaultProps = {
valueSuffix: '',
textStyle: {},
activeStrokeColor: '#2ecc71',
activeStrokeSecondaryColor: '',
inActiveStrokeColor: 'rgba(0,0,0,0.3)',
inActiveStrokeOpacity: 1,
activeStrokeWidth: 10,
Expand Down

0 comments on commit ea48099

Please sign in to comment.