mirror of
https://github.com/JustinZeus/Wholphin.git
synced 2026-07-08 15:50:16 +02:00
Support reloading main page
This commit is contained in:
parent
9e876a85d4
commit
1411859b7f
6 changed files with 22 additions and 7 deletions
|
|
@ -92,7 +92,7 @@ class MainActivity : AppCompatActivity() {
|
|||
remember(appPreferences) {
|
||||
createDeviceProfile(this@MainActivity, preferences, false)
|
||||
}
|
||||
val backStack = rememberNavBackStack(Destination.Main)
|
||||
val backStack = rememberNavBackStack(Destination.Main())
|
||||
val navigationManager = NavigationManager(backStack)
|
||||
|
||||
if (server != null && user != null) {
|
||||
|
|
|
|||
|
|
@ -24,7 +24,7 @@ fun ApplicationContent(
|
|||
) {
|
||||
NavDisplay(
|
||||
backStack = navigationManager.backStack,
|
||||
onBack = { navigationManager.goBack() },
|
||||
onBack = { repeat(it) { navigationManager.goBack() } },
|
||||
entryDecorators =
|
||||
listOf(
|
||||
rememberSceneSetupNavEntryDecorator(),
|
||||
|
|
|
|||
|
|
@ -26,7 +26,9 @@ sealed class Destination(
|
|||
data object UserList : Destination(true)
|
||||
|
||||
@Serializable
|
||||
data object Main : Destination()
|
||||
data class Main(
|
||||
val id: Long = 0L,
|
||||
) : Destination()
|
||||
|
||||
@Serializable
|
||||
data object Settings : Destination(true)
|
||||
|
|
|
|||
|
|
@ -29,7 +29,7 @@ fun DestinationContent(
|
|||
modifier: Modifier = Modifier,
|
||||
) {
|
||||
when (destination) {
|
||||
Destination.Main ->
|
||||
is Destination.Main ->
|
||||
MainPage(
|
||||
preferences = preferences,
|
||||
navigationManager = navigationManager,
|
||||
|
|
|
|||
|
|
@ -136,7 +136,13 @@ fun NavDrawer(
|
|||
IconNavItem(
|
||||
text = "Home",
|
||||
icon = Icons.Default.Home,
|
||||
onClick = { navigationManager.goToHome() },
|
||||
onClick = {
|
||||
if (destination is Destination.Main) {
|
||||
navigationManager.reloadHome()
|
||||
} else {
|
||||
navigationManager.goToHome()
|
||||
}
|
||||
},
|
||||
)
|
||||
LazyColumn(
|
||||
state = listState,
|
||||
|
|
|
|||
|
|
@ -15,7 +15,14 @@ class NavigationManager(
|
|||
}
|
||||
|
||||
fun goToHome() {
|
||||
backStack.clear()
|
||||
backStack.add(Destination.Main)
|
||||
while (backStack.size > 1) {
|
||||
backStack.removeLastOrNull()
|
||||
}
|
||||
}
|
||||
|
||||
fun reloadHome() {
|
||||
goToHome()
|
||||
val id = (backStack[0] as Destination.Main).id + 1
|
||||
backStack[0] = Destination.Main(id)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue