-
Notifications
You must be signed in to change notification settings - Fork 9
/
emoji.js
45 lines (42 loc) · 1.01 KB
/
emoji.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
import React from 'react';
import { Animated } from 'react-native';
export function EmojiItem({ emoji, translateX, translateY, opacity, rotateZ }) {
const spinZ = rotateZ.interpolate({
inputRange: [0, 10],
outputRange: ['0deg', '360deg'],
});
const itemStyle = {
height: 18,
width: 18,
opacity,
transform: [
{ translateX },
{ translateY },
{ rotateZ: spinZ },
],
position: 'absolute',
};
return (
<Animated.View style={itemStyle}>
<Animated.Text>{emoji}</Animated.Text>
</Animated.View>
);
}
export function generateEmojiItems(translations, count = 20, emojis) {
const items = [];
for (let i = 0; i < count; i++) {
const { transform, opacity, rotateZ } = translations[i];
const item = (
<EmojiItem
key={i}
emoji={emojis[i % emojis.length]}
translateX={transform.x}
translateY={transform.y}
rotateZ={rotateZ}
opacity={opacity}
/>
);
items.push(item);
}
return items;
}