Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit f16bd0b

Browse files
add color dots loader
1 parent 95698a9 commit f16bd0b

File tree

4 files changed

+136
-1
lines changed

4 files changed

+136
-1
lines changed

‎README.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ Here is currently available types:
4949
- [CirclesRotationScaleLoader](#CirclesRotationScaleLoader)
5050
- [NineCubesLoader](#NineCubesLoader)
5151
- [LineDotsLoader](#LineDotsLoader)
52+
- [ColorDotsLoader](#ColorDotsLoader)
5253

5354
```
5455
render(){
@@ -241,6 +242,19 @@ render(){
241242
| dotsNumber | number | 5 | the number of dots |
242243
| betweenSpace | number | 5 | distance between two dots |
243244

245+
246+
<a name="ColorDotsLoader" />
247+
248+
##### ColorDotsLoader
249+
250+
| prop | type | default | description |
251+
| ---- | ---- | ---- | ---- |
252+
| size | number | 15 | each cube's size |
253+
| betweenSpace | number | 7 | distance between two dots |
254+
| color1 | string | '#ff4500'(red) | 1st color |
255+
| color2 | string | '#ffd700'(yellow) | 2nd color |
256+
| color3 | string | '#9acd32'(green) | 3rd color |
257+
244258
## License
245259

246260
MIT

‎index.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import CirclesRotationScale from './lib/loader/CirclesRotationScaleLoader';
2020
//import Square from './lib/loader/SquareLoader';
2121
import NineCubes from './lib/loader/NineCubesLoader';
2222
import LineDots from './lib/loader/LineDotsLoader';
23+
import ColorDots from './lib/loader/ColorDotsLoader';
2324

2425
export const PulseLoader = Pulse;
2526
export const DotsLoader = Dots;
@@ -37,4 +38,5 @@ export const RotationHoleLoader = RotationHole;
3738
export const CirclesRotationScaleLoader = CirclesRotationScale;
3839
//export const SquareLoader = Square;
3940
export const NineCubesLoader = NineCubes;
40-
export const LineDotsLoader = LineDots;
41+
export const LineDotsLoader = LineDots;
42+
export const ColorDotsLoader = ColorDots;

‎lib/loader/ColorDotsLoader.js

Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
/**
2+
* Created by wangdi on 24/12/16.
3+
*/
4+
'use strict';
5+
6+
import React, {Component, PropTypes} from 'react';
7+
import {Animated, ART, Easing} from 'react-native';
8+
const {Surface, Group} = ART;
9+
import AnimatedCircle from '../animated/AnimatedCircle';
10+
11+
export default class ColorDotsLoader extends Component {
12+
static propTypes = {
13+
size: PropTypes.number,
14+
betweenSpace: PropTypes.number,
15+
color1: PropTypes.string,
16+
color2: PropTypes.string,
17+
color3: PropTypes.string
18+
};
19+
20+
static defaultProps = {
21+
size: 15,
22+
betweenSpace: 7,
23+
color1: '#ff4500',
24+
color2: '#ffd700',
25+
color3: '#9acd32'
26+
};
27+
28+
constructor(props) {
29+
super(props);
30+
const red = this.props.color1;
31+
const yellow = this.props.color2;
32+
const green = this.props.color3;
33+
this.state = {
34+
colors: [red, red, red],
35+
color: yellow,
36+
x: new Animated.Value(-this.props.size / 2)
37+
};
38+
this.patterns = [
39+
[yellow, red, red],
40+
[yellow, yellow, red],
41+
[yellow, yellow, yellow],
42+
[green, yellow, yellow],
43+
[green, green, yellow],
44+
[green, green, green],
45+
[red, green, green],
46+
[red, red, green],
47+
[red, red, red],
48+
];
49+
this._animation = this._animation.bind(this);
50+
this.timers = [];
51+
}
52+
53+
render() {
54+
const {size, betweenSpace} = this.props;
55+
return (
56+
<Surface width={size*3 + betweenSpace*2} height={size}>
57+
<Group>
58+
{this.state.colors.map((item, i) => {
59+
return <AnimatedCircle key={i} fill={item} radius={size} x={size/2 + i * (size+betweenSpace)}
60+
y={size/2}/>
61+
})}
62+
<AnimatedCircle fill={this.state.color} radius={size} x={this.state.x} y={size/2}/>
63+
</Group>
64+
</Surface>
65+
);
66+
}
67+
68+
componentDidMount() {
69+
this._animation();
70+
}
71+
72+
componentWillUnmount(){
73+
this.unmounted = true;
74+
this.timers.forEach((id)=>{
75+
clearTimeout(id);
76+
});
77+
}
78+
79+
_animation() {
80+
const {size, betweenSpace, color1, color2, color3} = this.props;
81+
const id1 = setTimeout(()=>{this.setState({color: color3})}, 600);
82+
const id2 = setTimeout(()=>{this.setState({color: color1})}, 1200);
83+
this.timers.push(id1);
84+
this.timers.push(id2);
85+
this.patterns.forEach((item, i)=>{
86+
const id = setTimeout(()=>{
87+
this.setState({colors: this.patterns[i]});
88+
}, i*200+100);
89+
this.timers.push(id);
90+
});
91+
92+
Animated.sequence([
93+
Animated.timing(this.state.x, {
94+
toValue: size * 3 + betweenSpace * 2 + size / 2,
95+
duration: 600,
96+
easing: Easing.linear}),
97+
Animated.timing(this.state.x, {
98+
toValue: -size / 2,
99+
duration: 0}),
100+
Animated.timing(this.state.x, {
101+
toValue: size * 3 + betweenSpace * 2 + size / 2,
102+
duration: 600,
103+
easing: Easing.linear}),
104+
Animated.timing(this.state.x, {
105+
toValue: -size / 2,
106+
duration: 0}),
107+
Animated.timing(this.state.x, {
108+
toValue: size * 3 + betweenSpace * 2 + size / 2,
109+
duration: 600,
110+
easing: Easing.linear})
111+
]).start(() => {
112+
if(!this.unmounted) {
113+
this.state.x.setValue(-size / 2);
114+
this.setState({color: color2});
115+
this._animation();
116+
}
117+
});
118+
}
119+
}

‎screenshot/ss4.gif

139 KB
Loading[フレーム]

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /