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 666e616

Browse files
fix an issue of rotation loaders
1 parent 4666c32 commit 666e616

File tree

4 files changed

+220
-206
lines changed

4 files changed

+220
-206
lines changed

‎lib/loader/CirclesRotationScaleLoader.js

Lines changed: 91 additions & 89 deletions
Original file line numberDiff line numberDiff line change
@@ -6,100 +6,102 @@ import AnimatedCircle from '../animated/AnimatedCircle';
66
import { color } from '../const';
77

88
export default class RotationCircleLoader extends React.PureComponent {
9-
static propTypes = {
10-
size: PropTypes.number,
11-
color: PropTypes.string,
12-
};
9+
static propTypes = {
10+
size: PropTypes.number,
11+
color: PropTypes.string,
12+
};
1313

14-
static defaultProps = {
15-
size: 50,
16-
color,
17-
};
14+
static defaultProps = {
15+
size: 50,
16+
color,
17+
};
1818

19-
state = {
20-
degree: new Animated.Value(0),
21-
scales: [new Animated.Value(0), new Animated.Value(0)],
22-
};
23-
timers = [];
19+
state = {
20+
degree: new Animated.Value(0),
21+
scales: [new Animated.Value(0), new Animated.Value(0)]
22+
};
23+
timers = [];
2424

25-
componentDidMount() {
26-
this._animation();
27-
this.state.scales.forEach((item, i) => {
28-
const id = setTimeout(() => {
29-
this._animationCircles(i);
30-
}, i * 500);
31-
this.timers.push(id);
32-
});
33-
}
25+
componentDidMount() {
26+
this._animation();
27+
this.state.scales.forEach((item, i) => {
28+
const id = setTimeout(() => {
29+
this._animationCircles(i)
30+
}, i * 500);
31+
this.timers.push(id);
32+
});
3433

35-
componentWillUnmount() {
36-
this.unmounted = true;
37-
this.timers.forEach((id) => {
38-
clearTimeout(id);
39-
});
40-
}
34+
}
4135

42-
_animation = () => {
43-
Animated.sequence([
44-
Animated.timing(this.state.degree, {
45-
toValue: 360,
46-
duration: 2000,
47-
easing: Easing.linear,
48-
useNativeDriver: false,
49-
}),
50-
]).start(() => {
51-
if (!this.unmounted) {
52-
this.state.degree.setValue(0);
53-
this._animation();
54-
}
55-
});
56-
};
36+
componentWillUnmount() {
37+
this.unmounted = true;
38+
this.timers.forEach((id) => {
39+
clearTimeout(id);
40+
});
41+
}
5742

58-
_animationCircles = (i) => {
59-
Animated.sequence([
60-
Animated.timing(this.state.scales[i], { toValue: 1, duration: 1000, useNativeDriver: false }),
61-
Animated.timing(this.state.scales[i], {
62-
toValue: 0.05,
63-
duration: 1000,
64-
useNativeDriver: false,
65-
}),
66-
]).start(() => {
67-
!this.unmounted && this._animationCircles(i);
68-
});
69-
};
43+
_animation = () => {
44+
Animated.sequence([
45+
Animated.timing(this.state.degree, {
46+
toValue: 360,
47+
duration: 2000,
48+
easing: Easing.linear,
49+
useNativeDriver: false
50+
})
51+
]).start(() => {
52+
if (!this.unmounted) {
53+
this.state.degree.setValue(0);
54+
this._animation();
55+
}
56+
});
57+
};
7058

71-
render() {
72-
const { size, color } = this.props;
73-
const degree = this.state.degree.interpolate({
74-
inputRange: [0, 360],
75-
outputRange: ['0deg', '360deg'],
76-
});
77-
return (
78-
<Animated.View
79-
style={{
80-
transform: [{ rotate: degree }],
81-
backgroundColor: 'rgba(0,0,0,0)',
82-
}}
83-
>
84-
<Surface width={size} height={size}>
85-
<Group>
86-
<AnimatedCircle
87-
fill={color}
88-
radius={size / 2}
89-
x={size / 2}
90-
y={size / 4}
91-
scale={this.state.scales[0]}
92-
/>
93-
<AnimatedCircle
94-
fill={color}
95-
radius={size / 2}
96-
x={size / 2}
97-
y={(size / 4) * 3}
98-
scale={this.state.scales[1]}
99-
/>
100-
</Group>
101-
</Surface>
102-
</Animated.View>
103-
);
104-
}
59+
_animationCircles = (i) => {
60+
Animated.sequence([
61+
Animated.timing(this.state.scales[i], { toValue: 1, duration: 1000, useNativeDriver: false }),
62+
Animated.timing(this.state.scales[i], {
63+
toValue: 0.05,
64+
duration: 1000,
65+
useNativeDriver: false
66+
}),
67+
]).start(() => {
68+
!this.unmounted && this._animationCircles(i);
69+
});
70+
};
71+
72+
render() {
73+
const { size, color } = this.props;
74+
const degree = this.state.degree.interpolate({
75+
inputRange: [0, 360],
76+
outputRange: ['0deg', '360deg']
77+
});
78+
return (
79+
<Animated.View
80+
style={{
81+
transform: [{ rotate: degree }],
82+
backgroundColor: 'rgba(0,0,0,0)',
83+
width: size,
84+
height: size
85+
}}>
86+
<Surface width={size} height={size}>
87+
<Group>
88+
<AnimatedCircle
89+
fill={color}
90+
radius={size / 2}
91+
x={size / 2}
92+
y={size / 4}
93+
scale={this.state.scales[0]}
94+
/>
95+
<AnimatedCircle
96+
fill={color}
97+
radius={size / 2}
98+
x={size / 2}
99+
y={size / 4 * 3}
100+
scale={this.state.scales[1]}
101+
/>
102+
</Group>
103+
</Surface>
104+
</Animated.View>
105+
);
106+
}
105107
}

‎lib/loader/RotationCircleLoader.js

Lines changed: 57 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -6,61 +6,67 @@ import AnimatedCircle from '../animated/AnimatedCircle';
66
import { color } from '../const';
77

88
export default class RotationCircleLoader extends React.PureComponent {
9-
static propTypes = {
10-
size: PropTypes.number,
11-
color: PropTypes.string,
12-
rotationSpeed: PropTypes.number,
13-
};
9+
static propTypes = {
10+
size: PropTypes.number,
11+
color: PropTypes.string,
12+
rotationSpeed: PropTypes.number
13+
};
1414

15-
static defaultProps = {
16-
size: 40,
17-
color,
18-
rotationSpeed: 800,
19-
};
15+
static defaultProps = {
16+
size: 40,
17+
color,
18+
rotationSpeed: 800
19+
};
2020

21-
state = {
22-
degree: new Animated.Value(0),
23-
};
21+
state = {
22+
degree: new Animated.Value(0)
23+
};
2424

25-
componentDidMount() {
26-
this._animation();
27-
}
25+
componentDidMount() {
26+
this._animation();
27+
}
2828

29-
componentWillUnmount() {
30-
this.unmounted = true;
31-
}
29+
componentWillUnmount() {
30+
this.unmounted = true;
31+
}
3232

33-
_animation = () => {
34-
Animated.sequence([
35-
Animated.timing(this.state.degree, {
36-
toValue: 360,
37-
duration: this.props.rotationSpeed,
38-
easing: Easing.linear,
39-
useNativeDriver: false,
40-
}),
41-
]).start(() => {
42-
if (!this.unmounted) {
43-
this.state.degree.setValue(0);
44-
this._animation();
45-
}
46-
});
47-
};
33+
_animation = () => {
34+
Animated.sequence([
35+
Animated.timing(this.state.degree, {
36+
toValue: 360,
37+
duration: this.props.rotationSpeed,
38+
easing: Easing.linear,
39+
useNativeDriver: false
40+
})
41+
]).start(() => {
42+
if (!this.unmounted) {
43+
this.state.degree.setValue(0);
44+
this._animation();
45+
}
46+
});
47+
};
4848

49-
render() {
50-
const { size, color } = this.props;
51-
const degree = this.state.degree.interpolate({
52-
inputRange: [0, 360],
53-
outputRange: ['0deg', '360deg'],
54-
});
55-
return (
56-
<Animated.View style={{ transform: [{ rotate: degree }], backgroundColor: 'rgba(0,0,0,0)' }}>
57-
<Surface width={size} height={size}>
58-
<Group>
59-
<AnimatedCircle fill={color} radius={size} x={size / 2} y={size / 2} />
60-
<AnimatedCircle fill="#fff" radius={size / 4} x={size / 2} y={size / 8} />
61-
</Group>
62-
</Surface>
63-
</Animated.View>
64-
);
65-
}
49+
render() {
50+
const { size, color } = this.props;
51+
const degree = this.state.degree.interpolate({
52+
inputRange: [0, 360],
53+
outputRange: ['0deg', '360deg']
54+
});
55+
return (
56+
<Animated.View
57+
style={{
58+
transform: [{ rotate: degree }],
59+
backgroundColor: 'rgba(0,0,0,0)',
60+
width: size,
61+
height: size
62+
}}>
63+
<Surface width={size} height={size}>
64+
<Group>
65+
<AnimatedCircle fill={color} radius={size} x={size / 2} y={size / 2}/>
66+
<AnimatedCircle fill="#fff" radius={size / 4} x={size / 2} y={size / 8}/>
67+
</Group>
68+
</Surface>
69+
</Animated.View>
70+
);
71+
}
6672
}

0 commit comments

Comments
(0)

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