rn-emoji-keyboard
repository·master·Indexed 19 days ago
https://github.com/thewidlarzgroup/rn-emoji-keyboardA lightweight, fully customizable emoji keyboard component for React Native version 1.7.0. Written in JavaScript/TypeScript without native elements, it supports both modal and static modes. Features include a built-in emoji dataset, search functionality, recently used emojis with persistence via the useRecentPicksPersistence hook, and extensive styling and theme customization options.
What's inside rn-emoji-keyboard
- The library supports skintone modifiers by default. Users can access different skin tone options by performing a long press on specific emojis. This action triggers a panel containing multiple skin tone options for that emoji.
Choose between Modal and Static modes
masterRN Emoji Keyboard provides two distinct ways to implement an emoji picker:
- Modal mode: An overlay-style picker.
- Static mode: An inline picker that can be embedded directly into your UI.
Refer to the specific API documentation for
/docs/api/modalor/docs/api/staticto implement your preferred mode.Use pre-defined translations
masterThe library provides built-in translations for several languages. To use one, import the specific language object from
rn-emoji-keyboardand pass it to thetranslationprop of the keyboard component.import { pl } from 'rn-emoji-keyboard' // ... translation = { pl }Install rn-emoji-keyboard
masterYou can install the
rn-emoji-keyboardpackage using eitheryarnornpm.yarn add rn-emoji-keyboardor
npm install rn-emoji-keyboardAdd new language translations
masterTo add support for a new language in
rn-emoji-keyboard, follow these steps:- Create a language file: Create a new
.tsfile in the/src/translation/directory (e.g.,fr.tsfor French). - Define the translation object: Create a translation object that implements the
CategoryTranslationtype. Ensure you use a unique object name corresponding to your language and follow the existing format. - Register the translation: Import and export your new translation file in
/src/index.tsxso it is available to the package. - Update documentation: Add information about the newly supported language to the project documentation.
export const fr: CategoryTranslation = { recently_used: 'Récemment utilisé', smileys_emotion: 'Smileys & Émotion', people_body: 'Personnes & Corps', animals_nature: 'Animaux & Nature', food_drink: 'Nourriture & Boisson', travel_places: 'Voyages & Lieux', activities: 'Activités', objects: 'Objets', symbols: 'Symboles', flags: 'Drapeaux', search: 'Rechercher', } export default fr- Create a language file: Create a new
Use the EmojiPicker component
masterTo use the emoji picker, import the
EmojiPickercomponent and theEmojiTypetype. You must manage the visibility of the picker using anopenprop and provide a callback for when the picker is closed viaonClose. To handle emoji selection, use theonEmojiSelectedprop, which returns anEmojiTypeobject.import EmojiPicker, { type EmojiType } from 'rn-emoji-keyboard' export default function App() { const [isOpen, setIsOpen] = React.useState<boolean>(false) const handlePick = (emojiObject: EmojiType) => { console.log(emojiObject) /* example emojiObject = { "emoji": "❤️", "name": "red heart", "slug": "red_heart", "unicode_version": "0.6", } */ } return ( <EmojiPicker onEmojiSelected={handlePick} open={isOpen} onClose={() => setIsOpen(false)} /> ) }Use the EmojiKeyboard in Static Mode
masterYou can use
rn-emoji-keyboardin static mode by importing theEmojiKeyboardcomponent. In this mode, the keyboard is treated as a standard component within your layout rather than a popup/modal.Note that static mode shares the same props as modal mode, but props related to modal lifecycle and visibility—specifically
openandonClose—are disabled and will not function.import { EmojiKeyboard } from 'rn-emoji-keyboard'Build the documentation website for production
masterGenerate static content for the website by running
yarn build. The resulting static files will be located in thebuilddirectory and can be hosted on any static content hosting service.$ yarn buildInstall dependencies for the documentation website
masterTo set up the documentation website environment, runyarnto install all necessary dependencies using the package manager.$ yarnRun the documentation website in local development mode
masterStart a local development server by running
yarn start. This command will open a browser window and support live reloading, meaning most changes to the documentation will be reflected immediately without a server restart.$ yarn startInstall rn-emoji-keyboard via yarn
masterTo add the emoji keyboard to your React Native project, use the following yarn command:
yarn add rn-emoji-keyboardPersist recent emoji picks with useRecentPicksPersistence
masterThe
useRecentPicksPersistencehook allows you to implement custom persistence logic for recently used emojis. You can use any storage mechanism (e.g., Async Storage, a backend API, etc.) as long as the functions return aPromise.Prerequisites
- You must enable
enableRecentlyUsedin yourEmojiKeyboardcomponent. - To ensure a smooth experience and consistent state across the app, it is recommended to use this hook as high as possible in your React component tree (e.g., in
App.tsx).
Important Behavior
This hook impacts every instance of
rn-emoji-keyboardused in your application that hasenableRecentlyUsedenabled.import { useRecentPicksPersistence } from 'rn-emoji-keyboard'- You must enable