-
Notifications
You must be signed in to change notification settings - Fork 2.9k
/
EmojiSkinToneList.js
80 lines (71 loc) · 3.51 KB
/
EmojiSkinToneList.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
import _ from 'underscore';
import React, {useState, useCallback} from 'react';
import {View} from 'react-native';
import PropTypes from 'prop-types';
import styles from '../../styles/styles';
import * as Emojis from '../../../assets/emojis';
import withLocalize, {withLocalizePropTypes} from '../withLocalize';
import Text from '../Text';
import EmojiPickerMenuItem from './EmojiPickerMenuItem';
import getSkinToneEmojiFromIndex from './getSkinToneEmojiFromIndex';
import PressableWithoutFeedback from '../Pressable/PressableWithoutFeedback';
import CONST from '../../CONST';
const propTypes = {
/** Stores user's preferred skin tone */
preferredSkinTone: PropTypes.oneOfType([PropTypes.number, PropTypes.string]).isRequired,
/** Function to sync the selected skin tone with parent, onyx and nvp */
updatePreferredSkinTone: PropTypes.func.isRequired,
/** Props related to translation */
...withLocalizePropTypes,
};
function EmojiSkinToneList(props) {
const [highlightedIndex, setHighlightedIndex] = useState(null);
const [isSkinToneListVisible, setIsSkinToneListVisible] = useState(false);
const toggleIsSkinToneListVisible = useCallback(() => {
setIsSkinToneListVisible((prev) => !prev);
}, []);
/**
* Pass the skinTone to props and hide the picker
* @param {object} skinToneEmoji
*/
function updateSelectedSkinTone(skinToneEmoji) {
toggleIsSkinToneListVisible();
setHighlightedIndex(skinToneEmoji.skinTone);
props.updatePreferredSkinTone(skinToneEmoji.skinTone);
}
const currentSkinTone = getSkinToneEmojiFromIndex(props.preferredSkinTone);
return (
<View style={[styles.flexRow, styles.p3, styles.ph4, styles.emojiPickerContainer]}>
{!isSkinToneListVisible && (
<PressableWithoutFeedback
onPress={toggleIsSkinToneListVisible}
style={[styles.flex1, styles.flexRow, styles.alignSelfCenter, styles.justifyContentStart, styles.alignItemsCenter]}
accessibilityLabel={props.translate('emojiPicker.skinTonePickerLabel')}
accessibilityRole={CONST.ACCESSIBILITY_ROLE.BUTTON}
>
<View style={[styles.emojiItem, styles.justifyContentCenter]}>
<Text style={[styles.emojiText, styles.ph2, styles.textNoWrap]}>{currentSkinTone.code}</Text>
</View>
<Text style={[styles.emojiSkinToneTitle]}>{props.translate('emojiPicker.skinTonePickerLabel')}</Text>
</PressableWithoutFeedback>
)}
{isSkinToneListVisible && (
<View style={[styles.flexRow, styles.flex1]}>
{_.map(Emojis.skinTones, (skinToneEmoji) => (
<EmojiPickerMenuItem
onPress={() => updateSelectedSkinTone(skinToneEmoji)}
onHoverIn={() => setHighlightedIndex(skinToneEmoji.skinTone)}
onHoverOut={() => setHighlightedIndex(null)}
key={skinToneEmoji.code}
emoji={skinToneEmoji.code}
isHighlighted={skinToneEmoji.skinTone === highlightedIndex || skinToneEmoji.skinTone === currentSkinTone.skinTone}
/>
))}
</View>
)}
</View>
);
}
EmojiSkinToneList.propTypes = propTypes;
EmojiSkinToneList.displayName = 'EmojiSkinToneList';
export default withLocalize(EmojiSkinToneList);