amend(collectionRepeat): do not allow computed height/width to be 0

This commit is contained in:
Andrew
2015-02-25 10:42:04 -07:00
parent e87449440e
commit 25f77dde58

View File

@@ -4,7 +4,7 @@
* @restrict A
* @name collectionRepeat
* @module ionic
* @codepen mFygh
* @codepen 7ec1ec58f2489ab8f359fa1a0fe89c15
* @description
* `collection-repeat` allows an app to show huge lists of items much more performantly than
* `ng-repeat`.
@@ -30,7 +30,7 @@
* if possible, lower the number of unique images. Check out [this codepen]().
*
* @usage
* #### Basic Item List (codepen)
* #### Basic Item List ([codepen](http://codepen.io/ionic/pen/0c2c35a34a8b18ad4d793fef0b081693))
* ```html
* <ion-content>
* <ion-item collection-repeat="item in items">
@@ -39,7 +39,7 @@
* </ion-content>
* ```
*
* #### Grid of Images (codepen)
* #### Grid of Images ([codepen])
* ```html
* <ion-content>
* <img collection-repeat="photo in photos"
@@ -208,12 +208,22 @@ function CollectionRepeatDirective($ionicCollectionManager, $parse, $window, $$r
if (heightData.computed) {
heightData.value = computedStyleDimensions.height;
if (!heightData.value) {
throw new Error('collection-repeat tried to compute the height of elements "' +
listExpression + '", but was unable to. Please provide the "item-height" attribute. ' +
'http://ionicframework.com/docs/api/directive/collectionRepeat/');
}
} else if (!heightData.dynamic && heightData.getValue) {
// If it's a constant with a getter (eg percent), we just refresh .value after resize
heightData.value = heightData.getValue();
}
if (widthData.computed) {
widthData.value = computedStyleDimensions.width;
if (!widthData.value) {
throw new Error('collection-repeat tried to compute the width of elements in "' +
listExpression + '", but was unable to. Please provide the "item-width" attribute. ' +
'http://ionicframework.com/docs/api/directive/collectionRepeat/');
}
} else if (!widthData.dynamic && widthData.getValue) {
// If it's a constant with a getter (eg percent), we just refresh .value after resize
widthData.value = widthData.getValue();
@@ -518,10 +528,13 @@ function RepeatManagerFactory($rootScope, $window, $$rAF) {
// one frame, causing visible jank.
// DON'T call any other functions inside this loop unless it's vital.
for (i = renderStartIndex; i <= renderEndIndex; i++) {
// If the item at this index is already shown, skip
if (i >= data.length || itemsShownMap[i] && !forceRerender) continue;
// We only go forward with render if the index is in data, the item isn't already shown,
// or forceRerender is on.
if (i >= data.length || (itemsShownMap[i] && !forceRerender)) continue;
item = itemsShownMap[i] || (itemsShownMap[i] = getNextItem());
item = itemsShownMap[i] || (itemsShownMap[i] = itemsLeaving.length ? itemsLeaving.pop() :
itemsPool.length ? itemsPool.shift() :
new RepeatItem())
itemsEntering.push(item);
item.isShown = true;
@@ -606,13 +619,13 @@ function RepeatManagerFactory($rootScope, $window, $$rAF) {
$$rAF(function process() {
if( (len = itemsEntering.length) ) {
var count = Math.floor(len / 1.5) || 1;
var rootScopePhase = $rootScope.$$phase;
var count = Math.floor(len / 1.25) || 1;
while (count && itemsEntering.length) {
item = itemsEntering.pop();
if (item.isShown) {
count--;
if (!$rootScope.$$phase) item.scope.$digest();
if (!rootScopePhase) item.scope.$digest();
}
}
$$rAF(process);