Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't extract skin from native emoji #673

Closed
Ethorsen opened this issue Aug 13, 2022 · 1 comment
Closed

Can't extract skin from native emoji #673

Ethorsen opened this issue Aug 13, 2022 · 1 comment

Comments

@Ethorsen
Copy link

Hi,

Following this #636 where I'm trying to migrate from emoji-mart v3

I'm trying to show an emoji based on its native version. I can't seem to figure how to get the skintone.

  1. If I use <em-emoji /> directly, it always print the no-skin-tone version (or skin = 1). I guess this is because you have to explicitly provide the skin to it.
    <em-emoji set="apple" native={"💑🏿"} /> // Will output "💑"

  2. If I use SearchIndex, it won't return the skin (whereas getEmojiDataFromNative used to do this)

const emojis = await SearchIndex.search("💑🏿");
console.log(emojis[0]);

Will output

id: "couple_with_heart"
keywords: (8) ['pair', 'love', 'like', 'affection', 'human', 'dating', 'valentines', 'marriage']
name: "Couple with Heart"
search: ",couple_with_heart,couple,with,heart,pair,love,like,affection,human,dating,valentines,marriage,💑,💑🏻,💑🏼,💑🏽,💑🏾,💑🏿"
skins: 
0: {unified: '1f491', native: '💑', x: 27, y: 7, shortcodes: ':couple_with_heart:'}
1: {unified: '1f491-1f3fb', native: '💑🏻', x: 27, y: 8, shortcodes: ':couple_with_heart::skin-tone-2:'}
2: {unified: '1f491-1f3fc', native: '💑🏼', x: 27, y: 9, shortcodes: ':couple_with_heart::skin-tone-3:'}
3: {unified: '1f491-1f3fd', native: '💑🏽', x: 27, y: 10, shortcodes: ':couple_with_heart::skin-tone-4:'}
4: {unified: '1f491-1f3fe', native: '💑🏾', x: 27, y: 11, shortcodes: ':couple_with_heart::skin-tone-5:'}
5: {unified: '1f491-1f3ff', native: '💑🏿', x: 27, y: 12, shortcodes: ':couple_with_heart::skin-tone-6:'}

Which does not tell me which skin was my native emoji.

@TranquilMarmot
Copy link
Contributor

We have this function that we use to get the skin tone out of a native emoji:

export const getEmojiSkinTone = (emoji: string): number | null => {
  // your editor may not render these, but they are skin tone modifiers
  // (copy and paste them into your browser to see)
  const skinTones = ['', '🏻', '🏼', '🏽', '🏾', '🏿'];

  let skin = null;

  skinTones.forEach(skinTone => {
    if (emoji.indexOf(skinTone) > 0) {
      skin = skinTones.indexOf(skinTone) + 1;
    }
  });

  return skin || 1;
};

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants