From 94f0b5b705d09fc17f2e34977c35e52747767bb1 Mon Sep 17 00:00:00 2001 From: Andrew Joslin Date: Wed, 21 May 2014 07:44:21 -0600 Subject: [PATCH] fix(collectionRepeat): fix rare NPE error on android 4.1 Closes #1292 --- js/angular/service/collectionRepeatDataSource.js | 2 +- js/angular/service/collectionRepeatManager.js | 6 +++--- test/unit/angular/directive/headerFooterBar.unit.js | 6 ++++-- .../unit/angular/service/collectionRepeatManager.unit.js | 9 ++++++--- 4 files changed, 14 insertions(+), 9 deletions(-) diff --git a/js/angular/service/collectionRepeatDataSource.js b/js/angular/service/collectionRepeatDataSource.js index 7f84d5d8b2d..32715fd9d63 100644 --- a/js/angular/service/collectionRepeatDataSource.js +++ b/js/angular/service/collectionRepeatDataSource.js @@ -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); diff --git a/js/angular/service/collectionRepeatManager.js b/js/angular/service/collectionRepeatManager.js index eefdd181e68..2cf661e17d0 100644 --- a/js/angular/service/collectionRepeatManager.js +++ b/js/angular/service/collectionRepeatManager.js @@ -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]; diff --git a/test/unit/angular/directive/headerFooterBar.unit.js b/test/unit/angular/directive/headerFooterBar.unit.js index a5ce05a0c20..ccfeda97b46 100644 --- a/test/unit/angular/directive/headerFooterBar.unit.js +++ b/test/unit/angular/directive/headerFooterBar.unit.js @@ -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() { diff --git a/test/unit/angular/service/collectionRepeatManager.unit.js b/test/unit/angular/service/collectionRepeatManager.unit.js index 0f22d5f509b..88d6a09e659 100644 --- a/test/unit/angular/service/collectionRepeatManager.unit.js +++ b/test/unit/angular/service/collectionRepeatManager.unit.js @@ -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('
') }; + 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); }); });