mirror of
https://github.com/ionic-team/ionic-framework.git
synced 2026-03-13 10:22:08 +08:00
collectionRepeat: fixes
This commit is contained in:
5
js/angular/directive/collectionRepeat.js
vendored
5
js/angular/directive/collectionRepeat.js
vendored
@@ -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();
|
||||
});
|
||||
|
||||
18
js/angular/service/collectionRepeatManager.js
vendored
18
js/angular/service/collectionRepeatManager.js
vendored
@@ -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];
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user