Skip to content
This repository was archived by the owner on Sep 5, 2024. It is now read-only.

Commit aca5944

Browse files
Scott HyndmanThomasBurleson
authored andcommitted
fix(gridlist): The gridlist will now lay out everytime a tile is added
Fixes #2227. Closes #2304.
1 parent b9803fe commit aca5944

3 files changed

Lines changed: 10 additions & 8 deletions

File tree

src/components/gridList/demoDynamicTiles/index.html

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
<div ng-app="gridListDemo" ng-controller="gridListDemoCtrl as vm" flex>
2-
<md-button ng-click="vm.rotate()">Rotate</md-button>
32
<md-grid-list
43
md-cols-sm="1" md-cols-md="2" md-cols-gt-md="6"
54
md-row-height-gt-md="1:1" md-row-height="4:3"

src/components/gridList/demoDynamicTiles/script.js

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,6 @@ angular
99
background: ""
1010
});
1111

12-
this.rotate = function() {
13-
this.tiles.unshift(this.tiles.pop());
14-
};
15-
1612
function buildGridModel(tileTmpl){
1713
var it, results = [ ];
1814

src/components/gridList/gridList.js

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -157,8 +157,12 @@ function GridListDirective($interpolate, $mdConstant, $mdGridLayout, $mdMedia) {
157157
/**
158158
* Invokes the layout engine, and uses its results to lay out our
159159
* tile elements.
160+
*
161+
* @param {boolean} tilesAdded Whether tiles have been added since the last
162+
* layout. This is to avoid situations where tiles are replaced with
163+
* properties identical to their removed counterparts.
160164
*/
161-
function layoutDelegate() {
165+
function layoutDelegate(tilesAdded) {
162166
var props = {
163167
tileSpans: getTileSpans(),
164168
colCount: getColumnCount(),
@@ -167,7 +171,7 @@ function GridListDirective($interpolate, $mdConstant, $mdGridLayout, $mdMedia) {
167171
gutter: getGutter()
168172
};
169173

170-
if (angular.equals(props, lastLayoutProps)) {
174+
if (!tilesAdded && angular.equals(props, lastLayoutProps)) {
171175
return;
172176
}
173177

@@ -407,6 +411,7 @@ function GridListDirective($interpolate, $mdConstant, $mdGridLayout, $mdMedia) {
407411
/* @ngInject */
408412
function GridListController($timeout) {
409413
this.invalidated = false;
414+
this.tilesAdded = false;
410415
this.$timeout_ = $timeout;
411416
this.tiles = [];
412417
this.layoutDelegate = angular.noop;
@@ -420,6 +425,7 @@ GridListController.prototype = {
420425
} else {
421426
this.tiles.splice(idx, 0, tile);
422427
}
428+
this.tilesAdded = true;
423429
this.invalidateLayout();
424430
},
425431

@@ -442,9 +448,10 @@ GridListController.prototype = {
442448

443449
layout: function() {
444450
try {
445-
this.layoutDelegate();
451+
this.layoutDelegate(this.tilesAdded);
446452
} finally {
447453
this.invalidated = false;
454+
this.tilesAdded = false;
448455
}
449456
},
450457

0 commit comments

Comments
 (0)