@2hats/react-native-circular-progress 中文文档教程

发布于 7年前 浏览 29 项目主页 更新于 3年前

[license]() 版本npm Twitter Follow

react-native-circular-progress

React Native 组件,用于使用 ReactART 创建动画循环进度。 例如用于显示用户点数。 适用于 iOS 和 Android。


寻找圆形滑块?看看我的其他组件 – react-native-circular-slider :alarm_clock:


Example app

image

Installation

  1. Install library npm i --save react-native-circular-progress
  2. Link ART library to your ReactNative project (how to link a library?). You'll find ReactART library in node_modules/react-native/Libraries/ART/ART.xcodeproj

Usage

导入 CircularProgress 或 AnimatedCircularProgress。

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

使用如下:

<AnimatedCircularProgress
  size={120}
  width={15}
  fill={100}
  tintColor="#00e0ff"
  backgroundColor="#3d5875" />

您还可以定义一个函数,该函数将接收当前进度并将其显示在圆圈内:

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

最后,您可以通过在组件上放置一个 ref 并调用 performLinearAnimation(toValue, duration) 函数如下:

<AnimatedCircularProgress
  ref='circularProgress'
  ...
/>
this.refs.circularProgress.performLinearAnimation(100, 8000); // Will fill the progress bar linearly in 8 seconds

Configuration

您可以通过以下道具配置传递:

  • size – width and height of the circle
  • width - thickness of the line
  • fill - current, percentage fill (from 0 to 100)
  • prefill - percentage fill before the animation (from 0 to 100)
  • tintColor - color of a progress line
  • backgroundColor - color of a background for progress line
  • rotation - by default, progress starts from the angle = 90⦝, you can change it by setting value from -360 to 360
  • tension - the tension value for the spring animation (see here)
  • friction - the friction value for the spring animation (see here)
  • linecap - the shape to be used at the ends of the circle. Possible values: butt (default), round or square. (see here)
  • children(fill) - you can pass function as a child to receive current fill

Working example app

您可以在该存储库的 example 目录中找到工作示例。 您可以通过以下方式运行它:

iOS

git clone https://github.com/bgryszko/react-native-circular-progress.git
cd  react-native-circular-progress/example/ProgressChart
npm install
open ios/ProgressChart.xcodeproj

XCode 将打开。 单击“运行”按钮即可。

Android

打开您的模拟器并运行:

git clone https://github.com/bgryszko/react-native-circular-progress.git
cd  react-native-circular-progress/example/ProgressChart
npm install
react-native run-android

Author

Bartosz Gryszko (b@gryszko.com)

对于新组件和更新在 twitter 上关注我

License

MIT

Special thanks

特别感谢 Chalk+Chisel 创造了人们成长的工作环境。 该组件是为我们正在进行的项目之一创建的。

[license]() VersionnpmTwitter Follow

react-native-circular-progress

React Native component for creating animated, circular progress with ReactART. Useful for displaying users points for example. Works on iOS & Android.


Looking for a circular slider? Take a look at my other component – react-native-circular-slider :alarm_clock:


Example app

image

Installation

  1. Install library npm i --save react-native-circular-progress
  2. Link ART library to your ReactNative project (how to link a library?). You'll find ReactART library in node_modules/react-native/Libraries/ART/ART.xcodeproj

Usage

Import CircularProgress or AnimatedCircularProgress.

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

Use as follows:

<AnimatedCircularProgress
  size={120}
  width={15}
  fill={100}
  tintColor="#00e0ff"
  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 style={styles.points}>
        { this.state.fill }
      </Text>
    )
  }
</AnimatedCircularProgress>

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

<AnimatedCircularProgress
  ref='circularProgress'
  ...
/>
this.refs.circularProgress.performLinearAnimation(100, 8000); // Will fill the progress bar linearly in 8 seconds

Configuration

You can configure the passing by following props:

  • size – width and height of the circle
  • width - thickness of the line
  • fill - current, percentage fill (from 0 to 100)
  • prefill - percentage fill before the animation (from 0 to 100)
  • tintColor - color of a progress line
  • backgroundColor - color of a background for progress line
  • rotation - by default, progress starts from the angle = 90⦝, you can change it by setting value from -360 to 360
  • tension - the tension value for the spring animation (see here)
  • friction - the friction value for the spring animation (see here)
  • linecap - the shape to be used at the ends of the circle. Possible values: butt (default), round or square. (see here)
  • children(fill) - you can pass function as a child to receive current fill

Working example app

You can find working example in the example directory of this repository. You can run it by:

iOS

git clone https://github.com/bgryszko/react-native-circular-progress.git
cd  react-native-circular-progress/example/ProgressChart
npm install
open ios/ProgressChart.xcodeproj

XCode will open. Click Run button and that's it.

Android

Open your emulator and run:

git clone https://github.com/bgryszko/react-native-circular-progress.git
cd  react-native-circular-progress/example/ProgressChart
npm install
react-native run-android

Author

Bartosz Gryszko (b@gryszko.com)

For new components and updates follow me on twitter.

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.

    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文