mirror of
https://github.com/msfjarvis/compose-lobsters
synced 2025-08-17 20:17:02 +05:30
Merge #132
132: Scope down coroutines r=msfjarvis a=msfjarvis bors r+ Co-authored-by: Harsh Shandilya <me@msfjarvis.dev>
This commit is contained in:
commit
fc3238a618
1 changed files with 5 additions and 7 deletions
|
@ -31,7 +31,6 @@ import kotlinx.coroutines.launch
|
||||||
@Composable
|
@Composable
|
||||||
fun LobstersApp() {
|
fun LobstersApp() {
|
||||||
val viewModel: LobstersViewModel = viewModel()
|
val viewModel: LobstersViewModel = viewModel()
|
||||||
val coroutineScope = rememberCoroutineScope()
|
|
||||||
val navController = rememberNavController()
|
val navController = rememberNavController()
|
||||||
val hottestPosts = viewModel.posts.collectAsLazyPagingItems()
|
val hottestPosts = viewModel.posts.collectAsLazyPagingItems()
|
||||||
val savedPosts by viewModel.savedPosts.collectAsState()
|
val savedPosts by viewModel.savedPosts.collectAsState()
|
||||||
|
@ -47,10 +46,8 @@ fun LobstersApp() {
|
||||||
popUpTo(navController.graph.startDestination) { inclusive = false }
|
popUpTo(navController.graph.startDestination) { inclusive = false }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
val jumpToIndex: (Int) -> Unit = {
|
val jumpToIndex: suspend (Int) -> Unit = {
|
||||||
coroutineScope.launch {
|
hottestPostsListState.animateScrollToItem(it)
|
||||||
hottestPostsListState.animateScrollToItem(it)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Scaffold(
|
Scaffold(
|
||||||
|
@ -87,8 +84,9 @@ fun LobstersApp() {
|
||||||
fun LobstersBottomNav(
|
fun LobstersBottomNav(
|
||||||
currentDestination: Destination,
|
currentDestination: Destination,
|
||||||
navigateToDestination: (destination: Destination) -> Unit,
|
navigateToDestination: (destination: Destination) -> Unit,
|
||||||
jumpToIndex: (index: Int) -> Unit,
|
jumpToIndex: suspend (index: Int) -> Unit,
|
||||||
) {
|
) {
|
||||||
|
val coroutineScope = rememberCoroutineScope()
|
||||||
BottomNavigation(modifier = Modifier.testTag("LobstersBottomNav")) {
|
BottomNavigation(modifier = Modifier.testTag("LobstersBottomNav")) {
|
||||||
Destination.values().forEach { screen ->
|
Destination.values().forEach { screen ->
|
||||||
BottomNavigationItem(
|
BottomNavigationItem(
|
||||||
|
@ -106,7 +104,7 @@ fun LobstersBottomNav(
|
||||||
if (screen != currentDestination) {
|
if (screen != currentDestination) {
|
||||||
navigateToDestination(screen)
|
navigateToDestination(screen)
|
||||||
} else if (screen.route == Destination.Hottest.route) {
|
} else if (screen.route == Destination.Hottest.route) {
|
||||||
jumpToIndex(0)
|
coroutineScope.launch { jumpToIndex(0) }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue