Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
require('string.fromcodepoint');
// i dont understand ANY of this but there's somethign called codepoints and surrogate pairs
// and this converts utf16 to a charachter in javascript. see more here:
//https://mathiasbynens.be/notes/javascript-unicode
//https://mathiasbynens.be/notes/javascript-escapes#unicode-code-point
//https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/fromCodePoint
const charFromUtf16 = utf16 => String.fromCodePoint(...utf16.split('-').map(u => '0x' + u))
const charFromEmojiObj = obj => charFromUtf16(obj.unified)
const blacklistedEmojis = ['white_frowning_face', 'keycap_star', 'eject']
const isAndroid = Platform.OS == 'android'
const letterSpacing = 10
const defaultEmojiSize = 30
const padding = 5
const filteredEmojis = emoji.filter(e => isAndroid ? !!e.google : !includes(blacklistedEmojis, e.short_name))
// sort emojis by 'sort_order' then group them into categories
const groupedAndSorted = groupBy(orderBy(filteredEmojis, 'sort_order'), 'category')
// convert the emoji object to a character
const emojisByCategory = mapValues(groupedAndSorted, group => group.map(charFromEmojiObj))
const CATEGORIES = ['People', 'Nature', 'Foods', 'Activity', 'Places', 'Objects', 'Symbols', 'Flags']
class EmojiPicker extends React.Component {
state = {
categories: CATEGORIES.slice(0, 1),
}
componentWillUnmount() {
clearTimeout(this._timeout)
}
if (c !== 'all') return (
{}}
/>
)
});
} else {
let list;
let hasSearchQuery = this.state.searchQuery !== '';
if (hasSearchQuery)
list = emoji.filter(e => {
// TODO: Use the short_names array instead of singular short_name
return e.short_name.includes(this.state.searchQuery.toLowerCase())
});
else
list = emojiByCategory(this.state.category.name);
return (
{}}
/>
);
}
name: 'Objects',
},
icons: {
icon: 'emojiSymbols',
name: 'Symbols',
},
flags: {
icon: 'emojiFlags',
name: 'Flags',
},
};
const charFromUtf16 = utf16 =>
String.fromCodePoint(...utf16.split('-').map(u => '0x' + u));
export const charFromEmojiObject = obj => charFromUtf16(obj.unified);
const filteredEmojis = emoji.filter(e => !e['obsoleted_by']);
const emojiByCategory = category =>
filteredEmojis.filter(e => e.category === category);
const sortEmoji = list => list.sort((a, b) => a.sort_order - b.sort_order);
const { width } = Dimensions.get('screen');
const categoryKeys = Object.keys(Categories);
const TabBar = ({ theme, activeCategory, onPress }) => {
return categoryKeys.map(c => {
const category = Categories[c];
if (c !== 'all')
return (
//TODO: OPTIMIZE THIS
let largeList = [];
categoryKeys.forEach(c => {
const name = Categories[c].name;
const list =
name === Categories.history.name ? history : emojiList[name];
if (c !== 'all' && c !== 'history') largeList = largeList.concat(list);
});
return largeList.map(emoji => ({ key: emoji.unified, emoji }));
} else {
let list;
const hasSearchQuery = searchQuery !== '';
const name = category.name;
if (hasSearchQuery) {
const filtered = emoji.filter(e => {
let display = false;
e.short_names.forEach(name => {
if (name.includes(searchQuery.toLowerCase())) display = true;
});
return display;
});
list = sortEmoji(filtered);
} else {
list = emojiList[name];
}
return list.map(emoji => ({ key: emoji.unified, emoji }));
}
}
let largeList = [];
categoryKeys.forEach(c => {
const name = Categories[c].name;
const list = name === Categories.history.name ? history : emojiList[name]
if (c !== 'all' && c !== 'history')
largeList = largeList.concat(list);
});
return (largeList.map(emoji => ({ key: emoji.unified, emoji })))
} else {
let list;
const hasSearchQuery = searchQuery !== '';
const name = category.name;
if (hasSearchQuery) {
const filtered = emoji.filter(e => {
let display = false;
e.short_names.forEach(name => {
if(name.includes(searchQuery.toLowerCase())) display = true;
})
return display;
});
list = sortEmoji(filtered);
} else if (name === Categories.history.name) {
list = history
} else {
list = emojiList[name];
}
return (list.map(emoji => ({ key: emoji.unified, emoji })))
}
}
_classify() {
let filteredData = emojiData.filter(e=> !_.includes(filters, e.short_name));
let sortedData = _.orderBy(filteredData, 'sort_order');
let groupedData = _.groupBy(sortedData, 'category');
if (this.props.concise) {
filteredData = emojiData.filter(e=> _.includes(choiceness, e.short_name));
const temp = [];
_.mapKeys(filteredData, (value)=> {
temp.push({
code: this._charFromCode(value.unified),
name: value.short_name
});
});
_.each(choiceness, (value)=> {
const one = temp.filter(e=> _.includes([value], e.name));
if (one[0])
this.state.data.push(one[0]);
});
} else {
this.state.data = _.mapValues(groupedData, group => group.map((value)=> {
return {
code: this._charFromCode(value.unified),
//TODO: OPTIMIZE THIS
let largeList = [];
categoryKeys.forEach(c => {
const name = Categories[c].name;
const list =
name === Categories.history.name ? history : emojiList[name];
if (c !== "all" && c !== "history") largeList = largeList.concat(list);
});
return largeList.map(emoji => ({ key: emoji.unified, emoji }));
} else {
let list;
const hasSearchQuery = searchQuery !== "";
const name = category.name;
if (hasSearchQuery) {
const filtered = emoji.filter(e => {
let display = false;
e.short_names.forEach(name => {
if (name.includes(searchQuery.toLowerCase())) display = true;
});
return display;
});
list = sortEmoji(filtered);
} else if (name === Categories.history.name) {
list = history;
} else {
list = emojiList[name];
}
return list.map(emoji => ({ key: emoji.unified, emoji }));
}
}
_classify() {
let filteredData = emojiData.filter(e=> !_.includes(filters, e.short_name));
let sortedData = _.orderBy(filteredData, 'sort_order');
let groupedData = _.groupBy(sortedData, 'category');
if (this.props.concise) {
filteredData = emojiData.filter(e=> _.includes(choiceness, e.short_name));
const temp = [];
_.mapKeys(filteredData, (value)=> {
temp.push({
code: this._charFromCode(value.unified),
name: value.short_name
});
});
_.each(choiceness, (value)=> {
const one = temp.filter(e=> _.includes([value], e.name));
if (one[0])
this.state.data.push(one[0]);