Skip to content

Commit

Permalink
Merge pull request #28589 from software-mansion-labs/ts-migration/emo…
Browse files Browse the repository at this point in the history
…ji-utils-lib
  • Loading branch information
francoisl authored Nov 7, 2023
2 parents 18ba46f + 082a210 commit 8f5007a
Show file tree
Hide file tree
Showing 8 changed files with 242 additions and 266 deletions.
25 changes: 13 additions & 12 deletions assets/emojis/common.js → assets/emojis/common.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import Smiley from '../images/emoji.svg';
import Flags from '../images/emojiCategoryIcons/flag.svg';
import FoodAndDrink from '../images/emojiCategoryIcons/hamburger.svg';
import Objects from '../images/emojiCategoryIcons/light-bulb.svg';
import Symbols from '../images/emojiCategoryIcons/peace-sign.svg';
import TravelAndPlaces from '../images/emojiCategoryIcons/plane.svg';
import AnimalsAndNature from '../images/emojiCategoryIcons/plant.svg';
import Activities from '../images/emojiCategoryIcons/soccer-ball.svg';
import FrequentlyUsed from '../images/history.svg';
import Smiley from '@assets/images/emoji.svg';
import Flags from '@assets/images/emojiCategoryIcons/flag.svg';
import FoodAndDrink from '@assets/images/emojiCategoryIcons/hamburger.svg';
import Objects from '@assets/images/emojiCategoryIcons/light-bulb.svg';
import Symbols from '@assets/images/emojiCategoryIcons/peace-sign.svg';
import TravelAndPlaces from '@assets/images/emojiCategoryIcons/plane.svg';
import AnimalsAndNature from '@assets/images/emojiCategoryIcons/plant.svg';
import Activities from '@assets/images/emojiCategoryIcons/soccer-ball.svg';
import FrequentlyUsed from '@assets/images/history.svg';
import {HeaderEmoji, PickerEmojis} from './types';

const skinTones = [
{
Expand All @@ -33,9 +34,9 @@ const skinTones = [
code: '🖐🏿',
skinTone: 0,
},
];
] as const;

const emojis = [
const emojis: PickerEmojis = [
{
header: true,
icon: Smiley,
Expand Down Expand Up @@ -7619,7 +7620,7 @@ const emojis = [
},
];

const categoryFrequentlyUsed = {
const categoryFrequentlyUsed: HeaderEmoji = {
header: true,
code: 'frequentlyUsed',
icon: FrequentlyUsed,
Expand Down
5 changes: 4 additions & 1 deletion assets/emojis/en.js → assets/emojis/en.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
const enEmojis = {
import {EmojisList} from './types';

/* eslint-disable @typescript-eslint/naming-convention */
const enEmojis: EmojisList = {
'😀': {
keywords: ['smile', 'happy', 'face', 'grin'],
},
Expand Down
5 changes: 4 additions & 1 deletion assets/emojis/es.js → assets/emojis/es.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
const esEmojis = {
import {EmojisList} from './types';

/* eslint-disable @typescript-eslint/naming-convention */
const esEmojis: EmojisList = {
'😀': {
name: 'sonriendo',
keywords: ['cara', 'divertido', 'feliz', 'sonrisa', 'cara sonriendo'],
Expand Down
41 changes: 0 additions & 41 deletions assets/emojis/index.js

This file was deleted.

35 changes: 35 additions & 0 deletions assets/emojis/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import emojis from './common';
import enEmojis from './en';
import esEmojis from './es';
import {Emoji} from './types';

type EmojiTable = Record<string, Emoji>;

const emojiNameTable = emojis.reduce<EmojiTable>((prev, cur) => {
const newValue = prev;
if (!('header' in cur) && cur.name) {
newValue[cur.name] = cur;
}
return newValue;
}, {});

const emojiCodeTableWithSkinTones = emojis.reduce<EmojiTable>((prev, cur) => {
const newValue = prev;
if (!('header' in cur)) {
newValue[cur.code] = cur;
}
if ('types' in cur && cur.types) {
cur.types.forEach((type) => {
newValue[type] = cur;
});
}
return newValue;
}, {});

const localeEmojis = {
en: enEmojis,
es: esEmojis,
} as const;

export {emojiNameTable, emojiCodeTableWithSkinTones, localeEmojis};
export {skinTones, categoryFrequentlyUsed, default} from './common';
19 changes: 19 additions & 0 deletions assets/emojis/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import {SvgProps} from 'react-native-svg';

type Emoji = {
code: string;
name: string;
types?: string[];
};

type HeaderEmoji = {
header: true;
icon: React.FC<SvgProps>;
code: string;
};

type PickerEmojis = Array<Emoji | HeaderEmoji>;

type EmojisList = Record<string, {keywords: string[]; name?: string}>;

export type {Emoji, HeaderEmoji, EmojisList, PickerEmojis};
5 changes: 4 additions & 1 deletion src/libs/EmojiTrie.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,14 @@ type LocalizedEmojis = Record<string, LocalizedEmoji>;
type Suggestion = {
code: string;
types?: string[];
name?: string;
name: string;
};

type EmojiMetaData = {
suggestions?: Suggestion[];
code?: string;
types?: string[];
name?: string;
};

Timing.start(CONST.TIMING.TRIE_INITIALIZATION);
Expand Down
Loading

0 comments on commit 8f5007a

Please sign in to comment.