Skip to content

Commit

Permalink
feat(collectionRepeat): automatically set width/height style to match…
Browse files Browse the repository at this point in the history
… collection-item-{width,height}

Closes #3034. Closes #1806.
  • Loading branch information
ajoslin committed Feb 6, 2015
1 parent 0145dc3 commit 34e350b
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 6 deletions.
1 change: 0 additions & 1 deletion js/angular/service/collectionRepeatDataSource.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ function($cacheFactory, $parse, $rootScope) {

item.scope = this.scope.$new();
this.transcludeFn(item.scope, function(clone) {
clone.css('position', 'absolute');
item.element = clone;
});
this.transcludeParent.append(item.element);
Expand Down
14 changes: 12 additions & 2 deletions js/angular/service/collectionRepeatManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -310,15 +310,25 @@ function($rootScope, $timeout) {
renderItem: function(dataIndex, primaryPos, secondaryPos) {
// Attach an item, and set its transform position to the required value
var item = this.dataSource.attachItemAtIndex(dataIndex);
var itemDimensions = this.dimensions[dataIndex];
//console.log(dataIndex, item);
if (item && item.element) {
if (item.primaryPos !== primaryPos || item.secondaryPos !== secondaryPos) {
item.element.css(ionic.CSS.TRANSFORM, this.transformString(
item.element[0].style[ionic.CSS.TRANSFORM] = this.transformString(
primaryPos, secondaryPos
));
);
item.primaryPos = primaryPos;
item.secondaryPos = secondaryPos;
}

var width = this.isVertical ? itemDimensions.secondarySize : itemDimensions.primarySize;
var height = this.isVertical ? itemDimensions.primarySize : itemDimensions.secondarySize;
if (item.cssWidth !== width) {
item.element[0].style.width = (item.cssWidth = width) + 'px';
}
if (item.cssHeight !== height) {
item.element[0].style.height = (item.cssHeight = height) + 'px';
}
// Save the item in rendered items
this.renderedItems[dataIndex] = item;
} else {
Expand Down
6 changes: 6 additions & 0 deletions scss/_util.scss
Original file line number Diff line number Diff line change
Expand Up @@ -248,3 +248,9 @@
.dark-border {
border-color: $button-dark-border;
}

[collection-repeat] {
/* Position is set by transforms */
left: 0 !important;
position: absolute !important;
}
4 changes: 1 addition & 3 deletions test/html/list-fit.html
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,7 @@ <h1 class="title">Hi</h1>
ng-click="alert(item)"
collection-repeat="item in items"
collection-item-height="85"
collection-item-width="'100%'"
ng-style="{height: '85px'}"
style="left: 0; right: 0;">
collection-item-width="'25%'">
<h2>{{item.text}}</h2>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Duis porttitor diam urna, vitae consectetur lectus aliquet quis.</p>
<ion-option-button>DEL</ion-option-button>
Expand Down

0 comments on commit 34e350b

Please sign in to comment.