collectionRepeat: fixes

This commit is contained in:
Andy Joslin
2014-04-24 08:56:25 -06:00
parent e5e5b911f7
commit b9fd76b35b
2 changed files with 13 additions and 10 deletions

View File

@@ -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();
});

View File

@@ -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];
}