2

I'm using React Native (chat), in this app I have one emoji picker but when users press virtual backspace button emojis only remove their last unicode byte.

How can I detect if last 'chat' (set of unicodes) is standalone emoji unicode?

Code to split it:

inputValue.substring(0, inputValue.length - 1)

I also tried to use Array.from(), then use slice(0,-1) and correct solutions to all cases appears when I console log it. BUT! When I set the SAME variable to the TextInput appears: 321331231221.

Some examples:

"Hello".length
7

"Hello".slice(0,-1)
'Hello�'

Array.from("Hello")
[ 'H', 'e', 'l', 'l', 'o', '' ]

Array.from("Hello").slice(0,-1)
[ 'H', 'e', 'l', 'l', 'o' ]

Array.from("Hello").slice(0,-1).join('')
'Hello'

But if I set this last solution in my React Native TextInput component I see something like this: 312412412411 (maybe all in hex). If the value has not emojis I see the same result as well.

When I set the emoji with the emoji picker, something like ${inputValue}${newEmoji} all works out.

I do not know what to think guys :/

  • Can you give some sample strings from which you're trying to remove emoji characters? – David Thomas Dec 19 '18 at 09:21
  • See my update please. I'm using emoji-datasource and parse the unified unicode with String.fromCodePoint() to add the new emoji when user select it with the emoji picker. Other feature is the backspace virtual button. (in the screen) but when I try the code above (update) the TextInput (**React Native**) works strange @DavidThomas – Ignacio Castillejo Gomez Dec 20 '18 at 01:36
  • I think is React Native TextInput issue because I see the correct value in console and if I send the value to the server to check with the react native debugger off the value are correct too. But when I dispatch the new value... So much strange... I want to be sure before post a issue to React Native project. – Ignacio Castillejo Gomez Dec 20 '18 at 01:39
  • Does this answer your question? [How can I remove the last emoji of a group of emojis in javascript?](https://stackoverflow.com/questions/46909766/how-can-i-remove-the-last-emoji-of-a-group-of-emojis-in-javascript) – JAnton Oct 25 '20 at 14:08

1 Answers1

1

Try with slice :

inputValue.slice(0, -1);

UPDATE :

This package might help you: runes

example of your need :

const runes = require('runes')

function backspace(text){

       return runes(text).slice(0, -1);

}

//the call : 

backspace('Made with ♥') // Made with