Finalet / Elegant-Emoji-Picker

Aesthetic, simple, and powerful emoji picker for Swift built with UIKit.
MIT License
64 stars 16 forks source link
emoji emoji-picker emoji-searcher ios mac-catalyst swift swift-package-manager uikit

Elegant Emoji Picker Swift UIKit

Elegant Emoji Picker

Elegant Emoji Picker Unicode version Elegant Emoji Picker iOS version Elegant Emoji Picker MacCatalyst version Elegant Emoji Picker UIKit Elengat Emoji Picker Swift Elegant Emoji Picker MIT License Elengat Emoji Picker Contact

Why is there no built in emoji picker in UIKit? Same reason as why there is no calculator app in iPadOS? Perhaps. But should we just eat up Craig's laziness? Not this time. Behold: UIEmojiPicker Elegant Emoji Picker.

P.S: Apple, you have my contacts, reach out.

https://user-images.githubusercontent.com/10033440/226136503-79eb27fb-1254-45da-a7c1-5528c1ec160e.MP4

πŸ€” About

Elegant Emoji Picker is a configurable, simple to use, even more simple to impement, and beautiful (subjectively) emoji picker for iOS, iPadOS, and MacCatalyst (iOS preview, MacCatalyst preview).

Features

Limitations

πŸ’» Installation

Elegant Emoji Picker is available via the Swift Package Manager.

With your Xcode project open, go to File β†’ Add Packages, enter the address below into the search field and click "Add Package".

https://github.com/Finalet/Elegant-Emoji-Picker

Afterwards, import ElegantEmojiPicker module where you want to use it.

import ElegantEmojiPicker

πŸ‘€ Usage

Offering emoji selection

ElegantPickerView is the main view controller, which interacts with you through a delegate protocol ElegantEmojiPickerDelegate. Conform to the protocol and present ElegantPickerView when you want to offer emoji selection like so:

func PresentEmojiPicker () {
    let picker = ElegantEmojiPicker(delegate: self)
    self.present(picker, animated: true)
}

Getting the selected emoji

Implement the required delegate method emojiPicker (_: didSelectEmoji :) to recieve user's selection. This function is called as soon as the user picks an emoji and passes an optinal emoji: Emoji? variable. emoji is nil when the users "resets" selection, meaning they used to have an emoji which they now want to remove.

func emojiPicker(_ picker: ElegantEmojiPicker, didSelectEmoji emoji: Emoji?) {
    guard let emoji = emoji else { return }

    uiLabel.text = emoji.emoji
}

It is that easy. If simply offering emojis is all your soul desires, we are done. But if you are a more intricate type of coder and want more control, keep on readin'.

🎨 Configuration

Showing or hiding features

Pass the ElegantConfiguration struct to the ElegantEmojiPicker initializer to configure the UI and behaviour of the emoji picker.

let config = ElegantConfiguration(showRandom: false, showReset: false, defaultSkinTone: .Light)
let picker = ElegantEmojiPicker(delegate: self, configuration: config)
viewController.present(picker, animated: true)

Offering a custom set of emojis

If you want to provide your own list of emojis to users, implement the emojiPicker(_: loadEmojiSections : withConfiguration : withLocalization) delegate method and return an array of sections containing emojis [EmojiSection]. You can use a static method ElegantEmojiPicker.getAllEmoji() to retrieve all existing emojis or ElegantEmojiPicker.getDefaultEmojiSections() to get all emojis categorized by default sections.

EmojiSection one section containing emojis, like "Smileys & Emotion" or "People & Body".

func emojiPicker(_ picker: ElegantEmojiPicker, loadEmojiSections withConfiguration: ElegantConfiguration, _ withLocalization: ElegantLocalization) -> [EmojiSection] {
    let allEmojis = ElegantEmojiPicker.getAllEmoji()

    let politeEmojis = allEmojis.filter({
        $0.emoji == "πŸ–•" ||
        $0.emoji == "πŸ‘Š" ||
        $0.emoji == "🀬"
    })

    return [EmojiSection(title: "Politeness", icon: UIImage(systemName: "heart"), emojis: politeEmojis)]
}

Localization

You can provide texts for all on screen labels by passing the ElegantLocalization struct to the ElegantEmojiPicker initializer.

let localization = ElegantLocalization(searchFieldPlaceholder: "Π§Π΅ Π½Π°Π΄ΠΎ", randomButtonTitle: "Π₯Π· Π³ΠΎ Ρ€Π°Π½Π΄ΠΎΠΌ")
let picker = ElegantEmojiPicker(delegate: self, localization: localization)
viewController.present(picker, animated: true)

πŸ“± Sample Project

Explore the Demo project for reference on what Elegant Emoji Picker is capable of or how to implement it. That said, the library is comically simple, so you should not have any trouble yourself.

If you want to see the picker live on the App Store, check out Finale To Do. This sentence was sponsored by #shamelessplug.

πŸ€·πŸ»β€β™‚οΈ Contribution guide

I have no idea what I am doing. Send help. How do git contributions work? The fuck if I know. Just don't do anything stupid and we will figure this out.