refactor: add unicode version, slug and reduce json size

This commit is contained in:
Jakub Grzywacz 2021-07-22 11:42:45 +02:00
parent db04194152
commit bdb8799fe1
No known key found for this signature in database
GPG Key ID: 5BBB685871FF63C4
6 changed files with 22 additions and 10 deletions

View File

@ -25,6 +25,7 @@ export default function App() {
"emoji": "❤️",
"name": "red heart",
"slug": "red_heart",
"unicode_version": "0.6",
}
*/
};

View File

@ -6,7 +6,7 @@ for (const [key, value] of Object.entries(json)) {
const newData = value.map((emoji) => ({
emoji: emoji.emoji,
name: emoji.name,
slug: emoji.slug,
v: emoji.unicode_version,
}));
newArray.push({
title: key.replace(' & ', '_').replace(' ', '_').toLocaleLowerCase(),

File diff suppressed because one or more lines are too long

View File

@ -1,7 +1,7 @@
import * as React from 'react';
import { StyleSheet, View, Text, FlatList } from 'react-native';
import type { EmojisByCategory, EmojiType } from '../types';
import type { EmojisByCategory, EmojiType, JsonEmoji } from '../types';
import { SingleEmoji } from './SingleEmoji';
import { KeyboardContext } from '../KeyboardContext';
@ -9,9 +9,7 @@ const emptyEmoji = {
emoji: '',
name: 'blank emoji',
slug: 'blank_emoji',
skin_tone_support: false,
unicode_version: '0',
emoji_version: '0',
};
export const EmojiCategory = ({
@ -46,11 +44,18 @@ export const EmojiCategory = ({
index,
});
const parseEmoji = (emoji: JsonEmoji) => ({
name: emoji.name,
emoji: emoji.emoji,
unicode_version: emoji.v,
slug: emoji.name.replace(' ', '_'),
});
const renderItem = React.useCallback(
(props) => (
<SingleEmoji
{...props}
onPress={() => onEmojiSelected(props.item)}
onPress={() => onEmojiSelected(parseEmoji(props.item))}
emojiSize={emojiSize}
/>
),

View File

@ -1,10 +1,10 @@
import * as React from 'react';
import { View, Text, TouchableOpacity, StyleSheet } from 'react-native';
import type { EmojiType } from '../types';
import type { JsonEmoji } from '../types';
export class SingleEmoji extends React.Component<{
item: EmojiType;
onPress: (emojiObject: EmojiType) => void;
item: JsonEmoji;
onPress: () => void;
emojiSize: number;
}> {
shouldComponentUpdate() {
@ -13,7 +13,7 @@ export class SingleEmoji extends React.Component<{
render() {
const { item, emojiSize, onPress } = this.props;
return (
<TouchableOpacity onPress={() => onPress(item)} style={styles.container}>
<TouchableOpacity onPress={() => onPress()} style={styles.container}>
<View style={styles.iconContainer}>
<Text style={{ fontSize: emojiSize }}>{item.emoji}</Text>
</View>

View File

@ -1,7 +1,13 @@
export type JsonEmoji = {
emoji: string;
name: string;
v: string;
};
export type EmojiType = {
emoji: string;
name: string;
slug: string;
unicode_version: string;
};
export type CategoryTypes =