-
Notifications
You must be signed in to change notification settings - Fork 1
/
GradientBubble.js
101 lines (95 loc) · 2.62 KB
/
GradientBubble.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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
import React from "react";
import { StyleSheet, Animated, Dimensions } from "react-native";
import LinearGradient from "react-native-linear-gradient";
const { width: deviceWidth, height: deviceHeight } = Dimensions.get("window");
const ballWidth = deviceWidth * 1.25;
const initialTop = -ballWidth * 0.1;
const initialLeft = -ballWidth * 0.2;
export default class extends React.Component {
constructor(props) {
super(props);
const { animatedValue, index } = this.props;
this.animatedBubbleTranslateYVal = animatedValue.interpolate({
inputRange: [
deviceWidth * (index - 1),
deviceWidth * (index - 0.25),
deviceWidth * index,
deviceWidth * (index + 0.25),
deviceWidth * (index + 1)
],
outputRange: [
deviceHeight - ballWidth / 2,
initialTop - 40,
initialTop,
initialTop - 40,
deviceHeight - ballWidth / 2
]
});
this.animatedBubbleTranslateXVal = animatedValue.interpolate({
inputRange: [
deviceWidth * (index - 1),
deviceWidth * index,
deviceWidth * (index + 1)
],
outputRange: [
initialLeft + (deviceWidth + initialLeft),
initialLeft,
initialLeft
]
});
this.animatedBubbleScaleVal = animatedValue.interpolate({
inputRange: [
deviceWidth * (index - 1),
deviceWidth * (index - 0.4),
deviceWidth * index,
deviceWidth * (index + 0.4),
deviceWidth * (index + 1)
],
outputRange: [
48 / ballWidth,
48 / ballWidth,
1.5,
48 / ballWidth,
48 / ballWidth
]
});
}
render() {
const {
gradientData: { colors, locations }
} = this.props;
return (
<Animated.View
style={{
position: "absolute",
top: initialTop,
left: initialLeft,
width: ballWidth,
height: ballWidth,
transform: [
{ translateX: this.animatedBubbleTranslateXVal },
{ translateY: this.animatedBubbleTranslateYVal }
]
}}
>
<Animated.View
style={{
transform: [{ scale: this.animatedBubbleScaleVal }],
width: ballWidth,
height: ballWidth,
borderRadius: ballWidth / 2,
overflow: "hidden"
}}
>
<LinearGradient
colors={colors}
locations={locations}
start={{ x: 0.0, y: 1.0 }}
end={{ x: 1.0, y: 0.0 }}
style={StyleSheet.absoluteFillObject}
/>
</Animated.View>
</Animated.View>
);
}
}