-
Notifications
You must be signed in to change notification settings - Fork 14
/
index.js
81 lines (73 loc) · 2.09 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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
import React, { PropTypes } from 'react';
import { View, ScrollView, Text, TouchableOpacity } from 'react-native';
import emoji from './data';
const EmojiItem = ({ size, item, onPress }) => (
<TouchableOpacity style={{ flex: 0, height: size, width: size }} onPress={onPress}>
<View style={{ flex: 0, height: size, width: size }}>
<Text style={{ flex: 0, fontSize: size / 4 * 3, paddingBottom: 2 }}>
{item}
</Text>
</View>
</TouchableOpacity>
);
const EmojiCategory = ({ headerStyle, emojiSize, name, items, onPick }) => (
<View style={styles.category}>
<Text style={{ ...styles.categoryName, ...headerStyle }}>{name}</Text>
<View style={styles.categoryItems}>
{items.map((em, idx) => (
<EmojiItem key={idx} size={emojiSize} onPress={() => onPick(em)} item={em} />
))}
</View>
</View>
);
const EmojiPicker = ({ headerStyle, containerHeight, containerBackgroundColor, emojiSize, onPick }) => (
<View style={{ ...styles.picker, height: containerHeight, backgroundColor: containerBackgroundColor }}>
<ScrollView horizontal={true}>
{emoji.map((category, idx) => (
<EmojiCategory
key={idx}
headerStyle={headerStyle}
emojiSize={emojiSize}
name={category.category}
items={category.items}
onPick={onPick}
/>
))}
</ScrollView>
</View>
);
EmojiPicker.propTypes = {
onPick: PropTypes.func,
headerStyle: PropTypes.object,
containerHeight: PropTypes.number.isRequired,
containerBackgroundColor: PropTypes.string.isRequired,
emojiSize: PropTypes.number.isRequired,
};
EmojiPicker.defaultProps = {
containerHeight: 240,
containerBackgroundColor: 'rgba(0, 0, 0, 0.1)',
emojiSize: 40,
};
const styles = {
picker: {
flex: 0,
borderTopWidth: 1,
borderTopColor: "#ddd",
},
category: {
flex: 0,
paddingHorizontal: 14,
paddingTop: 2,
},
categoryName: {
paddingVertical: 8,
paddingHorizontal: 4,
fontSize: 12,
color: "#888",
},
categoryItems: {
flex: 1,
flexWrap: 'wrap',
},
};
export default EmojiPicker;