-
Notifications
You must be signed in to change notification settings - Fork 38
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Feature] Add filterFunctions prop to enable emojis filtering #34
[Feature] Add filterFunctions prop to enable emojis filtering #34
Conversation
…at are invoked for every emoji before actual rendering making it possible to show only subset of emojis instead of all of them always
@rijn Let me know what You think : ) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
small nit. 😍 Thanks for working on this.
@@ -298,7 +301,7 @@ class EmojiInput extends React.PureComponent { | |||
.map((v, k) => [ | |||
{ char: category[k].key, categoryMarker: true, ...category[k] } | |||
]); | |||
_(emoji) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: rename it to emojis
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have changed the param of function to emojis
instead of emoji
- let me know if this is what You meant.
src/EmojiInput.js
Outdated
@@ -287,6 +287,9 @@ class EmojiInput extends React.PureComponent { | |||
return e1.char !== e2.char; | |||
}); | |||
|
|||
this.filtered = this.props.filterFunctions.length === 0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's directly connect the filter functions to lodash chain, e.g.
_(emojis)
.filter(emoji => _.every ...)
...
Also _.every
will return true if the first argument is empty array, so it's safe not to check whether the length is zero
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done. 👍
…terFunctions props as every will return true if collection is empty. Rename emoji param to emojis
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Minor changes required. Also, I realized that filterFunctions
will not be frequently changed. Therefore, moving the emojis that being filtered by filterFunctions
to the state might be a better approach. I'll create another issue to follow this.
example/src/EmojiInput.js
Outdated
let dataProvider = new DataProvider((e1, e2) => { | ||
return e1.char !== e2.char; | ||
}); | ||
|
||
this.filteredEmojis = _(emojis).pickBy(emoji => _.every(this.props.filterFunctions, fn => fn(emoji))).value(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do we need to assign filteredEmojis
to this component? The value will only be used inside the function, right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
filteredEmoji
is not needed anymore so I have removed that.
example/src/EmojiInput.js
Outdated
@@ -298,7 +299,7 @@ class EmojiInput extends React.PureComponent { | |||
.map((v, k) => [ | |||
{ char: category[k].key, categoryMarker: true, ...category[k] } | |||
]); | |||
_(emoji) | |||
_(this.filteredEmojis) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's do the following
_(emojis)
.values()
.filter(emoji => _.every(this.props.filterFunctions, fn => fn(emoji)))
.each(e => {
...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changed 👍
…riable as it is not requried anymore
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lovely. Thanks a lot!
No problem 👌 |
No problem, glad to help. |
Relate to any issue?
#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
filterFunctions
prop allowing user to pass an array of functions used to filter emojis list before rendering itExample of usage:
Change Preview:
Before on my Huawei P8Lite running Android 6.0:
After enabling only 6.0 Unicode: