always preload first batch of emoji to avoid unnecessary UI jumps

This commit is contained in:
Henry Jameson 2019-10-09 22:33:15 +03:00
parent fa4e69ec8c
commit b02de56fcb

View file

@ -24,9 +24,10 @@ const EmojiPicker = {
showingStickers: false, showingStickers: false,
groupsScrolledClass: 'scrolled-top', groupsScrolledClass: 'scrolled-top',
keepOpen: false, keepOpen: false,
customEmojiBuffer: [], customEmojiBuffer: (this.$store.state.instance.customEmoji || [])
.slice(0, LOAD_EMOJI_BY),
customEmojiTimeout: null, customEmojiTimeout: null,
customEmojiCounter: 0, customEmojiCounter: LOAD_EMOJI_BY,
customEmojiLoadAllConfirmed: false customEmojiLoadAllConfirmed: false
} }
}, },
@ -88,13 +89,23 @@ const EmojiPicker = {
this.customEmojiTimeout = window.setTimeout(this.loadEmoji, LOAD_EMOJI_INTERVAL) this.customEmojiTimeout = window.setTimeout(this.loadEmoji, LOAD_EMOJI_INTERVAL)
this.customEmojiCounter += LOAD_EMOJI_BY this.customEmojiCounter += LOAD_EMOJI_BY
}, },
startEmojiLoad () { startEmojiLoad (forceUpdate = false) {
const bufferSize = this.customEmojiBuffer.length
const bufferPrefilledSane = bufferSize === LOAD_EMOJI_SANE_AMOUNT && !this.customEmojiLoadAllConfirmed
const bufferPrefilledAll = bufferSize === this.filteredEmoji.length
if (!forceUpdate || bufferPrefilledSane || bufferPrefilledAll) {
return
}
if (this.customEmojiTimeout) { if (this.customEmojiTimeout) {
window.clearTimeout(this.customEmojiTimeout) window.clearTimeout(this.customEmojiTimeout)
} }
set(this, 'customEmojiBuffer', []) set(
this.customEmojiCounter = 0 this,
'customEmojiBuffer',
this.filteredEmoji.slice(0, LOAD_EMOJI_BY)
)
this.customEmojiCounter = LOAD_EMOJI_BY
this.customEmojiTimeout = window.setTimeout(this.loadEmoji, LOAD_EMOJI_INTERVAL) this.customEmojiTimeout = window.setTimeout(this.loadEmoji, LOAD_EMOJI_INTERVAL)
}, },
continueEmojiLoad () { continueEmojiLoad () {
@ -115,8 +126,9 @@ const EmojiPicker = {
}, },
watch: { watch: {
keyword () { keyword () {
this.customEmojiLoadAllConfirmed = false
this.scrolledGroup() this.scrolledGroup()
this.startEmojiLoad() this.startEmojiLoad(true)
} }
}, },
computed: { computed: {