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 22c22ed

Browse files
Add files via upload
1 parent d1d54c0 commit 22c22ed

File tree

1 file changed

+74
-0
lines changed

1 file changed

+74
-0
lines changed

‎lib/loader/OpacityDotsLoader.js

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

0 commit comments

Comments
(0)

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