From 1fff9d9aa227278411841819aca5106ee42040be Mon Sep 17 00:00:00 2001 From: Harsh Shandilya Date: Sun, 14 Apr 2024 20:51:57 +0530 Subject: [PATCH] fix(android): only attempt to scroll when items exist Fixes COMPOSE-LOBSTERS-3F --- .../claw/android/ui/screens/LobstersPostsScreen.kt | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/android/src/main/kotlin/dev/msfjarvis/claw/android/ui/screens/LobstersPostsScreen.kt b/android/src/main/kotlin/dev/msfjarvis/claw/android/ui/screens/LobstersPostsScreen.kt index a572268f..75081004 100644 --- a/android/src/main/kotlin/dev/msfjarvis/claw/android/ui/screens/LobstersPostsScreen.kt +++ b/android/src/main/kotlin/dev/msfjarvis/claw/android/ui/screens/LobstersPostsScreen.kt @@ -129,7 +129,9 @@ fun LobstersPostsScreen( icon = Icons.Outlined.Whatshot, selectedIcon = Icons.Filled.Whatshot, ) { - coroutineScope.launch { hottestListState.animateScrollToItem(index = 0) } + coroutineScope.launch { + if (hottestPosts.itemCount > 0) hottestListState.animateScrollToItem(index = 0) + } }, NavigationItem( label = "Newest", @@ -137,7 +139,9 @@ fun LobstersPostsScreen( icon = Icons.Outlined.NewReleases, selectedIcon = Icons.Filled.NewReleases, ) { - coroutineScope.launch { newestListState.animateScrollToItem(index = 0) } + coroutineScope.launch { + if (newestPosts.itemCount > 0) newestListState.animateScrollToItem(index = 0) + } }, NavigationItem( label = "Saved", @@ -145,7 +149,9 @@ fun LobstersPostsScreen( icon = Icons.Outlined.FavoriteBorder, selectedIcon = Icons.Filled.Favorite, ) { - coroutineScope.launch { savedListState.animateScrollToItem(index = 0) } + coroutineScope.launch { + if (savedPosts.isNotEmpty()) savedListState.animateScrollToItem(index = 0) + } }, )