Giter Club home page Giter Club logo

react-native-emoji-input's Introduction

React Native Emoji Input

npm version

A performant, customizable keyboard input for React Native. Built for and used in Opico.

Emoji Input Example

Installation

npm install --save react-native-emoji-input

or

yarn add react-native-emoji-input

If you make changes to the emoji synonyms files, you need to recompile the data sources. To compile the emoji dataset, run:

npx babel-node scripts/compile.js

Default Props

Prop Description type
onEmojiSelected A handler for the selected emoji function

Optional Props

Prop Description type default value
keyboardBackgroundColor Set the background color of the main keyboard pane string '#E3E1EC'
categoryUnhighlightedColor Set the default color of the category icons string 'lightgray'
categoryHighlightColor Set the color of a higlighted category icon string 'black'
width Width of the keyboard, number in px number window width
numColumns Number of emoji columns to display number 6
categoryLabelHeight The height of category title number 40
categoryLabelTextStyle The text size of the category title object {fontSize: 25}
emojiFontSize The default size of the emojis number 40
categoryFontSize The default size of the category icons number 40
numFrequentlyUsedEmoji Max number of frequently used emojis in the section number 18
showCategoryTab Whether the categories should be shown or not boolean true
enableSearch Whether the search bar should be shown or not boolean true
showCategoryTitleInSearchResults Whether the search title should be shown or not in search results boolean false
enableFrequentlyUsedEmoji Whether the frequently used category should be shown or not boolean true
defaultFrequentlyUsedEmoji An array of keys for emojis that will always render in the frequently used category Array(string) []
resetSearch Pass this in if you want to clear the the search boolean false
loggingFunction Logging function to be called when applicable.* function none
verboseLoggingFunction Same as loggingFunction but also provides strategy used to determine failed search boolean false
filterFunctions Array of functions that are used to limit which emojis should be rendered. Each of this function will be invoked with single parameter being emoji data and if every function returns true for emoji then this emoji will be included and displayed. Array(function) []
renderAheadOffset Specify how many pixels in advance you want views to be rendered. Increasing this value can help reduce blanks (if any). However, making this low can improve performance if you're having issues with it (see #36). Higher values also increase re-render compute number 1500

* When the search function yields this function is called. Additionally when the user clears the query box this function is called with the previous longest query since the last time the query box was empty. By default the function is called with one parameter, a string representing the query. If the verbose logging function parameter is set to true the function is called with a second parameter that is a string specifying why the function was called (either 'emptySearchResult' or 'longestPreviousQuery').

Usage

<EmojiInput
	onEmojiSelected={(emoji) => {console.log(emoji)}}
	/>

Compile emoji-data from source

The project is using iamcal/emoji-data. We only use the emoji.json that contains all the Unicode characters, short names, keywords, and categories. To embrace the latest version of Emoji, we suggest to compile the json file from source.

# You need first check out the `emoji-data` repo. We will use the compile tool provided in the repo.
git clone https://github.com/iamcal/emoji-data.git
cd emoji-data/build

# Pull data from Unicode standard
sh download_spec_files.sh

# Add new shortnames. Here're some examples in current dir, check out data_emoji_names.txt, data_emoji_names_v4.txt
vim data_emoji_names_vxx.txt # xx should be version of emoji, e.g. 11

# Compile from spec files into json
php build_map.php

Then copy the emoji-data/emoji.json to src/emoji-data/emoji-data.json and make sure the entry point is point to this json file.

// src/emoji-data/index.js
import emoji from './emoji-data.json';

Finally compile the data file that used in the keyboard.

node-babel ./scripts/compile.js

Missing Emojis on some devices

So why Emojis are displayed as X / other characters insetad of actual Emojis for some of your users?
That is because this library renders Emojis based on Font and Font need to support Emoji character in order to render it. And those fonts are updated with every system release, but because there is a lot of Android device manufacturers who are actually using Android as a base to come up with their own UI layer then it is harder for them to keep up with system updates.
You can read more about it here Emojipedia article link

So what can you do?
Apps such as Slack / WhatsApp are actually providing Emojis as little images so that they can be render regardless of operating system on mobile phone. The problem in React-Native is that there is no support for placing images in Input element at time of writing this.
Other solution is to limit number of possible emojis to most basic ones which are supported on most devices. Choosing emojis from Unicode 6.0 seems like solid solution: Unicode 6.0 Emojis List - you get tons of Emojis that are most likely to be correctly rendered across most of the devices.

In React-Native-Emoji-Input you can limit emojis displayed by using filterFunctions prop and passing array of functions. Each of this function takes emoji as an single parameter and if every function passed in filterFunctions prop returns true then emoji will be included in final list.
We can use that to show only emojis which are part of Unicode 6.0 or Unicode 6.1 like so:

	filterFunctionByUnicode = emoji => {
		return emoji.lib.added_in === "6.0" || emoji.lib.added_in === "6.1"
	}

	<EmojiInput
		onEmojiSelected={this.handleEmojiSelected}
		ref={emojiInput => this._emojiInput = emojiInput}
		resetSearch={this.state.reset}
		loggingFunction={this.verboseLoggingFunction.bind(this)}
		verboseLoggingFunction={true}
		filterFunctions={[this.filterFunctionByUnicode]}
	/>

This will render only emojis from Unicode 6.0 and Unicode 6.1 in input.

