add possibility to implement custom EmojiProvider

This commit is contained in:
Kelvas
2023-01-13 22:50:46 +01:00
parent 123c6c8d2a
commit d787591e21
7 changed files with 115 additions and 11 deletions

View File

@@ -109,6 +109,48 @@ By default the search for emoji is allowed in the picker, it is however possible
EmojiPickerView(selectedEmoji: $selectedEmoji, searchEnabled: false)
```
⚠️ **WARNING** Search is only possible when `EmojiPicker` is embed on `NavigationView`.
### Custom emoji provider
`EmojiPickerView` embeds `EmojiProvider` protocol with a default implementation: `DefaultEmojiProvider`. This class allows to retrieve all existing emojis.
When you build an `EmojiPickerView`, by default it uses this class to get the list of emojis to display.
If you want to use your own emoji list, you can create your own class by implementing the `EmojiProvider` protocol :
```swift
import Foundation
import EmojiPicker
final class LimitedEmojiProvider: EmojiProvider {
func getAll() -> [Emoji] {
return [
Emoji(value: "🚀", name: "rocket"),
Emoji(value: "🇫🇷", name: "France"),
Emoji(value: "🦄", name: "unicorn"),
Emoji(value: "🍺", name: "beer"),
Emoji(value: "💶", name: "euro")
]
}
}
```
And then use it in the creation of the view:
```swift
...
NavigationView {
EmojiPickerView(selectedEmoji: $selectedEmoji, selectedColor: .orange, emojiProvider: LimitedEmojiProvider())
.padding(.top, 32)
.navigationTitle("Emojis")
.navigationBarTitleDisplayMode(.inline)
}
...
```
## Samples
You can access to sample project on folder `EmojiPickerSample`