fix(collectionRepeat): correctly save user scroll position on back

Addresses #1157
This commit is contained in:
Andy Joslin
2014-05-05 10:38:33 -06:00
parent e6e1896629
commit 0a64075884
2 changed files with 12 additions and 9 deletions

View File

@@ -76,15 +76,17 @@ function($scope, scrollViewOptions, $timeout, $window, $$scrollValueCache, $loca
var viewId = historyData && historyData.viewId;
if (viewId) {
self.rememberScrollPosition(viewId);
self.scrollToRememberedPosition();
$timeout(function() {
self.rememberScrollPosition(viewId);
self.scrollToRememberedPosition();
backListenDone = $rootScope.$on('$viewHistory.viewBack', function(e, fromViewId, toViewId) {
//When going back from this view, forget its saved scroll position
if (viewId === fromViewId) {
self.forgetScrollPosition();
}
});
backListenDone = $rootScope.$on('$viewHistory.viewBack', function(e, fromViewId, toViewId) {
//When going back from this view, forget its saved scroll position
if (viewId === fromViewId) {
self.forgetScrollPosition();
}
});
}, 1, false);
}
});

View File

@@ -124,11 +124,12 @@ describe('$ionicScroll Controller', function() {
expect(ctrl.scrollToRememberedPosition).toHaveBeenCalled();
});
it('should forget on $viewHistory.viewBack after $viewContentLoaded', inject(function($rootScope) {
it('should forget on $viewHistory.viewBack after $viewContentLoaded', inject(function($rootScope, $timeout) {
var historyData = { viewId: 'foo' };
setup();
spyOn($rootScope, '$on').andCallThrough();;
scope.$broadcast('$viewContentLoaded', historyData);
$timeout.flush();
expect(scope.$on).toHaveBeenCalledWith('$viewHistory.viewBack', jasmine.any(Function));
//Should not forget unless backViewId is the same