Skip to content

Commit 2c2662f

Browse files
committed
fix(collectionRepeat): fix problem with option & delete buttons
Closes #3280.
1 parent 4f35d8e commit 2c2662f

File tree

4 files changed

+25
-11
lines changed

4 files changed

+25
-11
lines changed

js/angular/directive/collectionRepeat.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -300,8 +300,8 @@ function CollectionRepeatDirective($ionicCollectionManager, $parse, $window, $$r
300300
parsedValue = $parse(attrValue);
301301
}
302302

303-
var withoutQuotes = attrValue.replace(/(\'|\"|px|%)/g, '').trim();
304-
var isConstant = withoutQuotes.length && !/([a-zA-Z]|\$|:|\?)/.test(withoutQuotes);
303+
var constantAttrValue = attrValue.replace(/(\'|\"|px|%)/g, '').trim();
304+
var isConstant = constantAttrValue.length && !/([a-zA-Z]|\$|:|\?)/.test(constantAttrValue);
305305
dimensionData.attrValue = attrValue;
306306

307307
// If it's a constant, it's either a percent or just a constant pixel number.
@@ -560,7 +560,6 @@ function RepeatManagerFactory($rootScope, $window, $$rAF) {
560560
delete itemsShownMap[i];
561561
itemsLeaving.push(item);
562562
item.isShown = false;
563-
item.scope.$broadcast('$collectionRepeatChange');
564563
}
565564
}
566565

@@ -669,6 +668,7 @@ function RepeatManagerFactory($rootScope, $window, $$rAF) {
669668
if (item.isShown) {
670669
count--;
671670
if (!rootScopePhase) item.scope.$digest();
671+
item.scope.$broadcast('$collectionRepeatLeave');
672672
}
673673
}
674674
$$rAF(process);

js/angular/directive/item.js

+10-4
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ var ITEM_TPL_CONTENT =
2828
* ```
2929
*/
3030
IonicModule
31-
.directive('ionItem', function() {
31+
.directive('ionItem', ['$$rAF', function($$rAF) {
3232
var nextId = 0;
3333
return {
3434
restrict: 'E',
@@ -66,12 +66,18 @@ IonicModule
6666

6767
var content = $element[0].querySelector('.item-content');
6868
if (content) {
69-
$scope.$on('$collectionRepeatChange', function() {
70-
content && (content.style[ionic.CSS.TRANSFORM] = 'translate3d(0,0,0)');
69+
$scope.$on('$collectionRepeatLeave', function() {
70+
if (content) {
71+
content.style[ionic.CSS.TRANSFORM] = '';
72+
content.style[ionic.CSS.TRANSITION] = 'none';
73+
$$rAF(function() {
74+
content.style[ionic.CSS.TRANSITION] = '';
75+
});
76+
}
7177
});
7278
}
7379
};
7480

7581
}
7682
};
77-
});
83+
}]);

js/angular/directive/itemDeleteButton.js

+8-3
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ IonicModule
3333
.directive('ionDeleteButton', function() {
3434
return {
3535
restrict: 'E',
36-
require: ['^ionItem', '^?ionList'],
36+
require: ['^^ionItem', '^?ionList'],
3737
//Run before anything else, so we can move it before other directives process
3838
//its location (eg ngIf relies on the location of the directive in the dom)
3939
priority: Number.MAX_VALUE,
@@ -48,8 +48,13 @@ IonicModule
4848
container.append($element);
4949
itemCtrl.$element.append(container).addClass('item-left-editable');
5050

51-
if (listCtrl && listCtrl.showDelete()) {
52-
container.addClass('visible active');
51+
init();
52+
$scope.$on('$ionic.reconnectScope', init);
53+
function init() {
54+
listCtrl = listCtrl || $element.controller('ionList');
55+
if (listCtrl && listCtrl.showDelete()) {
56+
container.addClass('visible active');
57+
}
5358
}
5459
};
5560
}

test/html/collection-repeat/basic-list.html

+4-1
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,15 @@
1313

1414
<body ng-controller="MainCtrl">
1515
<ion-header-bar class="bar-positive">
16+
<button class="button" ng-click="$root.showDelete = !$root.showDelete">Toggle Delete</button>
1617
<h1 class="title">Basic List: Static Dimensions</h1>
1718
</ion-header-bar>
1819
<ion-content>
1920
<h4>WHATS UP</h4>
20-
<ion-list can-swipe="true">
21+
<ion-list can-swipe="true" show-delete="$root.showDelete">
2122
<ion-item class="item" collection-repeat="item in items">
23+
<ion-option-button>Button</ion-option-button>
24+
<ion-delete-button class="ion-minus-circled" ng-click="items.splice($index, 1)"></ion-delete-button>
2225
<h2>{{item.text}}</h2>
2326
</ion-item>
2427
</ion-list>

0 commit comments

Comments
 (0)