amethyst/app/src/main/java/com/vitorpamplona/amethyst/ui/navigation/AppNavigation.kt

52 wiersze
1.9 KiB
Kotlin
Czysty Zwykły widok Historia

2023-01-11 18:31:20 +00:00
package com.vitorpamplona.amethyst.ui.navigation
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.livedata.observeAsState
import androidx.lifecycle.viewmodel.compose.viewModel
2023-01-11 18:31:20 +00:00
import androidx.navigation.NavHostController
import androidx.navigation.compose.NavHost
import androidx.navigation.compose.composable
import com.vitorpamplona.amethyst.ui.dal.GlobalFeedFilter
2023-01-19 03:00:32 +00:00
import com.vitorpamplona.amethyst.ui.screen.AccountStateViewModel
import com.vitorpamplona.amethyst.ui.screen.NostrGlobalFeedViewModel
2023-01-11 18:31:20 +00:00
import com.vitorpamplona.amethyst.ui.screen.loggedIn.AccountViewModel
import com.vitorpamplona.amethyst.ui.screen.loggedIn.SearchScreen
2023-01-11 18:31:20 +00:00
@Composable
fun AppNavigation(
navController: NavHostController,
2023-01-19 03:00:32 +00:00
accountViewModel: AccountViewModel,
2023-01-25 00:53:22 +00:00
accountStateViewModel: AccountStateViewModel,
nextPage: String? = null
2023-01-11 18:31:20 +00:00
) {
val accountState by accountViewModel.accountLiveData.observeAsState()
val account = accountState?.account ?: return
GlobalFeedFilter.account = account
val globalFeedViewModel: NostrGlobalFeedViewModel = viewModel()
2023-01-11 18:31:20 +00:00
NavHost(navController, startDestination = Route.Home.route) {
Route.Search.let { route ->
composable(route.route, route.arguments, content = {
SearchScreen(
accountViewModel = accountViewModel,
feedViewModel = globalFeedViewModel,
navController = navController,
scrollToTop = it.arguments?.getBoolean("scrollToTop") ?: false
)
})
}
2023-01-11 18:31:20 +00:00
Routes.forEach {
it.buildScreen?.let { fn ->
composable(it.route, it.arguments, content = fn(accountViewModel, accountStateViewModel, navController))
}
2023-01-11 18:31:20 +00:00
}
}
2023-01-25 00:53:22 +00:00
if (nextPage != null) {
navController.navigate(nextPage)
}
2023-03-07 18:46:44 +00:00
}