From 1e36afc6537ec2ee0d789b2b5986dd13abe69dda Mon Sep 17 00:00:00 2001 From: Andrew Date: Mon, 6 Apr 2015 18:22:27 -0600 Subject: [PATCH] fix(collectionRepeat): compute width when height is not given Closes #3357. --- js/angular/directive/collectionRepeat.js | 15 +++++++------ test/html/collection-repeat/basic-list.html | 4 ++-- .../directive/collectionRepeat.unit.js | 21 ++++++++++++------- 3 files changed, 23 insertions(+), 17 deletions(-) diff --git a/js/angular/directive/collectionRepeat.js b/js/angular/directive/collectionRepeat.js index 510b2bb7e4b..0ac024c7f3a 100644 --- a/js/angular/directive/collectionRepeat.js +++ b/js/angular/directive/collectionRepeat.js @@ -268,16 +268,15 @@ function CollectionRepeatDirective($ionicCollectionManager, $parse, $window, $$r //4) Dynamic Mode // - The user provides a dynamic expression for the width or height. This is re-evaluated // for every item, stored on the `.getValue()` field. - if (!heightExpr && !widthExpr) { - heightData.computed = widthData.computed = true; + if (heightExpr) { + parseDimensionAttr(heightExpr, heightData); } else { - if (heightExpr) { - parseDimensionAttr(heightExpr, heightData); - } else { - heightData.computed = true; - } - if (!widthExpr) widthExpr = '"100%"'; + heightData.computed = true; + } + if (widthExpr) { parseDimensionAttr(widthExpr, widthData); + } else { + widthData.computed = true; } } diff --git a/test/html/collection-repeat/basic-list.html b/test/html/collection-repeat/basic-list.html index 0e01be4e4f6..2bc97645310 100644 --- a/test/html/collection-repeat/basic-list.html +++ b/test/html/collection-repeat/basic-list.html @@ -19,8 +19,8 @@

Basic List: Static Dimensions

I have 80px margin

- - + + Button

{{item.text}}

diff --git a/test/unit/angular/directive/collectionRepeat.unit.js b/test/unit/angular/directive/collectionRepeat.unit.js index 48a5b685040..f850d9e5d0f 100644 --- a/test/unit/angular/directive/collectionRepeat.unit.js +++ b/test/unit/angular/directive/collectionRepeat.unit.js @@ -1,5 +1,4 @@ describe('collectionRepeat', function() { - var el; beforeEach(module('ionic', function($provide) { $provide.decorator('$$rAF', function($delegate) { @@ -222,6 +221,10 @@ describe('collectionRepeat', function() { })); it('should refresh layout on scrollCtrl.resize', inject(function($timeout, $window) { + spyOn($window, 'getComputedStyle').andReturn({ + width: '1px', + height: '50px' + }); var el = setup(10, 'item-height="20px"', { __clientHeight: 50, __clientWidth: 1 @@ -289,16 +292,20 @@ describe('collectionRepeat', function() { }); describe('vertical static list', function() { - beforeEach(function() { + beforeEach(inject(function($window) { + spyOn($window, 'getComputedStyle').andReturn({ + width: '50px', + height: '50px' + }); setup(10); - }); + })); it('should show initial screen of items', function() { expect(activeItems().length).toBe(5); expect(activeItemContents()).toEqual(['0','1','2','3','4']); }); - it('should switch out as you scroll', function() { + it('should switch out as you scroll', inject(function($window) { expect(activeItems().length).toBe(5); expect(activeItemContents()).toEqual(['0','1','2','3','4']); expect(activeItemIds()).toEqual(['item0','item1','item2','item3','item4']); @@ -323,7 +330,7 @@ describe('collectionRepeat', function() { expect(activeItems().length).toBe(5); expect(activeItemContents()).toEqual(['5','6','7','8','9']); expect(activeItemIds()).toEqual(['item0','item1','item2','item3','item4']); - }); + })); it('should start with the same items when resizing', inject(function($window) { scrollTo(26); @@ -338,8 +345,8 @@ describe('collectionRepeat', function() { angular.element($window).triggerHandler('resize'); expect(activeItems().length).toBe(2); - expect(activeItemContents()).toEqual(['2','3']); - expect(activeItemIds()).toEqual(['item2','item3']); + expect(activeItemContents()).toEqual(['8','9']); + expect(activeItemIds()).toEqual(['item1','item0']); })); });