简体   繁体   English

iOS和Android中的JavaScript跨平台表情符号

[英]JavaScript Cross platform emojis in iOS and android

What is the best way to obtain the normal emoji (the yellow one, first in the image) in Android. 在Android中获取常规表情符号(黄色的,首先出现在图像中)的最佳方法是什么。 If the emojis could come with different colors (iOS emojis). 如果表情符号可以带有不同的颜色(iOS表情符号)。 The reason is that Android doesn't have colored emojis. 原因是Android没有彩色表情符号。

在此处输入图片说明

All emojis in android less the first one shows a '?' android中的所有表情符号(第一个除外)都显示“?” symbol. 符号。

I need to parse the emojis in JavaScript but I didn't find any good library. 我需要解析JavaScript中的表情符号,但找不到任何好的库。 Maybe there is a replace function that solves this. 也许有一个替换功能可以解决这个问题。

Emojis 表情符号

First let's understand what an emoji is. 首先让我们了解什么是表情符号。 An emoji is a combination of many characters as it is implemented in Unicode. 表情符号是由Unicode实现的许多字符的组合。 For example, the "light skin tone male shrug emoji" is actually the following 5 characters combined: 例如,“浅肤色男性耸肩表情符号”实际上是以下5个字符的组合:

0x1f937 0x1f3fb 0x200d 0x2642 0xfe0f

- 0x1f937: Person Shrugging
- 0x1f3fb: Light skin tone  
- 0x200d: Zero width joiner     (Used to combine two characters, in this case
                                 the Light skin tone Person shrugging and the
                                 male sign.)
- 0x2642: Male sign
- 0xfe0f: Variation selector-16 (Used to indicate an Emoji)

Unicode in JavaScript JavaScript中的Unicode

Good news is, we can simply remove 0x1f3fb to get the version without skin tone. 好消息是,我们可以简单地删除0x1f3fb以获得没有肤色的版本。 Bad news is however, JavaScript does not support UTF-16, so it shows up as 不过,坏消息是,JavaScript不支持UTF-16,因此显示为

0xd83e 0xdd37 0xd83c 0xdffb 0x200d 0x2642 0xfe0f
└───────── Uh oh ─────────┘

instead which is incorrect because it doesn't know what a surrogate pair is. 相反,这是不正确的,因为它不知道什么是代理对 To calculate the correct code point, we will have to reference the UTF-16 standard and make the necessary corrections. 要计算正确的代码点,我们必须参考UTF-16标准并进行必要的更正。 Fortunately, someone else already did the hard work and here I'm converting the string into proper UTF-16 and removing the part that I don't want: 幸运的是, 其他人已经做了艰苦的工作 ,在这里,我将字符串转换为正确的UTF-16并删除了我不需要的部分:

// Defines the range of skin tone modifiers
var modifiersMin = 0x1F3FB, modifiersMax = 0x1F3FF;

// Emoji with U+1F3FB "light skin tone" modifier combined with "male sign"
var string = new UnicodeString("🤷🏻‍♂️");

// Removes the modifier
string = new UnicodeString(string.codePoints.filter(c => {
    return c < modifiersMin || c > modifiersMax;
});

alert(string.toString());

You can see it in action here: https://jsfiddle.net/DerekL/b5848tor/ 您可以在这里查看它的运行情况: https : //jsfiddle.net/DerekL/b5848tor/

Now that you understand how emojis work, you can also do this: 现在您了解了表情符号的工作原理,您还可以执行以下操作:

// The replace function that you would like
var skinToneModifiers = new RegExp("\ud83c[\udffb-\udfff]", "g");
var string = "🤷🏻‍♂️";
// Remove skin tone modifier
string = string.replace(skinToneModifiers, "");

which works much faster but not exactly clear why it works without understanding the concepts behind it. 它的运行速度要快得多,但在不了解其背后的概念的情况下却无法完全弄清楚它为什么起作用。

See it in action: https://jsfiddle.net/DerekL/sn4n689r/ 实际操作中查看它: https : //jsfiddle.net/DerekL/sn4n689r/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用javascript解码从android和ios表情符号接收的unicode字符 - Decoding unicode charactors recieving from android and ios emojis with javascript 创建一个跨平台的javascript库 - Creating a cross platform javascript library WebApp使用webRTC在iOS浏览器和Android Chrome中实现跨平台视频聊天 - WebApp using webRTC for cross-platform videochat in iOS Browser and Android Chrome 使用 JavaScript、HTML5 或任何跨平台语言(支持 Android)将数据写入 USB HID - Write data to USB HID using JavaScript, HTML5, or any cross platform language (supports Android) 跨平台 AES 256 GCM Javascript 和 Elixir - Cross Platform AES 256 GCM Javascript & Elixir 一个用于跨平台鼠标处理的小型JavaScript库? - A small javascript library for cross platform mouse handling? 套接字编程跨平台(PHP和Javascript) - Socket Programming Cross Platform (PHP & Javascript) 跨平台桌面应用程序的最佳JavaScript引擎 - best javascript engine for cross platform desktop app 跨平台,跨浏览器的Javascript性能分析 - Cross-platform, cross-browser Javascript performance profiling 如何在React Native中使用index.js代替(index.ios.js,index.android.js)进行跨平台应用? - How to use index.js instead of (index.ios.js, index.android.js) in React Native for cross-platform app?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM