2.0.7 • Published 2 years ago

react-native-circular-progress-view v2.0.7

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

react-native-circular-progress-indicator

license platforms Version npm

A simple and customizable React Native circular progress indicator component.

This project is inspired from this Youtube tutorial. Do check it out. Special mention at @mironcatalin

Demo

❤️ Expo Snack

npm.io npm.io npm.io npm.io npm.io npm.io npm.io

Prerequisites

⚠️ Peer Dependencies

This component has a peer dependency on react-native-reanimated-v2. react-native-reanimated-v2 has to be installed and linked into your project. Follow react-native-reanimated-v2 to install the dependency.

This component has a peer dependency on react-native-svg to draw the countdown circle. react-native-svg has to be installed and linked into your project. Follow react-native-svg to install the dependency.

Installation

Supported version: react-native >= 0.59.0

npm install react-native-circular-progress-view

or

yarn add react-native-circular-progress-view

Example

import CircularProgress from 'react-native-circular-progress-indicator';

....

<CircularProgress value={58} />
<CircularProgress
  value={60}
  radius={120}
  duration={2000}
  textColor={'#ecf0f1'}
  maxValue={200}
  title={'KM/H'}
  titleColor={'white'}
  titleStyle={{fontWeight: 'bold'}}
/>
<CircularProgress
  value={60}
  activeStrokeWidth={12}
  textColor={'#ecf0f1'}
/>

npm.io

with value prefix/suffix

import CircularProgress from 'react-native-circular-progress-indicator';

....

<CircularProgress
  value={90}
  valuePrefix={'$'}
  inActiveStrokeColor={'#2ecc71'}
  inActiveStrokeOpacity={0.2}
/>

<CircularProgress
  value={85}
  inActiveStrokeColor={'#2ecc71'}
  inActiveStrokeOpacity={0.2}
  textColor={'#fff'}
  valueSuffix={'%'}
/>

npm.io

with callback function

import CircularProgress from 'react-native-circular-progress-indicator';

....

<CircularProgress
  value={90}
  inActiveStrokeColor={'#2ecc71'}
  inActiveStrokeOpacity={0.2}
  textColor={'#fff'}
  valueSuffix={'%'}
  onAnimationComplete={() => { alert('callback') }}
/>

npm.io

custom

import CircularProgress from 'react-native-circular-progress-indicator';

....

 <CircularProgress
  value={60}
  radius={120}
  textColor={'#ecf0f1'}
  activeStrokeColor={'#f39c12'}
  inActiveStrokeColor={'#9b59b6'}
  inActiveStrokeOpacity={0.5}
  inActiveStrokeWidth={20}
  activeStrokeWidth={40}
/>

<CircularProgress
  value={60}
  radius={120}
  textColor={'#ecf0f1'}
  activeStrokeColor={'#f39c12'}
  inActiveStrokeColor={'#9b59b6'}
  inActiveStrokeOpacity={0.5}
  inActiveStrokeWidth={40}
  activeStrokeWidth={20}
/>

<CircularProgress
  value={60}
  radius={120}
  inActiveStrokeOpacity={0.5}
  activeStrokeWidth={20}
  inActiveStrokeWidth={20}
  textStyle={{ fontWeight: '100', color: 'yellow' }}
/>

npm.io

use as a countdown timer

import CircularProgress from 'react-native-circular-progress-indicator';

....

<CircularProgress
  value={0}
  radius={120}
  maxValue={10}
  initialValue={10}
  textColor={'#fff'}
  activeStrokeWidth={15}
  inActiveStrokeWidth={15}
  duration={10000}
  onAnimationComplete={() => alert('time out')}
/>

npm.io

with gradient effect

import CircularProgress from 'react-native-circular-progress-indicator';

....

<CircularProgress
  value={100}
  activeStrokeColor={'#2465FD'}
  activeStrokeSecondaryColor={'#C25AFF'}
/>

npm.io

with multiple child

import { CircularProgressWithChild } from 'react-native-circular-progress-indicator';

// accepts any react element as child
....

const props = {
  activeStrokeWidth: 25,
  inActiveStrokeWidth: 25,
  inActiveStrokeOpacity: 0.2
};

...

<CircularProgressWithChild
  {...props}
  value={80}
  radius={125}
  activeStrokeColor={'#e84118'}
  inActiveStrokeColor={'#e84118'}
>
  <CircularProgressWithChild
    {...props}
    value={87}
    radius={100}
    activeStrokeColor={'#badc58'}
    inActiveStrokeColor={'#badc58'}
  >
    <CircularProgressWithChild
      {...props}
      value={62}
      radius={75}
      activeStrokeColor={'#18dcff'}
      inActiveStrokeColor={'#18dcff'}
    />
  </CircularProgressWithChild>
</CircularProgressWithChild>

npm.io

Props

PropDescriptionTypeDefault ValueRequired
valueprogress valueNumber0true
initialValueinitial progress value. Helpful when used as a countdown timerNumber0false
titletitle to display below the progress valueString''false
titleStyletitle text styleObject{}false
titleColortitle text colorStringfalse
titleFontSizetitle text font sizeNumberfalse
subtitlesubtitle to display below the progress valueString''false
subtitleStylesubtitle text styleObject{}false
subtitleColorsubtitle text colorStringfalse
subtitleFontSizesubtitle text font sizeNumberfalse
circleBackgroundColorprogress circle background colorString'transparent'false
radiusprogress circle radiusNumber60false
activeStrokeWidthactive progress circle stroke widthNumber10false
inActiveStrokeWidthinactive progress circle stroke widthNumber10false
durationprogress animation durationNumber500false
delayprogress animation delayNumber0false
textColorprogress value text colorStringfalse
textStyleprogress value text styleObject{}false
maxValueprogress maximum value. Percentage calculation is based on the maximum value providedString100false
fontSizeprogress value text font sizeNumberfalse
inActiveStrokeOpacityinactive progress circle opacity valueNumber1false
strokeLinecapprogress stroke line cap'round' or 'butt' or 'square''round'false
onAnimationCompletecallback when animation is completed.Function()=>{}false
valuePrefixprefix valueString''false
valueSuffixsuffix valueString''false
activeStrokeColoractive progress circle colorString'#2ecc71'false
activeStrokeSecondaryColoractive progress secondary color. Use this to provide a gradient effectString''false
inActiveStrokeColorinactive progress circle colorString'rgba(0,0,0,0.3)'false
showProgressValueshow or hide the progress text valueBooltruefalse
clockwiseshow ring progress clockwise or anti-clockwise. pass false to enable anti clock-wiseBooltruefalse

License

This project is licenced under the MIT License.