Skip to content

Instantly share code, notes, and snippets.

@lukemelia
Created October 6, 2015 00:58
Show Gist options
  • Save lukemelia/5719e2cae9c5c1ea6ab7 to your computer and use it in GitHub Desktop.
Save lukemelia/5719e2cae9c5c1ea6ab7 to your computer and use it in GitHub Desktop.
import ShelfFirst from 'layout-bin-packer/shelf-first';
export default class ListWithHeaders
{
constructor(content, width) {
this.content = content;
this.width = width;
this.bin = new ShelfFirst(content, width);
var bin = this.bin;
bin.length = function() {
return content.get('length');
};
bin.widthAtIndex = function() {
return width;
};
bin.heightAtIndex = function(index) {
if (this.content.objectAt(index).group) {
return 37;
}
return 49;
};
}
contentSize(clientSize) {
return {
width: clientSize.width,
height: this.bin.height()
};
}
indexAt(offsetX, offsetY, width, height) {
return this.bin.visibleStartingIndex(offsetY, width, height);
}
positionAt(index, width /*,height*/) {
var position = this.bin.position(index, width);
return position;
}
widthAt() {
return this.width;
}
heightAt(index) {
return this.bin.heightAtIndex(index);
}
count(offsetX, offsetY, width, height) {
return this.bin.numberVisibleWithin(offsetY, width, height, true);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment