iamcal / emoji-data

Easy to parse data and spritesheets for emoji
MIT License
2.56k stars 301 forks source link

Wrong emojis #199

Closed pedrohenriquebraga closed 2 years ago

pedrohenriquebraga commented 3 years ago

I'm converting the unified code with

String.fromCodePoint(parseInt(unified,  16))

and i'm getting this result (emojis wrong and/or duplicated), how fix it?

iamcal commented 3 years ago

Can you share some more of the code that you're using? That's just a fragment of pure JavaScript and doesn't use the data in this library at all.

pedrohenriquebraga commented 3 years ago

@iamcal

import _ from "lodash";
import emojiSource from "emoji-datasource";

const filteredEmojis = emojiSource.filter((e) => !e.obsoletes && !e.obsoleted_by);
const emojis = _.orderBy(filteredEmojis, "sort_order"))

// i'm passing the emoji unified code for this function

const codeToEmoji = (code: any) => {
    // code = unified
    return String.fromCodePoint(parseInt(code, 16));
}

it's my code, i'm using in React Native to create an Emoji Picker. This bug is occurring in android phone

(sorry my bad english)

iamcal commented 3 years ago

the issue is that the unified field does not just contain a single codepoint, for example "HASH KEY" has a value of "0023-FE0F-20E3". to make your code work correctly:

const codeToEmoji = (code: any) => {
    // code = unified
    var codes = code.split('-');
    var buffer = '';
    for (var i=0; i<codes.length; i++){
      buffer += String.fromCodePoint(parseInt(codes[i], 16));
    }
    return buffer;
}
pedrohenriquebraga commented 3 years ago

@iamcal This code works! But it generated another bug in some emojis (not all)

Screenshot_20210623-191232_Expo Go.jpg

It was like the emojis had separated

iamcal commented 3 years ago

It looks like the native rendering method you're using is unable to support certain codepoints, so they're appearing as their fallback (which is a sequence of images).

pedrohenriquebraga commented 3 years ago

@iamcal is there any way to solve this?

iamcal commented 3 years ago

I'm not sure what you're trying to do.

This project is a library of data to use in other applications. You should probably start with something higher level that's closer to whatever you're trying to accomplish. Maybe this is closer to what you're looking for: https://github.com/iamcal/js-emoji