-
Notifications
You must be signed in to change notification settings - Fork 785
/
Copy pathloading-animation.js
69 lines (58 loc) · 1.48 KB
/
loading-animation.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
import { Animated } from 'react-native';
import React from 'react';
export const loadingAnimation = state => {
const duration = 500;
const iterations = 10;
let opacity1 = 0.3;
let opacity2 = 0.7;
const animatedTimings = [];
for (let i = 0; i < iterations; i += 1) {
animatedTimings.push(
Animated.timing(state, { toValue: opacity1, duration })
);
const tempFrom = opacity2;
opacity2 = opacity1;
opacity1 = tempFrom;
}
return Animated.sequence(animatedTimings);
};
export const withFadeAnimation = WrappedComponent => {
return class extends React.Component {
constructor(props) {
super(props);
this.fadeFrom = 0.3;
this.fadeTo = 0.6;
this.state = {
fadeAnimValue: new Animated.Value(this.fadeTo),
};
}
componentDidMount() {
this.runAnimation();
}
runAnimation() {
const animatedTimings = [];
const duration = 1000;
animatedTimings.push(
Animated.timing(this.state.fadeAnimValue, {
toValue: this.fadeFrom,
duration,
})
);
animatedTimings.push(
Animated.timing(this.state.fadeAnimValue, {
toValue: this.fadeTo,
duration,
})
);
return Animated.sequence(animatedTimings).start(() => {
this.runAnimation();
});
}
render() {
return <WrappedComponent opacity={this.state.fadeAnimValue} />;
}
};
};
export type FadeAnimationProps = {
opacity: number,
};