react-native-emoji-input's People

Contributors

darekg11 avatar gutosanches avatar henrycwoo avatar rijn avatar skondi2 avatar sskhandek avatar zclewell avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

react-native-emoji-input's Issues

Option to prevent keyboard from getting dismissed when emoji is pressed.

Use case:
When an emoji is pressed, it does not register the touch event when the keyboard is visible. This is a very common scenario as input box will generally be focused when the user taps on emojis.

Solution
I'm creating a PR with keyboardShouldPersistTaps prop. This works on RecyclerListView exactly as it works on Scrollview.

componentWillMount and componentWillReceiveProps warnings in newer React

First, thank you very much for this project. I tried many different emoji providers and I finally decided to use yours. In newer expo/react, I see these warnings:

  1. Warning: componentWillMount has been renamed, and is not recommended for use. See https://fb.me/react-unsafe-component-lifecycles for details.

    • Move code with side effects to componentDidMount, and set initial state in the constructor.
    • Rename componentWillMount to UNSAFE_componentWillMount to suppress this warning in non-strict mode. In React 17.x, only the UNSAFE_ name will work. To rename all deprecated lifecycles to their new names, you can run npx react-codemod rename-unsafe-lifecycles in your project source folder.

    Please update the following components: RecyclerListView

  2. Warning: componentWillReceiveProps has been renamed, and is not recommended for use. See https://fb.me/react-unsafe-component-lifecycles for details.

    • Move data fetching code or side effects to componentDidUpdate.
    • If you're updating state whenever props change, refactor your code to use memoization techniques or move it to static getDerivedStateFromProps. Learn more at: https://fb.me/react-derived-state
    • Rename componentWillReceiveProps to UNSAFE_componentWillReceiveProps to suppress this warning in non-strict mode. In React 17.x, only the UNSAFE_ name will work. To rename all deprecated lifecycles to their new names, you can run npx react-codemod rename-unsafe-lifecycles in your project source folder.

    Please update the following components: RecyclerListView

  3. Warning: componentWillMount has been renamed, and is not recommended for use. See https://fb.me/react-unsafe-component-lifecycles for details.

    • Move code with side effects to componentDidMount, and set initial state in the constructor.
    • Rename componentWillMount to UNSAFE_componentWillMount to suppress this warning in non-strict mode. In React 17.x, only the UNSAFE_ name will work. To rename all deprecated lifecycles to their new names, you can run npx react-codemod rename-unsafe-lifecycles in your project source folder.

    Please update the following components: ViewRenderer

Create a fallback strategy for missing emoji

Some versions of iOS and Android do not support all the emoji unicode characters. Having a fallback emoji character upon detection of the missing emoji would replace it with a popular open source emoji font like Twemoji or EmojiOne

Add Skintone support

Add the ability to set your own skin tone. We'll need to pass that in as a prop and have that documented in the README

Merge datasources for emoji lib

Currently, we have a problem where the CLDR or the 'short_name' from the emoji-data package does not match up with the key from the emojilib package in every case. This can cause some issues, such as in the case of skin-tones. We should consolidate the two sources to address this problem

Add More Keywords to the Emoji Search Dictionary

Rather than use a thesaurus API or something else, it may very well be worth it to try to just manually work through some familiar emoji and add some relevant keywords. This can be frustrating for a lot of the "People" examples where they are performing certain sports, for example. Another that will frustrate me to no end is the pasta emoji only being identified as "spaghetti".

Editing emoji file

Hi,

The documentation just states to edit the file and compile using this command.

npx babel-node scripts/compile.js

I installed @babel/node and @babel/core first. In node 10 as well as 12 it didn't work. On node 10 it says "SyntaxError: Unexpected token import" and on node 12 its "SyntaxError: Cannot use import statement outside a module". Is it possible for someone to provide some help on how to get this compiled?

emoji containing '-' issue

First of all, great library.
I've noticed some issues with emoji containing the character '-' : in particular, all of the 'male-...' 'female-...' 'man-...' 'woman-...' : these emoji appear to be broken for me (they don't appear correctly).
Any idea what is causing this?

set renderAheadOffset={1500} as a prop can greatly boost the performance

First of all, great emoji component!!! I loved the work you have put on this, it is the emoji component that has the best performance in RN community.

I was building a composer which is under a page with content, so it only pops up when user want to write a comment, and I put the emoji component under the composer, so by pressing a button user can have keyboards down and selecting the emojis.

One of the problem that I find is that the performance really suffers,like the whole page freeze for 3-5 seconds even on the latest Android phone, when navigating to a new page with such setup, and by digging in I find the emoji component takes too long to load and block the entire JS thread. By reading the code and change the renderAheadOffset={1500} to renderAheadOffset={200} or any smaller number this problem solved. I think it might be a better idea to pass the renderAheadOffset as a prop instead of fix it inside the code, cause it is very much performance-related.

Thanks Sujay! Really an amazing emoji component, saved me tons of time, I owe you a beer!

category tab icons missing

Some icons from category tab is missing and is not displaying.

{ key: 'fue', title: 'Frequently Used', icon: props => ( <Icon name="clock" type="material-community" {...props} /> ), },

I looked at the component and found it is using react native element which uses a set of icons.
In my mobile it is not showing any icons of type="material community"

I do not know its a bug or not but I think this should be fixed

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.