From 00b1816986f252fe42d83b978a93154e81c7548b Mon Sep 17 00:00:00 2001 From: Bruno Windels Date: Thu, 24 Oct 2019 16:01:34 +0200 Subject: [PATCH] use LazyRenderList in emoji picker Category --- src/components/views/emojipicker/Category.js | 48 +++++++++++++++++--- 1 file changed, 41 insertions(+), 7 deletions(-) diff --git a/src/components/views/emojipicker/Category.js b/src/components/views/emojipicker/Category.js index ba48c8842b..ba525b76e2 100644 --- a/src/components/views/emojipicker/Category.js +++ b/src/components/views/emojipicker/Category.js @@ -16,9 +16,11 @@ limitations under the License. import React from 'react'; import PropTypes from 'prop-types'; - +import { CATEGORY_HEADER_HEIGHT, EMOJI_HEIGHT, EMOJIS_PER_ROW } from "./EmojiPicker"; import sdk from '../../../index'; +const OVERFLOW_ROWS = 3; + class Category extends React.PureComponent { static propTypes = { emojis: PropTypes.arrayOf(PropTypes.object).isRequired, @@ -30,22 +32,54 @@ class Category extends React.PureComponent { selectedEmojis: PropTypes.instanceOf(Set), }; + _renderEmojiRow = (rowIndex) => { + const { onClick, onMouseEnter, onMouseLeave, selectedEmojis, emojis } = this.props; + const emojisForRow = emojis.slice(rowIndex * 8, (rowIndex + 1) * 8); + const Emoji = sdk.getComponent("emojipicker.Emoji"); + return (
{ + emojisForRow.map(emoji => + ) + }
); + }; + render() { - const { onClick, onMouseEnter, onMouseLeave, emojis, name, selectedEmojis } = this.props; + const { emojis, name, heightBefore, viewportHeight, scrollTop } = this.props; if (!emojis || emojis.length === 0) { return null; } + const rows = new Array(Math.ceil(emojis.length / EMOJIS_PER_ROW)); + for (let counter = 0; counter < rows.length; ++counter) { + rows[counter] = counter; + } + const LazyRenderList = sdk.getComponent('elements.LazyRenderList'); + + const viewportTop = scrollTop; + const viewportBottom = viewportTop + viewportHeight; + const listTop = heightBefore + CATEGORY_HEADER_HEIGHT; + const listBottom = listTop + (rows.length * EMOJI_HEIGHT); + const top = Math.max(viewportTop, listTop); + const bottom = Math.min(viewportBottom, listBottom); + // the viewport height and scrollTop passed to the LazyRenderList + // is capped at the intersection with the real viewport, so lists + // out of view are passed height 0, so they won't render any items. + const localHeight = Math.max(0, bottom - top); + const localScrollTop = Math.max(0, scrollTop - listTop); - const Emoji = sdk.getComponent("emojipicker.Emoji"); return (

{name}

- + +
); }