We need a mechanism to retain scroll position after returning from a detail view when data is reloaded from a service. The current implementation only works when the controller has the list data pre-defined in the scope.
See this sample where the controller reloads the data from a service instead of having embedded in controller.
Sample : http://codepen.io/SatadruBhattacharjee/pen/jsLtb
http://forum.ionicframework.com/t/save-list-view-state/1554/2
Prerequisite issue: #565
How about: Every time a scrollView's associated ScrollController is created, it will:
Then $ionicScrollDelegate has a function that will try to load a saved scroll position (using current view's id).
$ionicScrollDelegate#scrollToRememberedPosition([shouldAnimateToPosition])
@calendee @adamdbradley @mlynch any ideas for a less verbose name than that ^?
Usage example (after implementing #565):
function MyCtrl($scope, $ionicScrollDelegate, DataService) {
var delegate = $ionicScrollDelegate($scope);
DataService.loadData().then(function() {
delegate.scrollToRememberedPosition();
});
}
.lastScrollPosition() ?
Less verbose? That's tiny. I always go big : delegate.scrollToThePlaceYouRememberedEarlierWhenThereWasDataInThisList
Seriously - Adam's suggestion is good.
The name needs to emphasize remembering _and_ scrolling to the last position, though.
I don't think it's best to make users do: delegate.scrollTo(delegate.lastScrollPosition());
delegate.scrollToPreviousPosition()? I think last is also too vague, because it could mean the user's last action, not the last action last time the page was loaded.
related to this issue, is it possible that back with the original page keep the same status. e.g. an input box w/ content still there, a photo kept there w/ original zoom level?
Added via 5a0efecef6ea2c4f89c6dfd3cbe98a98614a6e17
The first scrollView underneath a newly loaded view will remember that view's history based on that view's id.
However, any other scroll view needs its own id association to save its scroll by - so when the scroll view is recreated we know _which_ saved scroll position to use.
So here's an example of how you could save scroll position on an arbitrary <ion-scroll> element.
<ion-scroll ng-controller="MyCtrl">
Hi!
</ion-scroll>
function MyCtrl($scope, $ionicScrollDelegate) {
var delegate = $ionicScrollDelegate($scope);
delegate.scrollToRememberedPosition('my-scroll-id');
//saves scroll based on id on $destroy
delegate.rememberScrollPosition('my-scroll-id');
}
WIP Documentation: http://ajoslin.github.io/docs/nightly/api/service/$ionicScrollDelegate#rememberScrollPosition
How can this be implemented in ionic 2? I'd like my list to stay at the same even after the items have been loaded in the background.
And what about Ionic 3?
Thanks for the issue! This issue is being locked to prevent comments that are not relevant to the original issue. If this is still an issue with the latest version of Ionic, please create a new issue and ensure the template is fully filled out.
Most helpful comment
And what about Ionic 3?