Skip to content

Commit

Permalink
perf: Only add delay when loading fisrt set of books (#176)
Browse files Browse the repository at this point in the history
Signed-off-by: starry-shivam <[email protected]>
  • Loading branch information
starry-shivam authored May 20, 2024
1 parent 5b31262 commit 2072d18
Showing 1 changed file with 4 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 2072d18

Please sign in to comment.