Last active
November 27, 2017 15:16
-
-
Save t9md/704ff030ab8341dd5f3ad51d598228e4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
renderItems () { | |
if (this.items.length > 0) { | |
const className = ['list-group'].concat(this.props.itemsClassList || []).join(' ') | |
if (this.observer) { | |
etch.getScheduler().getNextUpdatePromise().then(() => { | |
const elements = Array.from(this.refs.items.children) | |
// Use initially rendered last item's height as height of all fake item | |
// Refering 1st item is bad idea, since 1st item tend to be rendered differently. | |
// const heightForFakeItem = elements.slice(0, this.props.initialRenderItemCount).pop().offsetHeight + 'px' | |
const heightForFakeItem = elements.slice(0, this.props.initialRenderItemCount).pop().scrollHeight + 'px' | |
elements.slice(this.props.initialRenderItemCount).forEach(element => { | |
element.style.height = heightForFakeItem | |
this.observer.observe(element) | |
}) | |
}) | |
} | |
this.listItems = this.items.map((item, index) => { | |
const selected = this.getSelectedItem() === item | |
return $(ListItemView, { | |
element: this.elementForItem(item, {selected, index}), | |
selected: selected, | |
onclick: () => this.didClickItem(index) | |
}) | |
}) | |
return $.ol( | |
{className, ref: 'items'}, | |
...this.listItems | |
) | |
} else if (!this.props.loadingMessage && this.props.emptyMessage) { | |
return $.span({ref: 'emptyMessage'}, this.props.emptyMessage) | |
} else { | |
return "" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment