Skip to content

Commit

Permalink
fix(collectionRepeat): fix rare NPE error on android 4.1
Browse files Browse the repository at this point in the history
Closes #1292
  • Loading branch information
ajoslin committed May 21, 2014
1 parent 3618109 commit 94f0b5b
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 9 deletions.
2 changes: 1 addition & 1 deletion js/angular/service/collectionRepeatDataSource.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,8 @@ function($cacheFactory, $parse) {
item.scope[this.keyExpr] = value;

this.transcludeFn(item.scope, function(clone) {
clone.css('position', 'absolute');
item.element = clone;
item.element[0].style.position = 'absolute';
});

return this.itemCache.put(key, item);
Expand Down
6 changes: 3 additions & 3 deletions js/angular/service/collectionRepeatManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -201,11 +201,11 @@ function($rootScope, $timeout) {
},
renderItem: function(dataIndex, primaryPos, secondaryPos) {
var item = this.dataSource.getItem(dataIndex);
if (item) {
if (item && item.element) {
this.dataSource.attachItem(item);
item.element[0].style[ionic.CSS.TRANSFORM] = this.transformString(
item.element.css(ionic.CSS.TRANSFORM, this.transformString(
primaryPos, secondaryPos, secondaryPos
);
));
this.renderedItems[dataIndex] = item;
} else {
delete this.renderedItems[dataIndex];
Expand Down
6 changes: 4 additions & 2 deletions test/unit/angular/directive/headerFooterBar.unit.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,12 @@ describe('bar directives', function() {
});
spyOn(ionic, 'off');
var el = setup();
expect(ionic.on).toHaveBeenCalledWith('tap', jasmine.any(Function), el[0]);
expect(ionic.on.mostRecentCall.args[0]).toBe('tap');
expect(ionic.off).not.toHaveBeenCalled();
el.scope().$destroy();
expect(ionic.off).toHaveBeenCalledWith('tap', callback, el[0]);
expect(ionic.off.mostRecentCall.args[0]).toBe('tap');
expect(ionic.off.mostRecentCall.args[1]).toBe(callback);
expect(ionic.off.mostRecentCall.args[2]).toBe(el[0]);
});
['input','textarea','select'].forEach(function(tag) {
it('should ignore tap if it\'s in a ' + tag, function() {
Expand Down
9 changes: 6 additions & 3 deletions test/unit/angular/service/collectionRepeatManager.unit.js
Original file line number Diff line number Diff line change
Expand Up @@ -525,14 +525,17 @@ describe('collectionRepeatManager service', function() {
it('should attachItem and set the element transform', function() {
var manager = setup();
var item = {
element: [{ style: {} }]
element: angular.element('<div>')
};
spyOn(item.element, 'css');
spyOn(manager.dataSource, 'getItem').andReturn(item);
spyOn(manager.dataSource, 'attachItem');
manager.renderItem(0, 33, 44);
expect(manager.dataSource.attachItem).toHaveBeenCalledWith(item);
expect(item.element[0].style[ionic.CSS.TRANSFORM])
.toEqual(manager.transformString(33, 44));
expect(item.element.css).toHaveBeenCalledWith(
ionic.CSS.TRANSFORM,
manager.transformString(33, 44)
);
expect(manager.renderedItems[0]).toBe(item);
});
});
Expand Down

0 comments on commit 94f0b5b

Please sign in to comment.