Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

react-native-circular-progress

Package Overview
Dependencies
Maintainers
0
Versions
28
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-native-circular-progress

React Native component for creating animated, circular progress with react-native-svg

  • 1.4.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
0
Created
Source

react-native-circular-progress

license Version npm

React Native component for creating animated, circular progress. Useful for displaying users points for example.

Example app

image

Installation

  1. Install this component and react-native-svg:

    npm i --save react-native-circular-progress react-native-svg

  2. Link native code for SVG:

    react-native link react-native-svg

Usage

import { AnimatedCircularProgress } from 'react-native-circular-progress';

<AnimatedCircularProgress
  size={120}
  width={15}
  fill={100}
  tintColor="#00e0ff"
  onAnimationComplete={() => console.log('onAnimationComplete')}
  backgroundColor="#3d5875" />

You can also define a function that'll receive current progress and for example display it inside the circle:

<AnimatedCircularProgress
  size={200}
  width={3}
  fill={this.state.fill}
  tintColor="#00e0ff"
  backgroundColor="#3d5875">
  {
    (fill) => (
      <Text>
        { this.state.fill }
      </Text>
    )
  }
</AnimatedCircularProgress>

You can also define a function that'll receive the location at the top of the progress circle and render a custom SVG element:

<AnimatedCircularProgress
  size={120}
  width={15}
  fill={100}
  tintColor="#00e0ff"
  backgroundColor="#3d5875"
  padding={10}
  renderCap={({ center }) => <Circle cx={center.x} cy={center.y} r="10" fill="blue" />}
  />

Finally, you can manually trigger a duration-based timing animation by putting a ref on the component and calling the animate(toValue, duration, easing) function like so:

<AnimatedCircularProgress
  ref={(ref) => this.circularProgress = ref}
  ...
/>
this.circularProgress.animate(100, 8000, Easing.quad); // Will fill the progress bar linearly in 8 seconds

The animate-function returns the timing animation so you can chain, run in parallel etc.

Configuration

You can configure the CircularProgress-component by passing the following props:

NameTypeDefault valueDescription
sizenumber|Animated.ValuerequiredWidth and height of circle
widthnumberrequiredThickness of the progress line
backgroundWidthnumberwidthThickness of background circle
fillnumber (0-100)0Current progress / fill
tintColorstringblackColor of the progress line
tintTransparencybooleantrueTransparency of the progress line
backgroundColorstringIf unspecified, no background line will be rendered
rotationnumber (-360 - 360)90Angle from which the progress starts from
lineCapstringbuttShape used at ends of progress line. Possible values: butt, round, square
arcSweepAnglenumber (0-360)360If you don't want a full circle, specify the arc angle
styleViewPropTypes.styleExtra styling for the main container
childrenfunctionPass a function as a child. It received the current fill-value as an argument
childrenContainerStyleViewPropTypes.styleExtra styling for the children container
paddingnumber0Padding applied around the circle to allow for a cap that bleeds outside its boundary
dashedBackgroundobject{ width: 0, gap: 0 }Bar background as dashed type
dashedTintobject{ width: 0, gap: 0 }Bar tint as dashed type
renderCapfunctionundefinedFunction that's invoked during rendering to draw at the tip of the progress circle

The following props can further be used on AnimatedCircularProgress:

NameTypeDefault valueDescription
prefillnumber (0-100)0Initial fill-value before animation starts
durationnumber500Duration of animation in ms
delaynumber0Delay of animation in ms
easingfunctionEasing.out(Easing.ease)Animation easing function
onAnimationCompletefunctionFunction that's invoked when the animation completes (both on mount and if called with .animate())
onFillChangefunctionFunction that returns current progress on every change
tintColorSecondarystringthe same as tintColorTo change fill color from tintColor to tintColorSecondary as animation progresses

AnimatedCircularProgress also exposes the following functions:

NameArgumentsDescription
animate(toVal: number, duration: number, ease: function)Animate the progress bar to a specific value
reAnimate(prefill: number, toVal: number, duration: number, ease: function)Re-run animation with a specified prefill-value

Running example app (Expo)

git clone https://github.com/bgryszko/react-native-circular-progress.git
cd react-native-circular-progress/example-app
yarn
yarn start

Authors

  • Bartosz Gryszko (b@gryszko.com)
  • Markus Lindqvist
  • Jacob Lauritzen
  • Special thanks to all contributors!

License

MIT

Special thanks

Special thanks to Chalk+Chisel for creating working environment where people grow. This component was created for one of the projects we're working on.

Keywords

FAQs

Package last updated on 26 Oct 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc