Skip to content

Commit

Permalink
fix(collectionRepeat): correctly save user scroll position on back
Browse files Browse the repository at this point in the history
Addresses #1157
  • Loading branch information
ajoslin committed May 5, 2014
1 parent e6e1896 commit 0a64075
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 10 deletions.
20 changes: 11 additions & 9 deletions js/angular/controller/scrollController.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,15 +76,17 @@ function($scope, scrollViewOptions, $timeout, $window, $$scrollValueCache, $loca

var viewId = historyData && historyData.viewId;
if (viewId) {
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();
}
});
$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();
}
});
}, 1, false);
}
});

Expand Down
3 changes: 2 additions & 1 deletion test/unit/angular/controller/scrollController.unit.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 0a64075

Please sign in to comment.