From 741ea6c06a4e34bf226fd54cbb25371f75be6097 Mon Sep 17 00:00:00 2001 From: starry-shivam Date: Mon, 20 May 2024 11:18:57 +0530 Subject: [PATCH] perf: Only add delay when loading fisrt set of books Signed-off-by: starry-shivam --- .../starry/myne/ui/screens/home/viewmodels/HomeViewModel.kt | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/com/starry/myne/ui/screens/home/viewmodels/HomeViewModel.kt b/app/src/main/java/com/starry/myne/ui/screens/home/viewmodels/HomeViewModel.kt index b631537d..e804dc9f 100644 --- a/app/src/main/java/com/starry/myne/ui/screens/home/viewmodels/HomeViewModel.kt +++ b/app/src/main/java/com/starry/myne/ui/screens/home/viewmodels/HomeViewModel.kt @@ -81,8 +81,10 @@ class HomeViewModel @Inject constructor( allBooksState = allBooksState.copy(isLoading = it) }, onRequest = { nextPage -> try { - // Slight delay for better UX - delay(400) + // Only add delay when loading first page to show shimmer effect + // and avoid flickering when navigating to home from welcome screen + // and immediately loading the first page. + if (nextPage == 1L) delay(400L) bookAPI.getAllBooks(nextPage, language.value) } catch (exc: Exception) { Result.failure(exc)