Skip to content

Commit 34e350b

Browse files
committed
feat(collectionRepeat): automatically set width/height style to match collection-item-{width,height}
Closes #3034. Closes #1806.
1 parent 0145dc3 commit 34e350b

File tree

4 files changed

+19
-6
lines changed

4 files changed

+19
-6
lines changed

js/angular/service/collectionRepeatDataSource.js

-1
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,6 @@ function($cacheFactory, $parse, $rootScope) {
6161

6262
item.scope = this.scope.$new();
6363
this.transcludeFn(item.scope, function(clone) {
64-
clone.css('position', 'absolute');
6564
item.element = clone;
6665
});
6766
this.transcludeParent.append(item.element);

js/angular/service/collectionRepeatManager.js

+12-2
Original file line numberDiff line numberDiff line change
@@ -310,15 +310,25 @@ function($rootScope, $timeout) {
310310
renderItem: function(dataIndex, primaryPos, secondaryPos) {
311311
// Attach an item, and set its transform position to the required value
312312
var item = this.dataSource.attachItemAtIndex(dataIndex);
313+
var itemDimensions = this.dimensions[dataIndex];
313314
//console.log(dataIndex, item);
314315
if (item && item.element) {
315316
if (item.primaryPos !== primaryPos || item.secondaryPos !== secondaryPos) {
316-
item.element.css(ionic.CSS.TRANSFORM, this.transformString(
317+
item.element[0].style[ionic.CSS.TRANSFORM] = this.transformString(
317318
primaryPos, secondaryPos
318-
));
319+
);
319320
item.primaryPos = primaryPos;
320321
item.secondaryPos = secondaryPos;
321322
}
323+
324+
var width = this.isVertical ? itemDimensions.secondarySize : itemDimensions.primarySize;
325+
var height = this.isVertical ? itemDimensions.primarySize : itemDimensions.secondarySize;
326+
if (item.cssWidth !== width) {
327+
item.element[0].style.width = (item.cssWidth = width) + 'px';
328+
}
329+
if (item.cssHeight !== height) {
330+
item.element[0].style.height = (item.cssHeight = height) + 'px';
331+
}
322332
// Save the item in rendered items
323333
this.renderedItems[dataIndex] = item;
324334
} else {

scss/_util.scss

+6
Original file line numberDiff line numberDiff line change
@@ -248,3 +248,9 @@
248248
.dark-border {
249249
border-color: $button-dark-border;
250250
}
251+
252+
[collection-repeat] {
253+
/* Position is set by transforms */
254+
left: 0 !important;
255+
position: absolute !important;
256+
}

test/html/list-fit.html

+1-3
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,7 @@ <h1 class="title">Hi</h1>
3131
ng-click="alert(item)"
3232
collection-repeat="item in items"
3333
collection-item-height="85"
34-
collection-item-width="'100%'"
35-
ng-style="{height: '85px'}"
36-
style="left: 0; right: 0;">
34+
collection-item-width="'25%'">
3735
<h2>{{item.text}}</h2>
3836
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Duis porttitor diam urna, vitae consectetur lectus aliquet quis.</p>
3937
<ion-option-button>DEL</ion-option-button>

0 commit comments

Comments
 (0)