mirror of
https://github.com/msfjarvis/compose-lobsters
synced 2025-08-14 10:37:05 +05:30
android: correctly finish parent activity in navigation flow
This commit is contained in:
parent
8040d85e16
commit
e515d6d2ba
2 changed files with 14 additions and 1 deletions
|
@ -65,6 +65,7 @@ fun LobstersApp(
|
||||||
val coroutineScope = rememberCoroutineScope()
|
val coroutineScope = rememberCoroutineScope()
|
||||||
val postActions = rememberPostActions(urlLauncher, navController, viewModel)
|
val postActions = rememberPostActions(urlLauncher, navController, viewModel)
|
||||||
val currentDestination by currentNavigationDestination(navController)
|
val currentDestination by currentNavigationDestination(navController)
|
||||||
|
val context = LocalContext.current
|
||||||
|
|
||||||
val hottestPosts = viewModel.hottestPosts.collectAsLazyPagingItems()
|
val hottestPosts = viewModel.hottestPosts.collectAsLazyPagingItems()
|
||||||
val newestPosts = viewModel.newestPosts.collectAsLazyPagingItems()
|
val newestPosts = viewModel.newestPosts.collectAsLazyPagingItems()
|
||||||
|
@ -128,7 +129,9 @@ fun LobstersApp(
|
||||||
backgroundColor = systemBarsColor,
|
backgroundColor = systemBarsColor,
|
||||||
navigationIcon = {
|
navigationIcon = {
|
||||||
if (navItems.none { it.route == currentDestination }) {
|
if (navItems.none { it.route == currentDestination }) {
|
||||||
IconButton(onClick = { navController.popBackStack() }) {
|
IconButton(
|
||||||
|
onClick = { if (!navController.popBackStack()) context.getActivity()?.finish() }
|
||||||
|
) {
|
||||||
Icon(
|
Icon(
|
||||||
painter = ClawIcons.ArrowBack,
|
painter = ClawIcons.ArrowBack,
|
||||||
contentDescription = "Go back to previous screen",
|
contentDescription = "Go back to previous screen",
|
||||||
|
|
|
@ -1,7 +1,9 @@
|
||||||
package dev.msfjarvis.claw.android.ui
|
package dev.msfjarvis.claw.android.ui
|
||||||
|
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
|
import android.content.ContextWrapper
|
||||||
import android.os.Build
|
import android.os.Build
|
||||||
|
import androidx.activity.ComponentActivity
|
||||||
import androidx.compose.animation.EnterTransition
|
import androidx.compose.animation.EnterTransition
|
||||||
import androidx.compose.animation.ExitTransition
|
import androidx.compose.animation.ExitTransition
|
||||||
import androidx.compose.animation.core.FastOutLinearInEasing
|
import androidx.compose.animation.core.FastOutLinearInEasing
|
||||||
|
@ -48,6 +50,14 @@ fun slideOutAnimation(): ExitTransition {
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun Context.getActivity(): ComponentActivity? {
|
||||||
|
return when (this) {
|
||||||
|
is ComponentActivity -> this
|
||||||
|
is ContextWrapper -> baseContext.getActivity()
|
||||||
|
else -> null
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Parses a given [String] into a [LocalDateTime]. This method is only intended to be used for dates
|
* Parses a given [String] into a [LocalDateTime]. This method is only intended to be used for dates
|
||||||
* in the format returned by the Lobsters API, and is not a general purpose parsing solution.
|
* in the format returned by the Lobsters API, and is not a general purpose parsing solution.
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue