From 81468c345ba78dccb3619ba0a54b58225cffade8 Mon Sep 17 00:00:00 2001 From: Noel De Martin Date: Wed, 10 May 2023 11:55:23 +0200 Subject: [PATCH] MOBILE-4270 core: Fix list items auto-scroll The previous implementation was running into some race conditions that caused it to scroll back to the previously selected item sometimes. --- src/core/classes/items-management/list-items-manager.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/core/classes/items-management/list-items-manager.ts b/src/core/classes/items-management/list-items-manager.ts index c66a35fde..83c466882 100644 --- a/src/core/classes/items-management/list-items-manager.ts +++ b/src/core/classes/items-management/list-items-manager.ts @@ -40,7 +40,10 @@ export class CoreListItemsManager< constructor(source: Source, pageRouteLocator: unknown | ActivatedRoute) { super(source); + const debouncedScrollToCurrentElement = CoreUtils.debounce(() => this.scrollToCurrentElement(), 300); + this.pageRouteLocator = pageRouteLocator; + this.addListener({ onSelectedItemUpdated: debouncedScrollToCurrentElement }); } get items(): Item[] { @@ -130,7 +133,6 @@ export class CoreListItemsManager< } await this.navigateToItem(item, { reset: this.resetNavigation() }); - setTimeout(async () => await this.scrollToCurrentElement(), 100); } /**