From 2072d18d503fcb8ad4c84b11344c91ecb3551851 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C9=91rry=20Shiv=C9=91m?= Date: Mon, 20 May 2024 11:27:15 +0530 Subject: [PATCH] perf: Only add delay when loading fisrt set of books (#176) 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)