Skip to content

Commit 3dc761f

Browse files
committed
doubleCircle loader
1 parent e86c95f commit 3dc761f

File tree

7 files changed

+98
-15
lines changed

7 files changed

+98
-15
lines changed

.idea/workspace.xml

Lines changed: 6 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

README.md

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ A useful indicator component for React Native
66

77
<img src="/screenshot/ss1.gif" width="372" height="666" />
88
<img src="/screenshot/ss2.gif" width="372" height="666" />
9+
<img src="/screenshot/ss3.gif" width="372" height="666" />
910

1011
## Installation
1112

@@ -41,6 +42,7 @@ Here is currently available types:
4142
- LinesLoader
4243
- MusicBarLoader
4344
- EatBeanLoader
45+
- DoubleCircleLoader
4446

4547
```
4648
render(){
@@ -59,8 +61,9 @@ render(){
5961

6062
| prop | type | default | description |
6163
| ---- | ---- | ---- | ---- |
62-
| size | number | 10 | circle's size |
64+
| size | number | 30 | circle's size |
6365
| color | string | '#1e90ff' | the indicator's color |
66+
| frequency | number | 500 | scale's frequency |
6467

6568

6669
##### DotsLoader
@@ -146,6 +149,14 @@ render(){
146149
| size | number | 30 | the indicator's size |
147150

148151

152+
##### DoubleCircleLoader
153+
154+
| prop | type | default | description |
155+
| ---- | ---- | ---- | ---- |
156+
| size | number | 30 | circle's size |
157+
| color | string | '#1e90ff' | the indicator's color |
158+
159+
149160
## License
150161

151162
MIT

index.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import Breathing from './lib/loader/BreathingLoader';
1313
import Lines from './lib/loader/LinesLoader';
1414
import Music from './lib/loader/MusicLoader';
1515
import EatBean from './lib/loader/EatBeanLoader';
16+
import DoubleCircle from './lib/loader/DoubleCircleLoader';
1617

1718
export const PulseLoader = Pulse;
1819
export const DotsLoader = Dots;
@@ -23,4 +24,5 @@ export const RippleLoader = Ripple;
2324
export const BreathingLoader = Breathing;
2425
export const LinesLoader = Lines;
2526
export const MusicBarLoader = Music;
26-
export const EatBeanLoader = EatBean;
27+
export const EatBeanLoader = EatBean;
28+
export const DoubleCircleLoader = DoubleCircle;

lib/loader/DoubleCircleLoader.js

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
/**
2+
* Created by wangdi on 15/12/16.
3+
*/
4+
'use strict';
5+
6+
import React, {Component, PropTypes} from 'react';
7+
import {Animated, ART} from 'react-native';
8+
const {Surface} = ART;
9+
import AnimatedCircle from '../animated/AnimatedCircle';
10+
11+
export default class DoubleCircleLoader extends Component {
12+
static propTypes = {
13+
color: PropTypes.string,
14+
size: PropTypes.number
15+
};
16+
17+
static defaultProps = {
18+
color: '#1e90ff',
19+
size: 30
20+
};
21+
22+
constructor(props) {
23+
super(props);
24+
this.state = {
25+
scales: [new Animated.Value(0), new Animated.Value(0)]
26+
};
27+
this._animation = this._animation.bind(this);
28+
this.timers = [];
29+
}
30+
31+
render() {
32+
const {color, size} = this.props;
33+
return (
34+
<Surface width={size} height={size}>
35+
<AnimatedCircle radius={size} fill={color} opacity={0.5}
36+
scale={this.state.scales[0]} x={size/2} y={size/2}/>
37+
<AnimatedCircle radius={size} fill={color} opacity={0.5}
38+
scale={this.state.scales[1]} x={size/2} y={size/2}/>
39+
</Surface>
40+
);
41+
}
42+
43+
componentDidMount() {
44+
this.state.scales.forEach((item, i) => {
45+
const id = setTimeout(() => {
46+
this._animation(i);
47+
}, i * 1000);
48+
this.timers.push(id);
49+
});
50+
}
51+
52+
componentWillUnmount() {
53+
this.unmounted = true;
54+
this.timers.forEach((id) => {
55+
clearTimeout(id);
56+
});
57+
}
58+
59+
_animation(i) {
60+
Animated.sequence([
61+
Animated.timing(this.state.scales[i], {toValue: 1, duration: 1000}),
62+
Animated.timing(this.state.scales[i], {toValue: 0, duration: 1000})
63+
]).start(() => {
64+
if (!this.unmounted)
65+
this._animation(i);
66+
});
67+
}
68+
}

lib/loader/PulseLoader.js

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,14 @@ import AnimatedCircle from '../animated/AnimatedCircle';
1212
export default class PulseLoader extends Component {
1313
static propTypes = {
1414
color: PropTypes.string,
15-
size: PropTypes.number
15+
size: PropTypes.number,
16+
frequency: PropTypes.number
1617
};
1718

1819
static defaultProps = {
1920
color: '#1e90ff',
20-
size: 10
21+
size: 30,
22+
frequency: 500
2123
};
2224

2325
constructor(props) {
@@ -31,8 +33,8 @@ export default class PulseLoader extends Component {
3133
render() {
3234
const {color, size} = this.props;
3335
return (
34-
<Surface width={size*2} height={size*2}>
35-
<AnimatedCircle radius={size} fill={color} scale={this.state.scale} x={size} y={size}/>
36+
<Surface width={size} height={size}>
37+
<AnimatedCircle radius={size} fill={color} scale={this.state.scale} x={size/2} y={size/2}/>
3638
</Surface>
3739
);
3840
}
@@ -47,8 +49,8 @@ export default class PulseLoader extends Component {
4749

4850
_animation() {
4951
Animated.sequence([
50-
Animated.timing(this.state.scale, {toValue: 0.2}),
51-
Animated.timing(this.state.scale, {toValue: 1})
52+
Animated.timing(this.state.scale, {toValue: 0.2, duration: this.props.frequency}),
53+
Animated.timing(this.state.scale, {toValue: 1, duration: this.props.frequency})
5254
]).start(() => {
5355
if (!this.unmounted)
5456
this._animation();

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "react-native-indicator",
3-
"version": "0.4.5",
3+
"version": "0.4.7",
44
"description": "React Native Indicator Component",
55
"main": "index.js",
66
"scripts": {

screenshot/ss3.gif

42.3 KB
Loading

0 commit comments

Comments
 (0)