fix(android): only attempt to scroll when items exist

Fixes COMPOSE-LOBSTERS-3F
This commit is contained in:
Harsh Shandilya 2024-04-14 20:51:57 +05:30
parent 9357362ef6
commit 1fff9d9aa2

View File

@ -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)
}
},
)