Update React-based emoji handling to fix skin tone modifiers (#2399)

This commit is contained in:
Scott Nonnenberg 2018-05-23 12:17:25 -07:00 committed by GitHub
parent 4f1df7377f
commit a328a70ba2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 25 additions and 28 deletions

View file

@ -48,46 +48,39 @@ export function getSizeClass(str: string) {
} }
} }
const VARIATION_LOOKUP: { [index: string]: string } = {
'\uD83C\uDFFB': '1f3fb',
'\uD83C\uDFFC': '1f3fc',
'\uD83C\uDFFD': '1f3fd',
'\uD83C\uDFFE': '1f3fe',
'\uD83C\uDFFF': '1f3ff',
};
// Taken from emoji-js/replace_unified // Taken from emoji-js/replace_unified
function getEmojiReplacementData( function getEmojiReplacementData(
m: string, m: string,
p1: string | undefined, p1: string | undefined,
p2: string | undefined p2: string | undefined
) { ) {
let val = instance.map.unified[p1]; const unified = instance.map.unified[p1];
if (val) { if (unified) {
let idx = null; const variation = VARIATION_LOOKUP[p2 || ''];
if (p2 === '\uD83C\uDFFB') { if (variation) {
idx = '1f3fb';
}
if (p2 === '\uD83C\uDFFC') {
idx = '1f3fc';
}
if (p2 === '\uD83C\uDFFD') {
idx = '1f3fd';
}
if (p2 === '\uD83C\uDFFE') {
idx = '1f3fe';
}
if (p2 === '\uD83C\uDFFF') {
idx = '1f3ff';
}
if (idx) {
return { return {
idx, value: unified,
actual: p2, variation,
}; };
} }
return { return {
idx: val, value: unified,
}; };
} }
val = instance.map.unified_vars[p1]; const unifiedVars = instance.map.unified_vars[p1];
if (val) { if (unifiedVars) {
return { return {
idx: val[1], value: unifiedVars[0],
actual: '', variation: unifiedVars[1],
}; };
} }
@ -110,8 +103,8 @@ function getImageTag({
return <span key={key}>{match[0]}</span>; return <span key={key}>{match[0]}</span>;
} }
const img = instance.find_image(result.idx); const img = instance.find_image(result.value, result.variation);
const title = instance.data[result.idx][3][0]; const title = instance.data[result.value][3][0];
return ( return (
<img <img

View file

@ -30,6 +30,10 @@
<MessageBody text="🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥" /> <MessageBody text="🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥" />
``` ```
```jsx
<MessageBody text="With skin color modifier: 👍🏾" />
```
### Text and emoji ### Text and emoji
```jsx ```jsx