diff --git a/src/core/components/loading/loading.ts b/src/core/components/loading/loading.ts index a1f8e5ff7..6de2d8f4b 100644 --- a/src/core/components/loading/loading.ts +++ b/src/core/components/loading/loading.ts @@ -147,6 +147,10 @@ export class CoreLoadingComponent implements OnInit, OnChanges, AfterViewInit, A * Recovers last set scroll position. */ protected async recoverScrollPosition(): Promise { + if (this.scroll <= 0) { + return; + } + const content = this.element.closest('ion-content'); if (!content) { return; diff --git a/src/core/features/course/pages/contents/contents.ts b/src/core/features/course/pages/contents/contents.ts index b190f4ec0..62915db57 100644 --- a/src/core/features/course/pages/contents/contents.ts +++ b/src/core/features/course/pages/contents/contents.ts @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -import { Component, ViewChild, OnInit, OnDestroy, forwardRef } from '@angular/core'; +import { Component, ViewChild, OnInit, OnDestroy, forwardRef, ChangeDetectorRef } from '@angular/core'; import { IonContent, IonRefresher } from '@ionic/angular'; import { CoreDomUtils } from '@services/utils/dom'; @@ -73,6 +73,8 @@ export class CoreCourseContentsPage implements OnInit, OnDestroy, CoreRefreshCon protected modulesHaveCompletion = false; protected debouncedUpdateCachedCompletion?: () => void; // Update the cached completion after a certain time. + constructor(protected changeDetectorRef: ChangeDetectorRef) {} + /** * @inheritdoc */ @@ -352,12 +354,8 @@ export class CoreCourseContentsPage implements OnInit, OnDestroy, CoreRefreshCon */ protected async showLoadingAndRefresh(sync = false, invalidateData = true): Promise { // Save scroll position to restore it once done. - const scrollElement = await this.content?.getScrollElement(); - const scrollTop = scrollElement?.scrollTop || 0; - const scrollLeft = scrollElement?.scrollLeft || 0; - this.updatingData = true; - this.content?.scrollToTop(0); // Scroll top so the spinner is seen. + this.changeDetectorRef.detectChanges(); try { if (invalidateData) { @@ -369,11 +367,7 @@ export class CoreCourseContentsPage implements OnInit, OnDestroy, CoreRefreshCon await this.formatComponent?.doRefresh(undefined, undefined, true); } finally { this.updatingData = false; - - // Wait for new content height to be calculated and scroll without animation. - setTimeout(() => { - this.content?.scrollToPoint(scrollLeft, scrollTop, 0); - }); + this.changeDetectorRef.detectChanges(); } }