-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathindex.js
66 lines (55 loc) · 1.39 KB
/
index.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
import React, { Component } from "react";
import { StyleSheet, Animated } from "react-native";
import { GradientHelper } from "./gradient-helper";
const styles = StyleSheet.create({
component: {
flex: 1
}
});
const AnimatedGradientHelper = Animated.createAnimatedComponent(GradientHelper);
export class AnimatedGradient extends Component {
constructor(props) {
super(props);
const { colors } = props;
this.state = {
prevColors: colors,
colors,
tweener: new Animated.Value(0)
};
}
static getDerivedStateFromProps(props, state) {
const { colors: prevColors } = state;
const { colors } = props;
const tweener = new Animated.Value(0);
return {
prevColors,
colors,
tweener
};
}
componentDidUpdate() {
const { tweener } = this.state;
Animated.timing(tweener, {
toValue: 1
}).start();
}
render() {
const { tweener, prevColors, colors } = this.state;
const { style } = this.props;
const color1Interp = tweener.interpolate({
inputRange: [0, 1],
outputRange: [prevColors[0], colors[0]]
});
const color2Interp = tweener.interpolate({
inputRange: [0, 1],
outputRange: [prevColors[1], colors[1]]
});
return (
<AnimatedGradientHelper
style={style || styles.component}
color1={color1Interp}
color2={color2Interp}
/>
);
}
}