Skip to content

Commit 1e36afc

Browse files
committed
fix(collectionRepeat): compute width when height is not given
Closes #3357.
1 parent 6c08b78 commit 1e36afc

File tree

3 files changed

+23
-17
lines changed

3 files changed

+23
-17
lines changed

Diff for: js/angular/directive/collectionRepeat.js

+7-8
Original file line numberDiff line numberDiff line change
@@ -268,16 +268,15 @@ function CollectionRepeatDirective($ionicCollectionManager, $parse, $window, $$r
268268
//4) Dynamic Mode
269269
// - The user provides a dynamic expression for the width or height. This is re-evaluated
270270
// for every item, stored on the `.getValue()` field.
271-
if (!heightExpr && !widthExpr) {
272-
heightData.computed = widthData.computed = true;
271+
if (heightExpr) {
272+
parseDimensionAttr(heightExpr, heightData);
273273
} else {
274-
if (heightExpr) {
275-
parseDimensionAttr(heightExpr, heightData);
276-
} else {
277-
heightData.computed = true;
278-
}
279-
if (!widthExpr) widthExpr = '"100%"';
274+
heightData.computed = true;
275+
}
276+
if (widthExpr) {
280277
parseDimensionAttr(widthExpr, widthData);
278+
} else {
279+
widthData.computed = true;
281280
}
282281
}
283282

Diff for: test/html/collection-repeat/basic-list.html

+2-2
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ <h1 class="title">Basic List: Static Dimensions</h1>
1919
</ion-header-bar>
2020
<ion-content>
2121
<h4 style="margin: 80px;">I have 80px margin</h4>
22-
<ion-list can-swipe="true" show-delete="$root.showDelete">
23-
<ion-item class="item" collection-repeat="item in items">
22+
<ion-list>
23+
<ion-item class="item card" collection-repeat="item in items" item-height="50px">
2424
<ion-option-button>Button</ion-option-button>
2525
<ion-delete-button class="ion-minus-circled" ng-click="items.splice($index, 1)"></ion-delete-button>
2626
<h2>{{item.text}}</h2>

Diff for: test/unit/angular/directive/collectionRepeat.unit.js

+14-7
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
describe('collectionRepeat', function() {
2-
32
var el;
43
beforeEach(module('ionic', function($provide) {
54
$provide.decorator('$$rAF', function($delegate) {
@@ -222,6 +221,10 @@ describe('collectionRepeat', function() {
222221
}));
223222

224223
it('should refresh layout on scrollCtrl.resize', inject(function($timeout, $window) {
224+
spyOn($window, 'getComputedStyle').andReturn({
225+
width: '1px',
226+
height: '50px'
227+
});
225228
var el = setup(10, 'item-height="20px"', {
226229
__clientHeight: 50,
227230
__clientWidth: 1
@@ -289,16 +292,20 @@ describe('collectionRepeat', function() {
289292
});
290293

291294
describe('vertical static list', function() {
292-
beforeEach(function() {
295+
beforeEach(inject(function($window) {
296+
spyOn($window, 'getComputedStyle').andReturn({
297+
width: '50px',
298+
height: '50px'
299+
});
293300
setup(10);
294-
});
301+
}));
295302

296303
it('should show initial screen of items', function() {
297304
expect(activeItems().length).toBe(5);
298305
expect(activeItemContents()).toEqual(['0','1','2','3','4']);
299306
});
300307

301-
it('should switch out as you scroll', function() {
308+
it('should switch out as you scroll', inject(function($window) {
302309
expect(activeItems().length).toBe(5);
303310
expect(activeItemContents()).toEqual(['0','1','2','3','4']);
304311
expect(activeItemIds()).toEqual(['item0','item1','item2','item3','item4']);
@@ -323,7 +330,7 @@ describe('collectionRepeat', function() {
323330
expect(activeItems().length).toBe(5);
324331
expect(activeItemContents()).toEqual(['5','6','7','8','9']);
325332
expect(activeItemIds()).toEqual(['item0','item1','item2','item3','item4']);
326-
});
333+
}));
327334

328335
it('should start with the same items when resizing', inject(function($window) {
329336
scrollTo(26);
@@ -338,8 +345,8 @@ describe('collectionRepeat', function() {
338345
angular.element($window).triggerHandler('resize');
339346

340347
expect(activeItems().length).toBe(2);
341-
expect(activeItemContents()).toEqual(['2','3']);
342-
expect(activeItemIds()).toEqual(['item2','item3']);
348+
expect(activeItemContents()).toEqual(['8','9']);
349+
expect(activeItemIds()).toEqual(['item1','item0']);
343350
}));
344351

345352
});

0 commit comments

Comments
 (0)