rn-emoji-keyboard

repository·master·Indexed 19 days ago

https://github.com/thewidlarzgroup/rn-emoji-keyboard

A 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.

Tokens
12.5K
Snippets
46
Records
58
Agent score
63%

What's inside rn-emoji-keyboard

  1. Add new language translations

    master

    To add support for a new language in rn-emoji-keyboard, follow these steps:

    1. Create a language file: Create a new .ts file in the /src/translation/ directory (e.g., fr.ts for French).
    2. Define the translation object: Create a translation object that implements the CategoryTranslation type. Ensure you use a unique object name corresponding to your language and follow the existing format.
    3. Register the translation: Import and export your new translation file in /src/index.tsx so it is available to the package.
    4. 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
  2. Use the EmojiPicker component

    master

    To use the emoji picker, import the EmojiPicker component and the EmojiType type. You must manage the visibility of the picker using an open prop and provide a callback for when the picker is closed via onClose. To handle emoji selection, use the onEmojiSelected prop, which returns an EmojiType object.

    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)} 
        />
      )
    }
  3. Use the EmojiKeyboard in Static Mode

    master

    You can use rn-emoji-keyboard in static mode by importing the EmojiKeyboard component. 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 open and onClose—are disabled and will not function.

    import { EmojiKeyboard } from 'rn-emoji-keyboard'
  4. Persist recent emoji picks with useRecentPicksPersistence

    master

    The useRecentPicksPersistence hook 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 a Promise.

    Prerequisites

    1. You must enable enableRecentlyUsed in your EmojiKeyboard component.
    2. 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-keyboard used in your application that has enableRecentlyUsed enabled.

    import { useRecentPicksPersistence } from 'rn-emoji-keyboard'