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

Doesn't work with iOS emojis #98

Closed
brunolm opened this issue May 9, 2018 · 4 comments
Closed

Doesn't work with iOS emojis #98

brunolm opened this issue May 9, 2018 · 4 comments

Comments

@brunolm
Copy link

brunolm commented May 9, 2018

This line

return node.innerText.trim().split('').map(char => {

.split('')

wrongly splits emojis in iOS webview, if you change to

for (const char of trimmedText) {
  // char
}

it will work with iOS emojis

@peterhry
Copy link
Owner

Fixed in 2.2.1

@brunolm
Copy link
Author

brunolm commented May 15, 2018

@peterhry that handles some emojis, but doesn't handle all.

I found a package called grapheme-splitter https://github.com/orling/grapheme-splitter
It handles a lot of different emojis (and special chars):

image

yarn add grapheme-splitter
import GraphemeSplitter from 'grapheme-splitter';

const splitter = new GraphemeSplitter();

/**
 * Splits the text of the provided element into its individual chars, wrapping
 * each with an instance of the provided wrapper element.
 *
 * @param {Node} node The node whose `innerText` will be split.
 * @param {string} [wrapper='span'] The name of the element to wrap each char.
 *
 * @return {Element[]} The wrapped split chars.
 */
export default (node, wrapper = 'span') => {
  const wrapperElement = document.createElement(wrapper);

  const trimmedText = node.innerText.trim();

  return splitter.splitGraphemes(trimmedText).map(char => {
    const parent = wrapperElement.cloneNode();

    parent.insertAdjacentHTML('afterbegin', char === ' ' ? ' ' : char);

    return parent;
  });
};

@peterhry peterhry reopened this May 22, 2018
@peterhry
Copy link
Owner

peterhry commented May 22, 2018

Thanks @brunolm. Can you give some examples of emojis that are not splitting correctly? I’d like to fix this but I have some concerns about introducing a dependency like GraphemeSplitter. This would increase the bundle size significantly.

Perhaps a solution would be to expose a hook that allows CircleType consumers to provide a custom split function. Thoughts?

@brunolm
Copy link
Author

brunolm commented May 22, 2018

Yeah, that makes sense @peterhry , and I like a lot your idea to allow providing a custom split function, that would totally solve issues with these emojis.

If you open this page https://emojipedia.org/people/
then open developer console and run this script

var emojis = document.querySelectorAll('.emoji');

var result = [];
for (const emoji of emojis) {
  const val = emoji.innerText;
  const spl = [...val];

  if (spl.length > 1)
    result.push(`"${val}" = [${spl.map(c => `"${c}"`)}]`);
}
console.log(result.join('\n'));

You're going to get examples of problematic emojis:

"👨‍⚕️" = ["👨","‍","⚕","️"]
"👩‍⚕️" = ["👩","‍","⚕","️"]
"👨‍🎓" = ["👨","‍","🎓"]
"👩‍🎓" = ["👩","‍","🎓"]
"👨‍⚖️" = ["👨","‍","⚖","️"]
"👩‍⚖️" = ["👩","‍","⚖","️"]
"👨‍🌾" = ["👨","‍","🌾"]
"👩‍🌾" = ["👩","‍","🌾"]
"👨‍🍳" = ["👨","‍","🍳"]
"👩‍🍳" = ["👩","‍","🍳"]
"👨‍🔧" = ["👨","‍","🔧"]
"👩‍🔧" = ["👩","‍","🔧"]
"👨‍🏭" = ["👨","‍","🏭"]
"👩‍🏭" = ["👩","‍","🏭"]
"👨‍💼" = ["👨","‍","💼"]
"👩‍💼" = ["👩","‍","💼"]
"👨‍🔬" = ["👨","‍","🔬"]
"👩‍🔬" = ["👩","‍","🔬"]
"👨‍💻" = ["👨","‍","💻"]
"👩‍💻" = ["👩","‍","💻"]
"👨‍🎤" = ["👨","‍","🎤"]
"👩‍🎤" = ["👩","‍","🎤"]
"👨‍🎨" = ["👨","‍","🎨"]
"👩‍🎨" = ["👩","‍","🎨"]
"👨‍✈️" = ["👨","‍","✈","️"]
"👩‍✈️" = ["👩","‍","✈","️"]
"👨‍🚀" = ["👨","‍","🚀"]
"👩‍🚀" = ["👩","‍","🚀"]
"👨‍🚒" = ["👨","‍","🚒"]
"👩‍🚒" = ["👩","‍","🚒"]
"👮‍♂️" = ["👮","‍","♂","️"]
"👮‍♀️" = ["👮","‍","♀","️"]
"🕵️‍♂️" = ["🕵","️","‍","♂","️"]
"🕵️‍♀️" = ["🕵","️","‍","♀","️"]
"💂‍♂️" = ["💂","‍","♂","️"]
"💂‍♀️" = ["💂","‍","♀","️"]
"👷‍♂️" = ["👷","‍","♂","️"]
"👷‍♀️" = ["👷","‍","♀","️"]
"👳‍♂️" = ["👳","‍","♂","️"]
"👳‍♀️" = ["👳","‍","♀","️"]
"👱‍♂️" = ["👱","‍","♂","️"]
"👱‍♀️" = ["👱","‍","♀","️"]
"🧙‍♀️" = ["🧙","‍","♀","️"]
"🧙‍♂️" = ["🧙","‍","♂","️"]
"🧚‍♀️" = ["🧚","‍","♀","️"]
"🧚‍♂️" = ["🧚","‍","♂","️"]
"🧛‍♀️" = ["🧛","‍","♀","️"]
"🧛‍♂️" = ["🧛","‍","♂","️"]
"🧜‍♀️" = ["🧜","‍","♀","️"]
"🧜‍♂️" = ["🧜","‍","♂","️"]
"🧝‍♀️" = ["🧝","‍","♀","️"]
"🧝‍♂️" = ["🧝","‍","♂","️"]
"🧞‍♀️" = ["🧞","‍","♀","️"]
"🧞‍♂️" = ["🧞","‍","♂","️"]
"🧟‍♀️" = ["🧟","‍","♀","️"]
"🧟‍♂️" = ["🧟","‍","♂","️"]
"🙍‍♂️" = ["🙍","‍","♂","️"]
"🙍‍♀️" = ["🙍","‍","♀","️"]
"🙎‍♂️" = ["🙎","‍","♂","️"]
"🙎‍♀️" = ["🙎","‍","♀","️"]
"🙅‍♂️" = ["🙅","‍","♂","️"]
"🙅‍♀️" = ["🙅","‍","♀","️"]
"🙆‍♂️" = ["🙆","‍","♂","️"]
"🙆‍♀️" = ["🙆","‍","♀","️"]
"💁‍♂️" = ["💁","‍","♂","️"]
"💁‍♀️" = ["💁","‍","♀","️"]
"🙋‍♂️" = ["🙋","‍","♂","️"]
"🙋‍♀️" = ["🙋","‍","♀","️"]
"🙇‍♂️" = ["🙇","‍","♂","️"]
"🙇‍♀️" = ["🙇","‍","♀","️"]
"🤦‍♂️" = ["🤦","‍","♂","️"]
"🤦‍♀️" = ["🤦","‍","♀","️"]
"🤷‍♂️" = ["🤷","‍","♂","️"]
"🤷‍♀️" = ["🤷","‍","♀","️"]
"💆‍♂️" = ["💆","‍","♂","️"]
"💆‍♀️" = ["💆","‍","♀","️"]
"💇‍♂️" = ["💇","‍","♂","️"]
"💇‍♀️" = ["💇","‍","♀","️"]
"🚶‍♂️" = ["🚶","‍","♂","️"]
"🚶‍♀️" = ["🚶","‍","♀","️"]
"🏃‍♂️" = ["🏃","‍","♂","️"]
"🏃‍♀️" = ["🏃","‍","♀","️"]
"👯‍♂️" = ["👯","‍","♂","️"]
"👯‍♀️" = ["👯","‍","♀","️"]
"🧖‍♀️" = ["🧖","‍","♀","️"]
"🧖‍♂️" = ["🧖","‍","♂","️"]
"👨‍❤️‍💋‍👨" = ["👨","‍","❤","️","‍","💋","‍","👨"]
"👩‍❤️‍💋‍👩" = ["👩","‍","❤","️","‍","💋","‍","👩"]
"👨‍❤️‍👨" = ["👨","‍","❤","️","‍","👨"]
"👩‍❤️‍👩" = ["👩","‍","❤","️","‍","👩"]
"👨‍👩‍👦" = ["👨","‍","👩","‍","👦"]
"👨‍👩‍👧" = ["👨","‍","👩","‍","👧"]
"👨‍👩‍👧‍👦" = ["👨","‍","👩","‍","👧","‍","👦"]
"👨‍👩‍👦‍👦" = ["👨","‍","👩","‍","👦","‍","👦"]
"👨‍👩‍👧‍👧" = ["👨","‍","👩","‍","👧","‍","👧"]
"👨‍👨‍👦" = ["👨","‍","👨","‍","👦"]
"👨‍👨‍👧" = ["👨","‍","👨","‍","👧"]
"👨‍👨‍👧‍👦" = ["👨","‍","👨","‍","👧","‍","👦"]
"👨‍👨‍👦‍👦" = ["👨","‍","👨","‍","👦","‍","👦"]
"👨‍👨‍👧‍👧" = ["👨","‍","👨","‍","👧","‍","👧"]
"👩‍👩‍👦" = ["👩","‍","👩","‍","👦"]
"👩‍👩‍👧" = ["👩","‍","👩","‍","👧"]
"👩‍👩‍👧‍👦" = ["👩","‍","👩","‍","👧","‍","👦"]
"👩‍👩‍👦‍👦" = ["👩","‍","👩","‍","👦","‍","👦"]
"👩‍👩‍👧‍👧" = ["👩","‍","👩","‍","👧","‍","👧"]
"👨‍👦" = ["👨","‍","👦"]
"👨‍👦‍👦" = ["👨","‍","👦","‍","👦"]
"👨‍👧" = ["👨","‍","👧"]
"👨‍👧‍👦" = ["👨","‍","👧","‍","👦"]
"👨‍👧‍👧" = ["👨","‍","👧","‍","👧"]
"👩‍👦" = ["👩","‍","👦"]
"👩‍👦‍👦" = ["👩","‍","👦","‍","👦"]
"👩‍👧" = ["👩","‍","👧"]
"👩‍👧‍👦" = ["👩","‍","👧","‍","👦"]
"👩‍👧‍👧" = ["👩","‍","👧","‍","👧"]
"🇦🇺" = ["🇦","🇺"]
"🇫🇷" = ["🇫","🇷"]
"🇨🇦" = ["🇨","🇦"]
"🇧🇷" = ["🇧","🇷"]
"🇲🇽" = ["🇲","🇽"]
"🇨🇳" = ["🇨","🇳"]
"🇺🇸" = ["🇺","🇸"]

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

Successfully merging a pull request may close this issue.

2 participants