2016-07-06 19:45:34 +00:00
|
|
|
import '../vendor/raf-polyfill'
|
2016-06-02 15:26:48 +00:00
|
|
|
|
2016-05-31 14:36:52 +00:00
|
|
|
import React from 'react'
|
2017-05-05 01:38:03 +00:00
|
|
|
import PropTypes from 'prop-types'
|
2017-09-28 23:24:17 +00:00
|
|
|
import data from '../data'
|
2016-06-02 17:21:31 +00:00
|
|
|
|
2016-07-20 18:45:28 +00:00
|
|
|
import store from '../utils/store'
|
|
|
|
import frequently from '../utils/frequently'
|
2017-09-28 23:57:20 +00:00
|
|
|
import { deepMerge, measureScrollbar } from '../utils'
|
2016-07-20 18:45:28 +00:00
|
|
|
|
2016-10-27 03:27:55 +00:00
|
|
|
import { Anchors, Category, Emoji, Preview, Search } from '.'
|
2016-06-02 15:26:48 +00:00
|
|
|
|
2016-10-27 03:22:59 +00:00
|
|
|
const I18N = {
|
|
|
|
search: 'Search',
|
2017-04-18 15:20:17 +00:00
|
|
|
notfound: 'No Emoji Found',
|
2016-10-27 03:22:59 +00:00
|
|
|
categories: {
|
|
|
|
search: 'Search Results',
|
|
|
|
recent: 'Frequently Used',
|
|
|
|
people: 'Smileys & People',
|
|
|
|
nature: 'Animals & Nature',
|
|
|
|
foods: 'Food & Drink',
|
|
|
|
activity: 'Activity',
|
|
|
|
places: 'Travel & Places',
|
|
|
|
objects: 'Objects',
|
|
|
|
symbols: 'Symbols',
|
|
|
|
flags: 'Flags',
|
2017-05-26 07:48:26 +00:00
|
|
|
custom: 'Custom',
|
2016-10-27 03:22:59 +00:00
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2017-09-29 14:46:29 +00:00
|
|
|
export default class Picker extends React.PureComponent {
|
2016-05-31 18:39:30 +00:00
|
|
|
constructor(props) {
|
|
|
|
super(props)
|
|
|
|
|
2018-03-02 18:25:39 +00:00
|
|
|
this.RECENT_CATEGORY = { id: 'recent', name: 'Recent', emojis: null }
|
|
|
|
this.CUSTOM_CATEGORY = { id: 'custom', name: 'Custom', emojis: [] }
|
|
|
|
this.SEARCH_CATEGORY = {
|
|
|
|
id: 'search',
|
|
|
|
name: 'Search',
|
|
|
|
emojis: null,
|
|
|
|
anchor: false,
|
|
|
|
}
|
|
|
|
|
2016-10-27 03:22:59 +00:00
|
|
|
this.i18n = deepMerge(I18N, props.i18n)
|
2016-05-31 18:39:30 +00:00
|
|
|
this.state = {
|
2018-03-02 18:45:33 +00:00
|
|
|
skin: props.skin || store.get('skin') || props.defaultSkin,
|
2016-07-15 16:24:50 +00:00
|
|
|
firstRender: true,
|
2016-05-31 18:39:30 +00:00
|
|
|
}
|
2017-01-30 21:01:41 +00:00
|
|
|
|
2017-04-07 21:09:30 +00:00
|
|
|
this.categories = []
|
2017-05-27 16:27:47 +00:00
|
|
|
let allCategories = [].concat(data.categories)
|
|
|
|
|
|
|
|
if (props.custom.length > 0) {
|
2018-03-02 18:25:39 +00:00
|
|
|
this.CUSTOM_CATEGORY.emojis = props.custom.map(emoji => {
|
2017-05-27 16:27:47 +00:00
|
|
|
return {
|
|
|
|
...emoji,
|
|
|
|
// `<Category />` expects emoji to have an `id`.
|
|
|
|
id: emoji.short_names[0],
|
|
|
|
custom: true,
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
2018-03-02 18:25:39 +00:00
|
|
|
allCategories.push(this.CUSTOM_CATEGORY)
|
2017-05-27 16:27:47 +00:00
|
|
|
}
|
2017-01-30 21:01:41 +00:00
|
|
|
|
2017-05-29 11:36:49 +00:00
|
|
|
this.hideRecent = true
|
2017-05-25 15:57:03 +00:00
|
|
|
|
2017-04-07 20:54:07 +00:00
|
|
|
if (props.include != undefined) {
|
2017-09-29 23:45:52 +00:00
|
|
|
allCategories.sort((a, b) => {
|
2017-12-15 20:04:51 +00:00
|
|
|
if (props.include.indexOf(a.id) > props.include.indexOf(b.id)) {
|
2017-04-07 20:54:07 +00:00
|
|
|
return 1
|
|
|
|
}
|
|
|
|
|
2018-02-15 13:39:17 +00:00
|
|
|
return -1
|
2017-04-07 20:54:07 +00:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2017-10-07 04:02:02 +00:00
|
|
|
for (
|
|
|
|
let categoryIndex = 0;
|
|
|
|
categoryIndex < allCategories.length;
|
|
|
|
categoryIndex++
|
|
|
|
) {
|
2017-09-17 08:54:22 +00:00
|
|
|
const category = allCategories[categoryIndex]
|
2017-10-07 04:02:02 +00:00
|
|
|
let isIncluded =
|
|
|
|
props.include && props.include.length
|
2017-12-15 20:04:51 +00:00
|
|
|
? props.include.indexOf(category.id) > -1
|
2017-10-07 04:02:02 +00:00
|
|
|
: true
|
|
|
|
let isExcluded =
|
|
|
|
props.exclude && props.exclude.length
|
2017-12-15 20:04:51 +00:00
|
|
|
? props.exclude.indexOf(category.id) > -1
|
2017-10-07 04:02:02 +00:00
|
|
|
: false
|
|
|
|
if (!isIncluded || isExcluded) {
|
|
|
|
continue
|
|
|
|
}
|
2017-04-04 16:00:32 +00:00
|
|
|
|
2017-04-18 14:22:32 +00:00
|
|
|
if (props.emojisToShowFilter) {
|
|
|
|
let newEmojis = []
|
2017-04-01 09:02:55 +00:00
|
|
|
|
2017-10-07 04:02:02 +00:00
|
|
|
const { emojis } = category
|
2017-09-17 08:54:22 +00:00
|
|
|
for (let emojiIndex = 0; emojiIndex < emojis.length; emojiIndex++) {
|
|
|
|
const emoji = emojis[emojiIndex]
|
2017-05-27 17:26:02 +00:00
|
|
|
if (props.emojisToShowFilter(data.emojis[emoji] || emoji)) {
|
2017-04-18 14:22:32 +00:00
|
|
|
newEmojis.push(emoji)
|
|
|
|
}
|
2017-01-30 21:01:41 +00:00
|
|
|
}
|
|
|
|
|
2017-04-18 14:22:32 +00:00
|
|
|
if (newEmojis.length) {
|
|
|
|
let newCategory = {
|
|
|
|
emojis: newEmojis,
|
|
|
|
name: category.name,
|
2018-01-09 20:20:18 +00:00
|
|
|
id: category.id,
|
2017-04-18 14:22:32 +00:00
|
|
|
}
|
2017-04-04 16:00:32 +00:00
|
|
|
|
2017-04-18 14:22:32 +00:00
|
|
|
this.categories.push(newCategory)
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
this.categories.push(category)
|
2017-01-30 21:01:41 +00:00
|
|
|
}
|
|
|
|
}
|
2017-04-04 16:00:32 +00:00
|
|
|
|
2017-10-07 04:02:02 +00:00
|
|
|
let includeRecent =
|
|
|
|
props.include && props.include.length
|
2018-03-02 18:25:39 +00:00
|
|
|
? props.include.indexOf(this.RECENT_CATEGORY.id) > -1
|
2017-10-07 04:02:02 +00:00
|
|
|
: true
|
|
|
|
let excludeRecent =
|
|
|
|
props.exclude && props.exclude.length
|
2018-03-02 18:25:39 +00:00
|
|
|
? props.exclude.indexOf(this.RECENT_CATEGORY.id) > -1
|
2017-10-07 04:02:02 +00:00
|
|
|
: false
|
2017-05-29 11:36:49 +00:00
|
|
|
if (includeRecent && !excludeRecent) {
|
|
|
|
this.hideRecent = false
|
2018-03-02 18:25:39 +00:00
|
|
|
this.categories.unshift(this.RECENT_CATEGORY)
|
2017-04-07 21:09:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (this.categories[0]) {
|
|
|
|
this.categories[0].first = true
|
|
|
|
}
|
2017-01-30 21:01:41 +00:00
|
|
|
|
2018-03-02 18:25:39 +00:00
|
|
|
this.categories.unshift(this.SEARCH_CATEGORY)
|
2017-09-29 14:46:29 +00:00
|
|
|
|
2017-10-07 04:02:02 +00:00
|
|
|
this.setAnchorsRef = this.setAnchorsRef.bind(this)
|
2017-09-29 14:46:29 +00:00
|
|
|
this.handleAnchorClick = this.handleAnchorClick.bind(this)
|
2017-10-07 04:02:02 +00:00
|
|
|
this.setSearchRef = this.setSearchRef.bind(this)
|
|
|
|
this.handleSearch = this.handleSearch.bind(this)
|
|
|
|
this.setScrollRef = this.setScrollRef.bind(this)
|
|
|
|
this.handleScroll = this.handleScroll.bind(this)
|
2017-09-29 14:46:29 +00:00
|
|
|
this.handleScrollPaint = this.handleScrollPaint.bind(this)
|
2017-10-07 04:02:02 +00:00
|
|
|
this.handleEmojiOver = this.handleEmojiOver.bind(this)
|
|
|
|
this.handleEmojiLeave = this.handleEmojiLeave.bind(this)
|
|
|
|
this.handleEmojiClick = this.handleEmojiClick.bind(this)
|
|
|
|
this.setPreviewRef = this.setPreviewRef.bind(this)
|
|
|
|
this.handleSkinChange = this.handleSkinChange.bind(this)
|
2016-05-31 18:39:30 +00:00
|
|
|
}
|
|
|
|
|
2016-06-09 00:22:06 +00:00
|
|
|
componentWillReceiveProps(props) {
|
2018-03-02 18:45:33 +00:00
|
|
|
if (props.skin) {
|
2016-07-06 17:35:09 +00:00
|
|
|
this.setState({ skin: props.skin })
|
2018-03-02 18:45:33 +00:00
|
|
|
} else if (props.defaultSkin && !store.get('skin')) {
|
|
|
|
this.setState({ skin: props.defaultSkin })
|
2016-07-06 17:35:09 +00:00
|
|
|
}
|
2016-06-09 00:22:06 +00:00
|
|
|
}
|
|
|
|
|
2016-07-15 16:24:50 +00:00
|
|
|
componentDidMount() {
|
|
|
|
if (this.state.firstRender) {
|
2016-10-04 00:49:35 +00:00
|
|
|
this.testStickyPosition()
|
2016-07-15 16:31:22 +00:00
|
|
|
this.firstRenderTimeout = setTimeout(() => {
|
2016-07-15 16:24:50 +00:00
|
|
|
this.setState({ firstRender: false })
|
|
|
|
}, 60)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-05-31 18:39:30 +00:00
|
|
|
componentDidUpdate() {
|
2016-07-08 17:56:29 +00:00
|
|
|
this.updateCategoriesSize()
|
2016-05-31 18:39:30 +00:00
|
|
|
this.handleScroll()
|
|
|
|
}
|
|
|
|
|
2016-07-15 16:31:22 +00:00
|
|
|
componentWillUnmount() {
|
2018-03-02 18:25:39 +00:00
|
|
|
this.SEARCH_CATEGORY.emojis = null
|
2016-07-18 18:42:21 +00:00
|
|
|
|
2016-07-15 16:31:22 +00:00
|
|
|
clearTimeout(this.leaveTimeout)
|
|
|
|
clearTimeout(this.firstRenderTimeout)
|
|
|
|
}
|
|
|
|
|
2016-05-31 18:39:30 +00:00
|
|
|
testStickyPosition() {
|
2017-09-17 08:54:22 +00:00
|
|
|
const stickyTestElement = document.createElement('div')
|
|
|
|
|
|
|
|
const prefixes = ['', '-webkit-', '-ms-', '-moz-', '-o-']
|
|
|
|
|
2017-10-07 04:02:02 +00:00
|
|
|
prefixes.forEach(
|
|
|
|
prefix => (stickyTestElement.style.position = `${prefix}sticky`)
|
|
|
|
)
|
2016-05-31 16:35:08 +00:00
|
|
|
|
|
|
|
this.hasStickyPosition = !!stickyTestElement.style.position.length
|
|
|
|
}
|
|
|
|
|
2016-05-31 14:36:52 +00:00
|
|
|
handleEmojiOver(emoji) {
|
2017-09-27 19:26:50 +00:00
|
|
|
var { preview } = this
|
2017-10-07 04:02:02 +00:00
|
|
|
if (!preview) {
|
|
|
|
return
|
|
|
|
}
|
2017-09-28 02:02:30 +00:00
|
|
|
|
2017-06-23 09:32:26 +00:00
|
|
|
// Use Array.prototype.find() when it is more widely supported.
|
2018-03-02 18:25:39 +00:00
|
|
|
const emojiData = this.CUSTOM_CATEGORY.emojis.filter(
|
2017-10-07 04:02:02 +00:00
|
|
|
customEmoji => customEmoji.id === emoji.id
|
|
|
|
)[0]
|
2017-09-17 08:54:22 +00:00
|
|
|
for (let key in emojiData) {
|
|
|
|
if (emojiData.hasOwnProperty(key)) {
|
2017-10-07 04:02:02 +00:00
|
|
|
emoji[key] = emojiData[key]
|
2017-09-17 08:54:22 +00:00
|
|
|
}
|
|
|
|
}
|
2017-09-28 02:02:30 +00:00
|
|
|
|
2017-09-17 08:54:22 +00:00
|
|
|
preview.setState({ emoji })
|
2016-05-31 20:53:06 +00:00
|
|
|
clearTimeout(this.leaveTimeout)
|
|
|
|
}
|
|
|
|
|
|
|
|
handleEmojiLeave(emoji) {
|
2017-09-28 02:02:30 +00:00
|
|
|
var { preview } = this
|
2017-10-07 04:02:02 +00:00
|
|
|
if (!preview) {
|
|
|
|
return
|
|
|
|
}
|
2017-09-28 02:02:30 +00:00
|
|
|
|
2016-05-31 20:53:06 +00:00
|
|
|
this.leaveTimeout = setTimeout(() => {
|
|
|
|
preview.setState({ emoji: null })
|
|
|
|
}, 16)
|
2016-05-31 14:36:52 +00:00
|
|
|
}
|
|
|
|
|
2016-07-21 19:10:33 +00:00
|
|
|
handleEmojiClick(emoji, e) {
|
|
|
|
this.props.onClick(emoji, e)
|
2017-10-07 14:26:09 +00:00
|
|
|
if (!this.hideRecent && !this.props.recent) frequently.add(emoji)
|
2016-07-07 18:22:02 +00:00
|
|
|
|
2017-09-27 19:26:50 +00:00
|
|
|
var component = this.categoryRefs['category-1']
|
2016-07-08 17:56:29 +00:00
|
|
|
if (component) {
|
2016-07-07 18:22:02 +00:00
|
|
|
let maxMargin = component.maxMargin
|
|
|
|
component.forceUpdate()
|
|
|
|
|
|
|
|
window.requestAnimationFrame(() => {
|
2017-09-29 23:14:24 +00:00
|
|
|
if (!this.scroll) return
|
2016-07-08 17:56:29 +00:00
|
|
|
component.memoizeSize()
|
2016-07-07 18:22:02 +00:00
|
|
|
if (maxMargin == component.maxMargin) return
|
|
|
|
|
2016-07-08 17:56:29 +00:00
|
|
|
this.updateCategoriesSize()
|
2016-07-07 18:22:02 +00:00
|
|
|
this.handleScrollPaint()
|
2016-10-14 01:38:24 +00:00
|
|
|
|
2018-03-02 18:25:39 +00:00
|
|
|
if (this.SEARCH_CATEGORY.emojis) {
|
2016-10-14 01:38:24 +00:00
|
|
|
component.updateDisplay('none')
|
|
|
|
}
|
2016-07-07 18:22:02 +00:00
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-05-31 16:35:08 +00:00
|
|
|
handleScroll() {
|
2016-06-02 15:26:48 +00:00
|
|
|
if (!this.waitingForPaint) {
|
|
|
|
this.waitingForPaint = true
|
2017-09-29 14:46:29 +00:00
|
|
|
window.requestAnimationFrame(this.handleScrollPaint)
|
2016-06-02 15:26:48 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
handleScrollPaint() {
|
|
|
|
this.waitingForPaint = false
|
|
|
|
|
2017-09-27 19:26:50 +00:00
|
|
|
if (!this.scroll) {
|
2016-07-15 16:24:50 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2017-05-27 17:36:41 +00:00
|
|
|
let activeCategory = null
|
|
|
|
|
2018-03-02 18:25:39 +00:00
|
|
|
if (this.SEARCH_CATEGORY.emojis) {
|
|
|
|
activeCategory = this.SEARCH_CATEGORY
|
2017-05-27 17:36:41 +00:00
|
|
|
} else {
|
2017-09-27 19:26:50 +00:00
|
|
|
var target = this.scroll,
|
2017-10-07 04:02:02 +00:00
|
|
|
scrollTop = target.scrollTop,
|
|
|
|
scrollingDown = scrollTop > (this.scrollTop || 0),
|
|
|
|
minTop = 0
|
2017-05-27 17:36:41 +00:00
|
|
|
|
|
|
|
for (let i = 0, l = this.categories.length; i < l; i++) {
|
2017-10-07 04:02:02 +00:00
|
|
|
let ii = scrollingDown ? this.categories.length - 1 - i : i,
|
|
|
|
category = this.categories[ii],
|
|
|
|
component = this.categoryRefs[`category-${ii}`]
|
2017-05-27 17:36:41 +00:00
|
|
|
|
|
|
|
if (component) {
|
|
|
|
let active = component.handleScroll(scrollTop)
|
|
|
|
|
|
|
|
if (!minTop || component.top < minTop) {
|
|
|
|
if (component.top > 0) {
|
|
|
|
minTop = component.top
|
|
|
|
}
|
2016-07-15 16:24:50 +00:00
|
|
|
}
|
|
|
|
|
2017-05-27 17:36:41 +00:00
|
|
|
if (active && !activeCategory) {
|
|
|
|
activeCategory = category
|
|
|
|
}
|
2016-05-31 16:35:08 +00:00
|
|
|
}
|
2016-06-02 15:26:48 +00:00
|
|
|
}
|
|
|
|
|
2017-05-27 17:36:41 +00:00
|
|
|
if (scrollTop < minTop) {
|
2017-10-07 04:02:02 +00:00
|
|
|
activeCategory = this.categories.filter(
|
|
|
|
category => !(category.anchor === false)
|
|
|
|
)[0]
|
2017-05-27 17:36:41 +00:00
|
|
|
} else if (scrollTop + this.clientHeight >= this.scrollHeight) {
|
|
|
|
activeCategory = this.categories[this.categories.length - 1]
|
2017-04-07 21:09:30 +00:00
|
|
|
}
|
2016-07-08 21:03:41 +00:00
|
|
|
}
|
|
|
|
|
2016-06-02 15:26:48 +00:00
|
|
|
if (activeCategory) {
|
2017-09-27 19:26:50 +00:00
|
|
|
let { anchors } = this,
|
2017-10-07 04:02:02 +00:00
|
|
|
{ name: categoryName } = activeCategory
|
2016-06-02 15:26:48 +00:00
|
|
|
|
|
|
|
if (anchors.state.selected != categoryName) {
|
|
|
|
anchors.setState({ selected: categoryName })
|
|
|
|
}
|
2016-05-31 16:35:08 +00:00
|
|
|
}
|
2016-06-02 15:26:48 +00:00
|
|
|
|
|
|
|
this.scrollTop = scrollTop
|
2016-05-31 16:35:08 +00:00
|
|
|
}
|
|
|
|
|
2016-05-31 18:39:30 +00:00
|
|
|
handleSearch(emojis) {
|
2018-03-02 18:25:39 +00:00
|
|
|
this.SEARCH_CATEGORY.emojis = emojis
|
2016-07-08 17:56:29 +00:00
|
|
|
|
2017-04-07 21:09:30 +00:00
|
|
|
for (let i = 0, l = this.categories.length; i < l; i++) {
|
2017-09-27 19:26:50 +00:00
|
|
|
let component = this.categoryRefs[`category-${i}`]
|
2016-07-08 17:56:29 +00:00
|
|
|
|
|
|
|
if (component && component.props.name != 'Search') {
|
2017-02-15 22:28:25 +00:00
|
|
|
let display = emojis ? 'none' : 'inherit'
|
2016-07-08 21:03:41 +00:00
|
|
|
component.updateDisplay(display)
|
2016-07-08 17:56:29 +00:00
|
|
|
}
|
2016-05-31 18:39:30 +00:00
|
|
|
}
|
2016-07-08 17:56:29 +00:00
|
|
|
|
|
|
|
this.forceUpdate()
|
2017-09-27 19:26:50 +00:00
|
|
|
this.scroll.scrollTop = 0
|
2017-04-23 17:25:45 +00:00
|
|
|
this.handleScroll()
|
2016-05-31 18:39:30 +00:00
|
|
|
}
|
|
|
|
|
2016-06-02 18:58:19 +00:00
|
|
|
handleAnchorClick(category, i) {
|
2017-09-27 19:26:50 +00:00
|
|
|
var component = this.categoryRefs[`category-${i}`],
|
2017-10-07 04:02:02 +00:00
|
|
|
{ scroll, anchors } = this,
|
|
|
|
scrollToComponent = null
|
2016-06-02 18:58:19 +00:00
|
|
|
|
2016-07-08 20:28:43 +00:00
|
|
|
scrollToComponent = () => {
|
|
|
|
if (component) {
|
|
|
|
let { top } = component
|
|
|
|
|
2017-04-07 21:09:30 +00:00
|
|
|
if (category.first) {
|
2016-07-08 20:28:43 +00:00
|
|
|
top = 0
|
|
|
|
} else {
|
|
|
|
top += 1
|
|
|
|
}
|
2016-06-02 18:58:19 +00:00
|
|
|
|
2016-07-08 20:28:43 +00:00
|
|
|
scroll.scrollTop = top
|
2016-06-02 18:58:19 +00:00
|
|
|
}
|
2016-07-08 20:28:43 +00:00
|
|
|
}
|
|
|
|
|
2018-03-02 18:25:39 +00:00
|
|
|
if (this.SEARCH_CATEGORY.emojis) {
|
2016-07-08 20:28:43 +00:00
|
|
|
this.handleSearch(null)
|
2017-09-27 19:26:50 +00:00
|
|
|
this.search.clear()
|
2016-06-02 18:58:19 +00:00
|
|
|
|
2016-07-08 20:28:43 +00:00
|
|
|
window.requestAnimationFrame(scrollToComponent)
|
|
|
|
} else {
|
|
|
|
scrollToComponent()
|
2016-06-02 18:58:19 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-06-09 00:22:06 +00:00
|
|
|
handleSkinChange(skin) {
|
2018-03-02 18:33:14 +00:00
|
|
|
var newState = { skin: skin },
|
|
|
|
{ onSkinChange } = this.props
|
2016-07-06 17:35:09 +00:00
|
|
|
|
|
|
|
this.setState(newState)
|
|
|
|
store.update(newState)
|
2018-03-02 18:33:14 +00:00
|
|
|
|
|
|
|
onSkinChange(skin)
|
2016-06-09 00:22:06 +00:00
|
|
|
}
|
|
|
|
|
2016-07-08 17:56:29 +00:00
|
|
|
updateCategoriesSize() {
|
2017-04-07 21:09:30 +00:00
|
|
|
for (let i = 0, l = this.categories.length; i < l; i++) {
|
2017-09-27 19:26:50 +00:00
|
|
|
let component = this.categoryRefs[`category-${i}`]
|
2016-07-08 17:56:29 +00:00
|
|
|
if (component) component.memoizeSize()
|
|
|
|
}
|
2017-05-27 16:58:46 +00:00
|
|
|
|
2017-09-27 19:26:50 +00:00
|
|
|
if (this.scroll) {
|
|
|
|
let target = this.scroll
|
2017-05-27 16:58:46 +00:00
|
|
|
this.scrollHeight = target.scrollHeight
|
|
|
|
this.clientHeight = target.clientHeight
|
|
|
|
}
|
2016-07-08 17:56:29 +00:00
|
|
|
}
|
|
|
|
|
2016-07-15 16:24:50 +00:00
|
|
|
getCategories() {
|
2017-10-07 04:02:02 +00:00
|
|
|
return this.state.firstRender
|
|
|
|
? this.categories.slice(0, 3)
|
|
|
|
: this.categories
|
2016-07-15 16:24:50 +00:00
|
|
|
}
|
|
|
|
|
2017-09-27 19:26:50 +00:00
|
|
|
setAnchorsRef(c) {
|
|
|
|
this.anchors = c
|
|
|
|
}
|
|
|
|
|
|
|
|
setSearchRef(c) {
|
|
|
|
this.search = c
|
|
|
|
}
|
|
|
|
|
|
|
|
setPreviewRef(c) {
|
|
|
|
this.preview = c
|
|
|
|
}
|
|
|
|
|
|
|
|
setScrollRef(c) {
|
|
|
|
this.scroll = c
|
|
|
|
}
|
|
|
|
|
|
|
|
setCategoryRef(name, c) {
|
|
|
|
if (!this.categoryRefs) {
|
|
|
|
this.categoryRefs = {}
|
|
|
|
}
|
|
|
|
|
|
|
|
this.categoryRefs[name] = c
|
|
|
|
}
|
|
|
|
|
2016-05-31 14:36:52 +00:00
|
|
|
render() {
|
2017-10-07 04:02:02 +00:00
|
|
|
var {
|
|
|
|
perLine,
|
|
|
|
emojiSize,
|
|
|
|
set,
|
|
|
|
sheetSize,
|
|
|
|
style,
|
|
|
|
title,
|
|
|
|
emoji,
|
|
|
|
color,
|
|
|
|
native,
|
|
|
|
backgroundImageFn,
|
|
|
|
emojisToShowFilter,
|
|
|
|
showPreview,
|
2018-03-02 20:08:52 +00:00
|
|
|
showSkinTones,
|
2017-10-07 04:02:02 +00:00
|
|
|
emojiTooltip,
|
|
|
|
include,
|
|
|
|
exclude,
|
2017-10-07 14:26:09 +00:00
|
|
|
recent,
|
2017-10-07 04:02:02 +00:00
|
|
|
autoFocus,
|
|
|
|
} = this.props,
|
|
|
|
{ skin } = this.state,
|
|
|
|
width = perLine * (emojiSize + 12) + 12 + 2 + measureScrollbar()
|
|
|
|
|
|
|
|
return (
|
|
|
|
<div style={{ width: width, ...style }} className="emoji-mart">
|
|
|
|
<div className="emoji-mart-bar">
|
|
|
|
<Anchors
|
|
|
|
ref={this.setAnchorsRef}
|
2016-10-27 03:22:59 +00:00
|
|
|
i18n={this.i18n}
|
2017-10-07 04:02:02 +00:00
|
|
|
color={color}
|
|
|
|
categories={this.categories}
|
|
|
|
onAnchorClick={this.handleAnchorClick}
|
2016-05-31 14:36:52 +00:00
|
|
|
/>
|
2017-10-07 04:02:02 +00:00
|
|
|
</div>
|
2016-05-31 14:36:52 +00:00
|
|
|
|
2017-10-07 04:02:02 +00:00
|
|
|
<Search
|
|
|
|
ref={this.setSearchRef}
|
|
|
|
onSearch={this.handleSearch}
|
|
|
|
i18n={this.i18n}
|
|
|
|
emojisToShowFilter={emojisToShowFilter}
|
|
|
|
include={include}
|
|
|
|
exclude={exclude}
|
2018-03-02 18:25:39 +00:00
|
|
|
custom={this.CUSTOM_CATEGORY.emojis}
|
2017-10-07 04:02:02 +00:00
|
|
|
autoFocus={autoFocus}
|
2016-05-31 14:36:52 +00:00
|
|
|
/>
|
2017-10-07 04:02:02 +00:00
|
|
|
|
|
|
|
<div
|
|
|
|
ref={this.setScrollRef}
|
|
|
|
className="emoji-mart-scroll"
|
|
|
|
onScroll={this.handleScroll}
|
|
|
|
>
|
|
|
|
{this.getCategories().map((category, i) => {
|
|
|
|
return (
|
|
|
|
<Category
|
|
|
|
ref={this.setCategoryRef.bind(this, `category-${i}`)}
|
|
|
|
key={category.name}
|
2017-12-08 17:45:31 +00:00
|
|
|
id={category.id}
|
2017-10-07 04:02:02 +00:00
|
|
|
name={category.name}
|
|
|
|
emojis={category.emojis}
|
|
|
|
perLine={perLine}
|
|
|
|
native={native}
|
|
|
|
hasStickyPosition={this.hasStickyPosition}
|
|
|
|
i18n={this.i18n}
|
2018-03-02 20:10:04 +00:00
|
|
|
recent={
|
|
|
|
category.id == this.RECENT_CATEGORY.id ? recent : undefined
|
|
|
|
}
|
2017-10-07 04:02:02 +00:00
|
|
|
custom={
|
2018-03-02 18:25:39 +00:00
|
|
|
category.id == this.RECENT_CATEGORY.id
|
|
|
|
? this.CUSTOM_CATEGORY.emojis
|
2017-12-15 20:31:49 +00:00
|
|
|
: undefined
|
2017-10-07 04:02:02 +00:00
|
|
|
}
|
|
|
|
emojiProps={{
|
|
|
|
native: native,
|
|
|
|
skin: skin,
|
|
|
|
size: emojiSize,
|
|
|
|
set: set,
|
|
|
|
sheetSize: sheetSize,
|
|
|
|
forceSize: native,
|
|
|
|
tooltip: emojiTooltip,
|
|
|
|
backgroundImageFn: backgroundImageFn,
|
|
|
|
onOver: this.handleEmojiOver,
|
|
|
|
onLeave: this.handleEmojiLeave,
|
|
|
|
onClick: this.handleEmojiClick,
|
|
|
|
}}
|
|
|
|
/>
|
|
|
|
)
|
|
|
|
})}
|
|
|
|
</div>
|
|
|
|
|
|
|
|
{showPreview && (
|
|
|
|
<div className="emoji-mart-bar">
|
|
|
|
<Preview
|
|
|
|
ref={this.setPreviewRef}
|
|
|
|
title={title}
|
|
|
|
emoji={emoji}
|
2018-03-02 20:08:52 +00:00
|
|
|
showSkinTones={showSkinTones}
|
2017-10-07 04:02:02 +00:00
|
|
|
emojiProps={{
|
|
|
|
native: native,
|
|
|
|
size: 38,
|
|
|
|
skin: skin,
|
|
|
|
set: set,
|
|
|
|
sheetSize: sheetSize,
|
|
|
|
backgroundImageFn: backgroundImageFn,
|
|
|
|
}}
|
|
|
|
skinsProps={{
|
|
|
|
skin: skin,
|
|
|
|
onChange: this.handleSkinChange,
|
|
|
|
}}
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
)}
|
|
|
|
</div>
|
|
|
|
)
|
2016-05-31 14:36:52 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Picker.propTypes = {
|
2017-05-05 01:38:03 +00:00
|
|
|
onClick: PropTypes.func,
|
2018-03-02 18:33:14 +00:00
|
|
|
onSkinChange: PropTypes.func,
|
2017-05-05 01:38:03 +00:00
|
|
|
perLine: PropTypes.number,
|
|
|
|
emojiSize: PropTypes.number,
|
|
|
|
i18n: PropTypes.object,
|
|
|
|
style: PropTypes.object,
|
|
|
|
title: PropTypes.string,
|
|
|
|
emoji: PropTypes.string,
|
|
|
|
color: PropTypes.string,
|
2016-10-27 00:55:44 +00:00
|
|
|
set: Emoji.propTypes.set,
|
2016-10-27 01:04:05 +00:00
|
|
|
skin: Emoji.propTypes.skin,
|
2017-05-05 01:38:03 +00:00
|
|
|
native: PropTypes.bool,
|
2017-02-17 15:13:59 +00:00
|
|
|
backgroundImageFn: Emoji.propTypes.backgroundImageFn,
|
2016-10-27 01:31:56 +00:00
|
|
|
sheetSize: Emoji.propTypes.sheetSize,
|
2017-05-05 01:38:03 +00:00
|
|
|
emojisToShowFilter: PropTypes.func,
|
2017-09-28 02:02:30 +00:00
|
|
|
showPreview: PropTypes.bool,
|
2018-03-02 20:08:52 +00:00
|
|
|
showSkinTones: PropTypes.bool,
|
2017-10-07 03:34:06 +00:00
|
|
|
emojiTooltip: Emoji.propTypes.tooltip,
|
2017-05-05 01:38:03 +00:00
|
|
|
include: PropTypes.arrayOf(PropTypes.string),
|
|
|
|
exclude: PropTypes.arrayOf(PropTypes.string),
|
2017-10-07 14:26:09 +00:00
|
|
|
recent: PropTypes.arrayOf(PropTypes.string),
|
2017-05-05 01:38:03 +00:00
|
|
|
autoFocus: PropTypes.bool,
|
2017-10-07 04:02:02 +00:00
|
|
|
custom: PropTypes.arrayOf(
|
|
|
|
PropTypes.shape({
|
|
|
|
name: PropTypes.string.isRequired,
|
|
|
|
short_names: PropTypes.arrayOf(PropTypes.string).isRequired,
|
|
|
|
emoticons: PropTypes.arrayOf(PropTypes.string),
|
|
|
|
keywords: PropTypes.arrayOf(PropTypes.string),
|
|
|
|
imageUrl: PropTypes.string.isRequired,
|
|
|
|
})
|
|
|
|
),
|
2016-05-31 14:36:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Picker.defaultProps = {
|
2017-10-07 04:02:02 +00:00
|
|
|
onClick: () => {},
|
2018-03-02 18:33:14 +00:00
|
|
|
onSkinChange: () => {},
|
2016-05-31 21:23:51 +00:00
|
|
|
emojiSize: 24,
|
2016-05-31 14:36:52 +00:00
|
|
|
perLine: 9,
|
2016-10-27 03:22:59 +00:00
|
|
|
i18n: {},
|
2016-07-11 18:08:41 +00:00
|
|
|
style: {},
|
2016-07-27 15:35:12 +00:00
|
|
|
title: 'Emoji Mart™',
|
|
|
|
emoji: 'department_store',
|
2016-07-21 19:33:18 +00:00
|
|
|
color: '#ae65c5',
|
2016-10-27 00:55:44 +00:00
|
|
|
set: Emoji.defaultProps.set,
|
2018-03-02 18:45:33 +00:00
|
|
|
skin: null,
|
|
|
|
defaultSkin: Emoji.defaultProps.skin,
|
2017-02-17 15:13:59 +00:00
|
|
|
native: Emoji.defaultProps.native,
|
2016-10-27 01:31:56 +00:00
|
|
|
sheetSize: Emoji.defaultProps.sheetSize,
|
2016-11-30 19:21:40 +00:00
|
|
|
backgroundImageFn: Emoji.defaultProps.backgroundImageFn,
|
2017-04-18 14:22:32 +00:00
|
|
|
emojisToShowFilter: null,
|
2017-09-28 02:02:30 +00:00
|
|
|
showPreview: true,
|
2018-03-02 20:08:52 +00:00
|
|
|
showSkinTones: true,
|
2017-10-07 03:34:06 +00:00
|
|
|
emojiTooltip: Emoji.defaultProps.tooltip,
|
2017-04-04 15:07:48 +00:00
|
|
|
autoFocus: false,
|
2017-05-26 07:48:26 +00:00
|
|
|
custom: [],
|
2016-05-31 14:36:52 +00:00
|
|
|
}
|