From b9fd76b35b931aee9eb0fdee49d3035d75361e6d Mon Sep 17 00:00:00 2001 From: Andy Joslin Date: Thu, 24 Apr 2014 08:56:25 -0600 Subject: [PATCH] collectionRepeat: fixes --- js/angular/directive/collectionRepeat.js | 5 +++++ js/angular/service/collectionRepeatManager.js | 18 ++++++++---------- 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/js/angular/directive/collectionRepeat.js b/js/angular/directive/collectionRepeat.js index 7326d0de22..4cfcbf863b 100644 --- a/js/angular/directive/collectionRepeat.js +++ b/js/angular/directive/collectionRepeat.js @@ -28,6 +28,10 @@ function($collectionRepeatManager, $collectionRepeatDataSource, $parse) { var widthGetter = $attr.collectionItemWidth ? $parse($attr.collectionItemWidth) : function() { return scrollView.__clientWidth; }; + console.log(widthGetter()); + setTimeout(function() { + console.log(widthGetter()); + }); var match = $attr.collectionRepeat.match(/^\s*([\s\S]+?)\s+in\s+([\s\S]+?)(?:\s+track\s+by\s+([\s\S]+?))?\s*$/); if (!match) { @@ -54,6 +58,7 @@ function($collectionRepeatManager, $collectionRepeatDataSource, $parse) { if (value && !angular.isArray(value)) { throw new Error("collection-repeat expects an array to repeat over, but instead got '" + typeof value + "'."); } + scrollView.resize(); dataSource.setData(value); collectionRepeatManager.resize(); }); diff --git a/js/angular/service/collectionRepeatManager.js b/js/angular/service/collectionRepeatManager.js index 03b0e1e723..ad7691de95 100644 --- a/js/angular/service/collectionRepeatManager.js +++ b/js/angular/service/collectionRepeatManager.js @@ -68,8 +68,6 @@ function($rootScope, $timeout) { } }, resize: function() { - this.scrollView.resize(); - var primaryPos = 0; var secondaryPos = 0; var itemsPerSpace = 0; @@ -77,23 +75,21 @@ function($rootScope, $timeout) { this.dimensions = this.dataSource.dimensions.map(function(dimensions, index) { var rect = { primarySize: this.isVertical ? dimensions.height : dimensions.width, - secondarySize: this.isVertical ? dimensions.width: dimensions.height, + secondarySize: this.isVertical ? dimensions.width : dimensions.height, primaryPos: primaryPos, secondaryPos: secondaryPos }; - if (secondaryPos + rect.secondarySize >= this.getSecondaryScrollSize()) { + itemsPerSpace++; + secondaryPos += rect.secondarySize; + if (secondaryPos >= this.getSecondaryScrollSize()) { secondaryPos = 0; primaryPos += rect.primarySize; - rect.primaryPos = primaryPos; - rect.secondaryPos = secondaryPos; if (!this.itemsPerSpace) { this.itemsPerSpace = itemsPerSpace; } } - itemsPerSpace++; - secondaryPos += rect.secondarySize; return rect; }, this); @@ -147,6 +143,10 @@ function($rootScope, $timeout) { return i; }, render: function(shouldRedrawAll) { + if (this.currentIndex >= this.dataSource.getLength()) { + return; + } + var i; if (shouldRedrawAll) { for (i in this.renderedItems) { @@ -157,7 +157,6 @@ function($rootScope, $timeout) { var scrollDelta = scrollValue - this.lastRenderScrollValue; var scrollSize = this.scrollSize(); var scrollSizeEnd = scrollSize + scrollValue; - var startIndex = this.getIndexForScrollValue(this.currentIndex, scrollValue); var bufferStartIndex = Math.max(0, startIndex - this.itemsPerSpace); var startPos = this.dimensions[bufferStartIndex].primaryPos; @@ -199,7 +198,6 @@ function($rootScope, $timeout) { removeItem: function(dataIndex) { var item = this.renderedItems[dataIndex]; if (item) { - console.log('removing', dataIndex, item); this.dataSource.detachItem(item); delete this.renderedItems[dataIndex]; }