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

Commit

Permalink
fix(gridlist): The gridlist will now lay out everytime a tile is added
Browse files Browse the repository at this point in the history
Fixes #2227. Closes #2304.
  • Loading branch information
Scott Hyndman authored and ThomasBurleson committed Apr 14, 2015
1 parent b9803fe commit aca5944
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 8 deletions.
1 change: 0 additions & 1 deletion src/components/gridList/demoDynamicTiles/index.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
<div ng-app="gridListDemo" ng-controller="gridListDemoCtrl as vm" flex>
<md-button ng-click="vm.rotate()">Rotate</md-button>
<md-grid-list
md-cols-sm="1" md-cols-md="2" md-cols-gt-md="6"
md-row-height-gt-md="1:1" md-row-height="4:3"
Expand Down
4 changes: 0 additions & 4 deletions src/components/gridList/demoDynamicTiles/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,6 @@ angular
background: ""
});

this.rotate = function() {
this.tiles.unshift(this.tiles.pop());
};

function buildGridModel(tileTmpl){
var it, results = [ ];

Expand Down
13 changes: 10 additions & 3 deletions src/components/gridList/gridList.js
Original file line number Diff line number Diff line change
Expand Up @@ -157,8 +157,12 @@ function GridListDirective($interpolate, $mdConstant, $mdGridLayout, $mdMedia) {
/**
* Invokes the layout engine, and uses its results to lay out our
* tile elements.
*
* @param {boolean} tilesAdded Whether tiles have been added since the last
* layout. This is to avoid situations where tiles are replaced with
* properties identical to their removed counterparts.
*/
function layoutDelegate() {
function layoutDelegate(tilesAdded) {
var props = {
tileSpans: getTileSpans(),
colCount: getColumnCount(),
Expand All @@ -167,7 +171,7 @@ function GridListDirective($interpolate, $mdConstant, $mdGridLayout, $mdMedia) {
gutter: getGutter()
};

if (angular.equals(props, lastLayoutProps)) {
if (!tilesAdded && angular.equals(props, lastLayoutProps)) {
return;
}

Expand Down Expand Up @@ -407,6 +411,7 @@ function GridListDirective($interpolate, $mdConstant, $mdGridLayout, $mdMedia) {
/* @ngInject */
function GridListController($timeout) {
this.invalidated = false;
this.tilesAdded = false;
this.$timeout_ = $timeout;
this.tiles = [];
this.layoutDelegate = angular.noop;
Expand All @@ -420,6 +425,7 @@ GridListController.prototype = {
} else {
this.tiles.splice(idx, 0, tile);
}
this.tilesAdded = true;
this.invalidateLayout();
},

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

layout: function() {
try {
this.layoutDelegate();
this.layoutDelegate(this.tilesAdded);
} finally {
this.invalidated = false;
this.tilesAdded = false;
}
},

Expand Down

0 comments on commit aca5944

Please sign in to comment.