-
Notifications
You must be signed in to change notification settings - Fork 24.3k
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
TextInput maxlength cuts Unicode caracters (Emojis) #10964
Labels
Resolution: Locked
This issue was locked by the bot.
Comments
Might be related to this? |
Closing this issue because it has been inactive for a while. If you think it should still be opened let us know why. |
This also happen with me. We have
|
@euharrison can you please share this plugin link? |
@KavithaSaras sorry, which plugin? My solution was to set a dynamic maxLength that resolve this: import React from 'react';
import { TextInput } from 'react-native';
const MAX_LENGTH = 95;
class MessageInput extends React.Component {
constructor(props) {
super(props);
this.valueLength = 0;
this.amountOfEmoji = 0;
this.state = {
value: '',
maxLength: MAX_LENGTH,
}
}
onChangeText = (text) => {
// if text.length increased by 2, then the user has typed an emoji
if ((text.length - this.valueLength) === 2) {
this.amountOfEmoji += 1;
}
// maxLength will be increased to support emoji as only one character count
let maxLength = MAX_LENGTH + this.amountOfEmoji;
// if missing only one character to be typed, reduce maxLength to avoid emoji breaks the TextInput
if (text.length >= (MAX_LENGTH + this.amountOfEmoji) - 1) {
maxLength = text.length;
}
this.setState({ value: text, maxLength });
this.valueLength = text.length;
}
render() {
return (
<TextInput
editable
value={this.state.value}
maxLength={this.state.maxLength}
onChangeText={this.onChangeText}
/>
)
}
} |
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Hello everyone,
yesterday i noticed that a TextInput has a problem displaying Emojis at the end of the fields maxlength.
If i insert the "white happy man with black hair raising one hand" Emoji (iOS) at the position maxlength-1 it shows a square with an "A" in it instead.
If i insert the "white happy man with black hair raising one hand" Emoji (iOS) at the position maxlength-2 it shows a square with an "yellow happy woman with blonde hair raising one hand" in it instead.
If i insert the "white happy man with black hair raising one hand" Emoji (iOS) at the position maxlength-3 it shows a square with an "white happy woman with black hair raising one hand" in it instead.
If i insert the "white happy man with black hair raising one hand" Emoji (iOS) at the position maxlength-4 it shows a square with an "yellow happy woman with blonde hair raising one hand" and the square with an "A" in it instead.
Seems like the maxlength cuts the unicode sign at the end and causes to show different Emojis than inserted
The text was updated successfully, but these errors were encountered: