sskhandek / react-native-emoji-input

A fully-featured emoji keyboard ⌨️ for React Native ⚛️
MIT License
71 stars 38 forks source link

[Feature]Add includeOnlySubsets prop to enable emojis filtering by Unicode version #31

Closed darekg11 closed 5 years ago

darekg11 commented 5 years ago

Relate to any issue?

https://github.com/sskhandek/react-native-emoji-input/issues/5
It is a temporary workaround that would allow user of this library to avoid missing emojis being render as X

Breaking change?

Nope, by default all emojis will be rendered as before.

What this PR does?

Adds new includeOnlySubsets prop allowing user to pass an array of strings being Unicode versions and filters possible emojis by that Unicode Versions.

Example of usage:

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

Change Preview:

Before on my Huawei P8Lite running Android 6.0:
before

After enabling only 6.0 Unicode:
after

darekg11 commented 5 years ago

Seems like Your Travis is broken currently?

rijn commented 5 years ago

I don't think we have an effective travis.

I like the idea, but could you make it more general. Can we pass an array of filter functions to the component instead of specifying only the unicode version?

darekg11 commented 5 years ago

How would you see implementation? The filter function would take an param that is an emoji entry in lib and upon returning true it would be included in rendered list?

Like (example of changing my unicode only implementation to external filter function):
Let's assume that this is part of my component and state.unicode is an array containing such entries: ["6.0", "6.1"]
And emoji param is passed from EmojiInput component

filterFunction = emoji => {
    return this.state.unicode.indexOf(emoji.lib.added_in) !== -1
}

And pass it to EmojiInput via prop like:

<EmojiInput filterFunction={this.filterFunction} />

And component calls the external filter function like so:

        this.filtered = 
            this.props.filterFunction
               ? _.pickBy(emoji, value => this.props.filterFunction(value))
               : emoji

Am I on track with what you have in mind?

rijn commented 5 years ago

Yeah that's just my thought. I think this approach can bring more flexibility to the component. You can even use an array of filter functions.

<EmojiInput filterFunctions={[ this.filterFunction ]} />

defaultProps = {
    filterFunctions: []
}

this.filtered = _.filter(emojis, emoji => _.every(this.props.filterFunctions, fn => fn(emoji)));
darekg11 commented 5 years ago

@rijn Nice idea, I will push change with that around end of the week. :+1:

darekg11 commented 5 years ago

Have to close this one in favor of:
https://github.com/sskhandek/react-native-emoji-input/pull/34 Since I don't have access anymore to organization account from which I have created original PR and I can't push there.