MOBILE-4362 course: Keep scroll position after refresh

main
Dani Palou 2023-09-28 12:43:29 +02:00
parent 4ea7b56bde
commit 2d1a018304
1 changed files with 9 additions and 0 deletions

View File

@ -357,6 +357,10 @@ export class CoreCourseContentsPage implements OnInit, OnDestroy, CoreRefreshCon
* @returns Promise resolved when done.
*/
protected async showLoadingAndRefresh(sync = false, invalidateData = true): Promise<void> {
// Try to keep current scroll position.
const scrollElement = await CoreUtils.ignoreErrors(this.content?.getScrollElement());
const scrollTop = scrollElement?.scrollTop ?? -1;
this.updatingData = true;
this.changeDetectorRef.detectChanges();
@ -371,6 +375,11 @@ export class CoreCourseContentsPage implements OnInit, OnDestroy, CoreRefreshCon
} finally {
this.updatingData = false;
this.changeDetectorRef.detectChanges();
if (scrollTop > 0) {
await CoreUtils.nextTick();
this.content?.scrollToPoint(0, scrollTop, 0);
}
}
}